github.com/pion/webrtc/v4@v4.0.1/rtptransceiverdirection.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package webrtc 5 6 // RTPTransceiverDirection indicates the direction of the RTPTransceiver. 7 type RTPTransceiverDirection int 8 9 const ( 10 // RTPTransceiverDirectionUnknown is the enum's zero-value 11 RTPTransceiverDirectionUnknown RTPTransceiverDirection = iota 12 13 // RTPTransceiverDirectionSendrecv indicates the RTPSender will offer 14 // to send RTP and the RTPReceiver will offer to receive RTP. 15 RTPTransceiverDirectionSendrecv 16 17 // RTPTransceiverDirectionSendonly indicates the RTPSender will offer 18 // to send RTP. 19 RTPTransceiverDirectionSendonly 20 21 // RTPTransceiverDirectionRecvonly indicates the RTPReceiver will 22 // offer to receive RTP. 23 RTPTransceiverDirectionRecvonly 24 25 // RTPTransceiverDirectionInactive indicates the RTPSender won't offer 26 // to send RTP and the RTPReceiver won't offer to receive RTP. 27 RTPTransceiverDirectionInactive 28 ) 29 30 // This is done this way because of a linter. 31 const ( 32 rtpTransceiverDirectionSendrecvStr = "sendrecv" 33 rtpTransceiverDirectionSendonlyStr = "sendonly" 34 rtpTransceiverDirectionRecvonlyStr = "recvonly" 35 rtpTransceiverDirectionInactiveStr = "inactive" 36 ) 37 38 // NewRTPTransceiverDirection defines a procedure for creating a new 39 // RTPTransceiverDirection from a raw string naming the transceiver direction. 40 func NewRTPTransceiverDirection(raw string) RTPTransceiverDirection { 41 switch raw { 42 case rtpTransceiverDirectionSendrecvStr: 43 return RTPTransceiverDirectionSendrecv 44 case rtpTransceiverDirectionSendonlyStr: 45 return RTPTransceiverDirectionSendonly 46 case rtpTransceiverDirectionRecvonlyStr: 47 return RTPTransceiverDirectionRecvonly 48 case rtpTransceiverDirectionInactiveStr: 49 return RTPTransceiverDirectionInactive 50 default: 51 return RTPTransceiverDirectionUnknown 52 } 53 } 54 55 func (t RTPTransceiverDirection) String() string { 56 switch t { 57 case RTPTransceiverDirectionSendrecv: 58 return rtpTransceiverDirectionSendrecvStr 59 case RTPTransceiverDirectionSendonly: 60 return rtpTransceiverDirectionSendonlyStr 61 case RTPTransceiverDirectionRecvonly: 62 return rtpTransceiverDirectionRecvonlyStr 63 case RTPTransceiverDirectionInactive: 64 return rtpTransceiverDirectionInactiveStr 65 default: 66 return ErrUnknownType.Error() 67 } 68 } 69 70 // Revers indicate the opposite direction 71 func (t RTPTransceiverDirection) Revers() RTPTransceiverDirection { 72 switch t { 73 case RTPTransceiverDirectionSendonly: 74 return RTPTransceiverDirectionRecvonly 75 case RTPTransceiverDirectionRecvonly: 76 return RTPTransceiverDirectionSendonly 77 default: 78 return t 79 } 80 } 81 82 func haveRTPTransceiverDirectionIntersection(haystack []RTPTransceiverDirection, needle []RTPTransceiverDirection) bool { 83 for _, n := range needle { 84 for _, h := range haystack { 85 if n == h { 86 return true 87 } 88 } 89 } 90 return false 91 }