configuration_common.go 910 B

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