http.go 685 B

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package signal
  4. import (
  5. "flag"
  6. "fmt"
  7. "io/ioutil"
  8. "net/http"
  9. "strconv"
  10. )
  11. // HTTPSDPServer starts a HTTP Server that consumes SDPs
  12. func HTTPSDPServer() chan string {
  13. port := flag.Int("port", 8080, "http server port")
  14. flag.Parse()
  15. sdpChan := make(chan string)
  16. http.HandleFunc("/sdp", func(w http.ResponseWriter, r *http.Request) {
  17. body, _ := ioutil.ReadAll(r.Body)
  18. fmt.Fprintf(w, "done")
  19. sdpChan <- string(body)
  20. })
  21. go func() {
  22. // nolint: gosec
  23. err := http.ListenAndServe(":"+strconv.Itoa(*port), nil)
  24. if err != nil {
  25. panic(err)
  26. }
  27. }()
  28. return sdpChan
  29. }