iceserver_js.go 902 B

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