-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
icetransportstate.go
155 lines (137 loc) · 4.86 KB
/
icetransportstate.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package webrtc
import "github.com/pion/ice/v4"
// ICETransportState represents the current state of the ICE transport.
type ICETransportState int
const (
// ICETransportStateUnknown is the enum's zero-value
ICETransportStateUnknown ICETransportState = iota
// ICETransportStateNew indicates the ICETransport is waiting
// for remote candidates to be supplied.
ICETransportStateNew
// ICETransportStateChecking indicates the ICETransport has
// received at least one remote candidate, and a local and remote
// ICECandidateComplete dictionary was not added as the last candidate.
ICETransportStateChecking
// ICETransportStateConnected indicates the ICETransport has
// received a response to an outgoing connectivity check, or has
// received incoming DTLS/media after a successful response to an
// incoming connectivity check, but is still checking other candidate
// pairs to see if there is a better connection.
ICETransportStateConnected
// ICETransportStateCompleted indicates the ICETransport tested
// all appropriate candidate pairs and at least one functioning
// candidate pair has been found.
ICETransportStateCompleted
// ICETransportStateFailed indicates the ICETransport the last
// candidate was added and all appropriate candidate pairs have either
// failed connectivity checks or have lost consent.
ICETransportStateFailed
// ICETransportStateDisconnected indicates the ICETransport has received
// at least one local and remote candidate, but the final candidate was
// received yet and all appropriate candidate pairs thus far have been
// tested and failed.
ICETransportStateDisconnected
// ICETransportStateClosed indicates the ICETransport has shut down
// and is no longer responding to STUN requests.
ICETransportStateClosed
)
const (
iceTransportStateNewStr = "new"
iceTransportStateCheckingStr = "checking"
iceTransportStateConnectedStr = "connected"
iceTransportStateCompletedStr = "completed"
iceTransportStateFailedStr = "failed"
iceTransportStateDisconnectedStr = "disconnected"
iceTransportStateClosedStr = "closed"
)
func newICETransportState(raw string) ICETransportState {
switch raw {
case iceTransportStateNewStr:
return ICETransportStateNew
case iceTransportStateCheckingStr:
return ICETransportStateChecking
case iceTransportStateConnectedStr:
return ICETransportStateConnected
case iceTransportStateCompletedStr:
return ICETransportStateCompleted
case iceTransportStateFailedStr:
return ICETransportStateFailed
case iceTransportStateDisconnectedStr:
return ICETransportStateDisconnected
case iceTransportStateClosedStr:
return ICETransportStateClosed
default:
return ICETransportStateUnknown
}
}
func (c ICETransportState) String() string {
switch c {
case ICETransportStateNew:
return iceTransportStateNewStr
case ICETransportStateChecking:
return iceTransportStateCheckingStr
case ICETransportStateConnected:
return iceTransportStateConnectedStr
case ICETransportStateCompleted:
return iceTransportStateCompletedStr
case ICETransportStateFailed:
return iceTransportStateFailedStr
case ICETransportStateDisconnected:
return iceTransportStateDisconnectedStr
case ICETransportStateClosed:
return iceTransportStateClosedStr
default:
return ErrUnknownType.Error()
}
}
func newICETransportStateFromICE(i ice.ConnectionState) ICETransportState {
switch i {
case ice.ConnectionStateNew:
return ICETransportStateNew
case ice.ConnectionStateChecking:
return ICETransportStateChecking
case ice.ConnectionStateConnected:
return ICETransportStateConnected
case ice.ConnectionStateCompleted:
return ICETransportStateCompleted
case ice.ConnectionStateFailed:
return ICETransportStateFailed
case ice.ConnectionStateDisconnected:
return ICETransportStateDisconnected
case ice.ConnectionStateClosed:
return ICETransportStateClosed
default:
return ICETransportStateUnknown
}
}
func (c ICETransportState) toICE() ice.ConnectionState {
switch c {
case ICETransportStateNew:
return ice.ConnectionStateNew
case ICETransportStateChecking:
return ice.ConnectionStateChecking
case ICETransportStateConnected:
return ice.ConnectionStateConnected
case ICETransportStateCompleted:
return ice.ConnectionStateCompleted
case ICETransportStateFailed:
return ice.ConnectionStateFailed
case ICETransportStateDisconnected:
return ice.ConnectionStateDisconnected
case ICETransportStateClosed:
return ice.ConnectionStateClosed
default:
return ice.ConnectionStateUnknown
}
}
// MarshalText implements encoding.TextMarshaler
func (c ICETransportState) MarshalText() ([]byte, error) {
return []byte(c.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler
func (c *ICETransportState) UnmarshalText(b []byte) error {
*c = newICETransportState(string(b))
return nil
}