-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
rtptransceiverdirection.go
85 lines (75 loc) · 2.56 KB
/
rtptransceiverdirection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package webrtc
// RTPTransceiverDirection indicates the direction of the RTPTransceiver.
type RTPTransceiverDirection int
const (
// RTPTransceiverDirectionSendrecv indicates the RTPSender will offer
// to send RTP and the RTPReceiver will offer to receive RTP.
RTPTransceiverDirectionSendrecv RTPTransceiverDirection = iota + 1
// RTPTransceiverDirectionSendonly indicates the RTPSender will offer
// to send RTP.
RTPTransceiverDirectionSendonly
// RTPTransceiverDirectionRecvonly indicates the RTPReceiver will
// offer to receive RTP.
RTPTransceiverDirectionRecvonly
// RTPTransceiverDirectionInactive indicates the RTPSender won't offer
// to send RTP and the RTPReceiver won't offer to receive RTP.
RTPTransceiverDirectionInactive
)
// This is done this way because of a linter.
const (
rtpTransceiverDirectionSendrecvStr = "sendrecv"
rtpTransceiverDirectionSendonlyStr = "sendonly"
rtpTransceiverDirectionRecvonlyStr = "recvonly"
rtpTransceiverDirectionInactiveStr = "inactive"
)
// NewRTPTransceiverDirection defines a procedure for creating a new
// RTPTransceiverDirection from a raw string naming the transceiver direction.
func NewRTPTransceiverDirection(raw string) RTPTransceiverDirection {
switch raw {
case rtpTransceiverDirectionSendrecvStr:
return RTPTransceiverDirectionSendrecv
case rtpTransceiverDirectionSendonlyStr:
return RTPTransceiverDirectionSendonly
case rtpTransceiverDirectionRecvonlyStr:
return RTPTransceiverDirectionRecvonly
case rtpTransceiverDirectionInactiveStr:
return RTPTransceiverDirectionInactive
default:
return RTPTransceiverDirection(Unknown)
}
}
func (t RTPTransceiverDirection) String() string {
switch t {
case RTPTransceiverDirectionSendrecv:
return rtpTransceiverDirectionSendrecvStr
case RTPTransceiverDirectionSendonly:
return rtpTransceiverDirectionSendonlyStr
case RTPTransceiverDirectionRecvonly:
return rtpTransceiverDirectionRecvonlyStr
case RTPTransceiverDirectionInactive:
return rtpTransceiverDirectionInactiveStr
default:
return ErrUnknownType.Error()
}
}
// Revers indicate the opposite direction
func (t RTPTransceiverDirection) Revers() RTPTransceiverDirection {
switch t {
case RTPTransceiverDirectionSendonly:
return RTPTransceiverDirectionRecvonly
case RTPTransceiverDirectionRecvonly:
return RTPTransceiverDirectionSendonly
default:
return t
}
}
func haveRTPTransceiverDirectionIntersection(haystack []RTPTransceiverDirection, needle []RTPTransceiverDirection) bool {
for _, n := range needle {
for _, h := range haystack {
if n == h {
return true
}
}
}
return false
}