github.com/pion/webrtc/v3@v3.2.24/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 // ICERoleControlling indicates that the ICE agent that is responsible 12 // for selecting the final choice of candidate pairs and signaling them 13 // through STUN and an updated offer, if needed. In any session, one agent 14 // is always controlling. The other is the controlled agent. 15 ICERoleControlling ICERole = iota + 1 16 17 // ICERoleControlled indicates that an ICE agent that waits for the 18 // controlling agent to select the final choice of candidate pairs. 19 ICERoleControlled 20 ) 21 22 // This is done this way because of a linter. 23 const ( 24 iceRoleControllingStr = "controlling" 25 iceRoleControlledStr = "controlled" 26 ) 27 28 func newICERole(raw string) ICERole { 29 switch raw { 30 case iceRoleControllingStr: 31 return ICERoleControlling 32 case iceRoleControlledStr: 33 return ICERoleControlled 34 default: 35 return ICERole(Unknown) 36 } 37 } 38 39 func (t ICERole) String() string { 40 switch t { 41 case ICERoleControlling: 42 return iceRoleControllingStr 43 case ICERoleControlled: 44 return iceRoleControlledStr 45 default: 46 return ErrUnknownType.Error() 47 } 48 } 49 50 // MarshalText implements encoding.TextMarshaler 51 func (t ICERole) MarshalText() ([]byte, error) { 52 return []byte(t.String()), nil 53 } 54 55 // UnmarshalText implements encoding.TextUnmarshaler 56 func (t *ICERole) UnmarshalText(b []byte) error { 57 *t = newICERole(string(b)) 58 return nil 59 }