forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peerconnectionstate.go
83 lines (73 loc) · 2.89 KB
/
peerconnectionstate.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
package webrtc
// PeerConnectionState indicates the state of the PeerConnection.
type PeerConnectionState int
const (
// PeerConnectionStateNew indicates that any of the ICETransports or
// DTLSTransports are in the "new" state and none of the transports are
// in the "connecting", "checking", "failed" or "disconnected" state, or
// all transports are in the "closed" state, or there are no transports.
PeerConnectionStateNew PeerConnectionState = iota + 1
// PeerConnectionStateConnecting indicates that any of the
// ICETransports or DTLSTransports are in the "connecting" or
// "checking" state and none of them is in the "failed" state.
PeerConnectionStateConnecting
// PeerConnectionStateConnected indicates that all ICETransports and
// DTLSTransports are in the "connected", "completed" or "closed" state
// and at least one of them is in the "connected" or "completed" state.
PeerConnectionStateConnected
// PeerConnectionStateDisconnected indicates that any of the
// ICETransports or DTLSTransports are in the "disconnected" state
// and none of them are in the "failed" or "connecting" or "checking" state.
PeerConnectionStateDisconnected
// PeerConnectionStateFailed indicates that any of the ICETransports
// or DTLSTransports are in a "failed" state.
PeerConnectionStateFailed
// PeerConnectionStateClosed indicates the peer connection is closed
// and the isClosed member variable of PeerConnection is true.
PeerConnectionStateClosed
)
// This is done this way because of a linter.
const (
peerConnectionStateNewStr = "new"
peerConnectionStateConnectingStr = "connecting"
peerConnectionStateConnectedStr = "connected"
peerConnectionStateDisconnectedStr = "disconnected"
peerConnectionStateFailedStr = "failed"
peerConnectionStateClosedStr = "closed"
)
func newPeerConnectionState(raw string) PeerConnectionState {
switch raw {
case peerConnectionStateNewStr:
return PeerConnectionStateNew
case peerConnectionStateConnectingStr:
return PeerConnectionStateConnecting
case peerConnectionStateConnectedStr:
return PeerConnectionStateConnected
case peerConnectionStateDisconnectedStr:
return PeerConnectionStateDisconnected
case peerConnectionStateFailedStr:
return PeerConnectionStateFailed
case peerConnectionStateClosedStr:
return PeerConnectionStateClosed
default:
return PeerConnectionState(Unknown)
}
}
func (t PeerConnectionState) String() string {
switch t {
case PeerConnectionStateNew:
return peerConnectionStateNewStr
case PeerConnectionStateConnecting:
return peerConnectionStateConnectingStr
case PeerConnectionStateConnected:
return peerConnectionStateConnectedStr
case PeerConnectionStateDisconnected:
return peerConnectionStateDisconnectedStr
case PeerConnectionStateFailed:
return peerConnectionStateFailedStr
case PeerConnectionStateClosed:
return peerConnectionStateClosedStr
default:
return ErrUnknownType.Error()
}
}