github.com/pion/webrtc/v3@v3.2.24/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  	// RTPTransceiverDirectionSendrecv indicates the RTPSender will offer
    11  	// to send RTP and the RTPReceiver will offer to receive RTP.
    12  	RTPTransceiverDirectionSendrecv RTPTransceiverDirection = iota + 1
    13  
    14  	// RTPTransceiverDirectionSendonly indicates the RTPSender will offer
    15  	// to send RTP.
    16  	RTPTransceiverDirectionSendonly
    17  
    18  	// RTPTransceiverDirectionRecvonly indicates the RTPReceiver will
    19  	// offer to receive RTP.
    20  	RTPTransceiverDirectionRecvonly
    21  
    22  	// RTPTransceiverDirectionInactive indicates the RTPSender won't offer
    23  	// to send RTP and the RTPReceiver won't offer to receive RTP.
    24  	RTPTransceiverDirectionInactive
    25  )
    26  
    27  // This is done this way because of a linter.
    28  const (
    29  	rtpTransceiverDirectionSendrecvStr = "sendrecv"
    30  	rtpTransceiverDirectionSendonlyStr = "sendonly"
    31  	rtpTransceiverDirectionRecvonlyStr = "recvonly"
    32  	rtpTransceiverDirectionInactiveStr = "inactive"
    33  )
    34  
    35  // NewRTPTransceiverDirection defines a procedure for creating a new
    36  // RTPTransceiverDirection from a raw string naming the transceiver direction.
    37  func NewRTPTransceiverDirection(raw string) RTPTransceiverDirection {
    38  	switch raw {
    39  	case rtpTransceiverDirectionSendrecvStr:
    40  		return RTPTransceiverDirectionSendrecv
    41  	case rtpTransceiverDirectionSendonlyStr:
    42  		return RTPTransceiverDirectionSendonly
    43  	case rtpTransceiverDirectionRecvonlyStr:
    44  		return RTPTransceiverDirectionRecvonly
    45  	case rtpTransceiverDirectionInactiveStr:
    46  		return RTPTransceiverDirectionInactive
    47  	default:
    48  		return RTPTransceiverDirection(Unknown)
    49  	}
    50  }
    51  
    52  func (t RTPTransceiverDirection) String() string {
    53  	switch t {
    54  	case RTPTransceiverDirectionSendrecv:
    55  		return rtpTransceiverDirectionSendrecvStr
    56  	case RTPTransceiverDirectionSendonly:
    57  		return rtpTransceiverDirectionSendonlyStr
    58  	case RTPTransceiverDirectionRecvonly:
    59  		return rtpTransceiverDirectionRecvonlyStr
    60  	case RTPTransceiverDirectionInactive:
    61  		return rtpTransceiverDirectionInactiveStr
    62  	default:
    63  		return ErrUnknownType.Error()
    64  	}
    65  }
    66  
    67  // Revers indicate the opposite direction
    68  func (t RTPTransceiverDirection) Revers() RTPTransceiverDirection {
    69  	switch t {
    70  	case RTPTransceiverDirectionSendonly:
    71  		return RTPTransceiverDirectionRecvonly
    72  	case RTPTransceiverDirectionRecvonly:
    73  		return RTPTransceiverDirectionSendonly
    74  	default:
    75  		return t
    76  	}
    77  }
    78  
    79  func haveRTPTransceiverDirectionIntersection(haystack []RTPTransceiverDirection, needle []RTPTransceiverDirection) bool {
    80  	for _, n := range needle {
    81  		for _, h := range haystack {
    82  			if n == h {
    83  				return true
    84  			}
    85  		}
    86  	}
    87  	return false
    88  }