github.com/pion/webrtc/v3@v3.2.24/iceprotocol.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package webrtc 5 6 import ( 7 "fmt" 8 "strings" 9 ) 10 11 // ICEProtocol indicates the transport protocol type that is used in the 12 // ice.URL structure. 13 type ICEProtocol int 14 15 const ( 16 // ICEProtocolUDP indicates the URL uses a UDP transport. 17 ICEProtocolUDP ICEProtocol = iota + 1 18 19 // ICEProtocolTCP indicates the URL uses a TCP transport. 20 ICEProtocolTCP 21 ) 22 23 // This is done this way because of a linter. 24 const ( 25 iceProtocolUDPStr = "udp" 26 iceProtocolTCPStr = "tcp" 27 ) 28 29 // NewICEProtocol takes a string and converts it to ICEProtocol 30 func NewICEProtocol(raw string) (ICEProtocol, error) { 31 switch { 32 case strings.EqualFold(iceProtocolUDPStr, raw): 33 return ICEProtocolUDP, nil 34 case strings.EqualFold(iceProtocolTCPStr, raw): 35 return ICEProtocolTCP, nil 36 default: 37 return ICEProtocol(Unknown), fmt.Errorf("%w: %s", errICEProtocolUnknown, raw) 38 } 39 } 40 41 func (t ICEProtocol) String() string { 42 switch t { 43 case ICEProtocolUDP: 44 return iceProtocolUDPStr 45 case ICEProtocolTCP: 46 return iceProtocolTCPStr 47 default: 48 return ErrUnknownType.Error() 49 } 50 }