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