icerole.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. // ICERole describes the role ice.Agent is playing in selecting the
  5. // preferred the candidate pair.
  6. type ICERole int
  7. const (
  8. // ICERoleControlling indicates that the ICE agent that is responsible
  9. // for selecting the final choice of candidate pairs and signaling them
  10. // through STUN and an updated offer, if needed. In any session, one agent
  11. // is always controlling. The other is the controlled agent.
  12. ICERoleControlling ICERole = iota + 1
  13. // ICERoleControlled indicates that an ICE agent that waits for the
  14. // controlling agent to select the final choice of candidate pairs.
  15. ICERoleControlled
  16. )
  17. // This is done this way because of a linter.
  18. const (
  19. iceRoleControllingStr = "controlling"
  20. iceRoleControlledStr = "controlled"
  21. )
  22. func newICERole(raw string) ICERole {
  23. switch raw {
  24. case iceRoleControllingStr:
  25. return ICERoleControlling
  26. case iceRoleControlledStr:
  27. return ICERoleControlled
  28. default:
  29. return ICERole(Unknown)
  30. }
  31. }
  32. func (t ICERole) String() string {
  33. switch t {
  34. case ICERoleControlling:
  35. return iceRoleControllingStr
  36. case ICERoleControlled:
  37. return iceRoleControlledStr
  38. default:
  39. return ErrUnknownType.Error()
  40. }
  41. }
  42. // MarshalText implements encoding.TextMarshaler
  43. func (t ICERole) MarshalText() ([]byte, error) {
  44. return []byte(t.String()), nil
  45. }
  46. // UnmarshalText implements encoding.TextUnmarshaler
  47. func (t *ICERole) UnmarshalText(b []byte) error {
  48. *t = newICERole(string(b))
  49. return nil
  50. }