Files
webrtc/examples/internal/signal/http.go
Sean DuBois 9eded4ee7a Fix ORTC example
README didn't describe how to get signaling into client 1

Relates to #379
2023-09-16 14:35:41 -04:00

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
}