Files
webrtc/examples/internal/signal/http.go
2024-04-02 22:54:57 -04:00

32 lines
603 B
Go

// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package signal
import (
"fmt"
"io"
"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, _ := io.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
}