iceserver_js.go 1004 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. //go:build js && wasm
  4. // +build js,wasm
  5. package webrtc
  6. import (
  7. "errors"
  8. "github.com/pion/ice/v2"
  9. )
  10. // ICEServer describes a single STUN and TURN server that can be used by
  11. // the ICEAgent to establish a connection with a peer.
  12. type ICEServer struct {
  13. URLs []string
  14. Username string
  15. // Note: TURN is not supported in the WASM bindings yet
  16. Credential interface{}
  17. CredentialType ICECredentialType
  18. }
  19. func (s ICEServer) parseURL(i int) (*ice.URL, error) {
  20. return ice.ParseURL(s.URLs[i])
  21. }
  22. func (s ICEServer) validate() ([]*ice.URL, error) {
  23. urls := []*ice.URL{}
  24. for i := range s.URLs {
  25. url, err := s.parseURL(i)
  26. if err != nil {
  27. return nil, err
  28. }
  29. if url.Scheme == ice.SchemeTypeTURN || url.Scheme == ice.SchemeTypeTURNS {
  30. return nil, errors.New("TURN is not currently supported in the JavaScript/Wasm bindings")
  31. }
  32. urls = append(urls, url)
  33. }
  34. return urls, nil
  35. }