mirror of
https://github.com/pion/webrtc.git
synced 2025-09-27 03:25:58 +08:00
32 lines
614 B
Go
32 lines
614 B
Go
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package signal
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
// HTTPSDPServer starts a HTTP Server that consumes SDPs
|
|
func HTTPSDPServer(port int) chan string {
|
|
sdpChan := make(chan string)
|
|
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
body, _ := ioutil.ReadAll(r.Body)
|
|
fmt.Fprintf(w, "done")
|
|
sdpChan <- string(body)
|
|
})
|
|
|
|
go func() {
|
|
// nolint: gosec
|
|
err := http.ListenAndServe(":"+strconv.Itoa(port), nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
|
|
return sdpChan
|
|
}
|