configuration_common.go 808 B

123456789101112131415161718192021222324
  1. package webrtc
  2. import "strings"
  3. // getICEServers side-steps the strict parsing mode of the ice package
  4. // (as defined in https://tools.ietf.org/html/rfc7064) by copying and then
  5. // stripping any erroneous queries from "stun(s):" URLs before parsing.
  6. func (c Configuration) getICEServers() []ICEServer {
  7. iceServers := append([]ICEServer{}, c.ICEServers...)
  8. for iceServersIndex := range iceServers {
  9. iceServers[iceServersIndex].URLs = append([]string{}, iceServers[iceServersIndex].URLs...)
  10. for urlsIndex, rawURL := range iceServers[iceServersIndex].URLs {
  11. if strings.HasPrefix(rawURL, "stun") {
  12. // strip the query from "stun(s):" if present
  13. parts := strings.Split(rawURL, "?")
  14. rawURL = parts[0]
  15. }
  16. iceServers[iceServersIndex].URLs[urlsIndex] = rawURL
  17. }
  18. }
  19. return iceServers
  20. }