forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iceconnectionstate.go
94 lines (83 loc) · 3.11 KB
/
iceconnectionstate.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
package webrtc
// ICEConnectionState indicates signaling state of the ICE Connection.
type ICEConnectionState int
const (
// ICEConnectionStateNew indicates that any of the ICETransports are
// in the "new" state and none of them are in the "checking", "disconnected"
// or "failed" state, or all ICETransports are in the "closed" state, or
// there are no transports.
ICEConnectionStateNew ICEConnectionState = iota + 1
// ICEConnectionStateChecking indicates that any of the ICETransports
// are in the "checking" state and none of them are in the "disconnected"
// or "failed" state.
ICEConnectionStateChecking
// ICEConnectionStateConnected indicates that all ICETransports are
// in the "connected", "completed" or "closed" state and at least one of
// them is in the "connected" state.
ICEConnectionStateConnected
// ICEConnectionStateCompleted indicates that all ICETransports are
// in the "completed" or "closed" state and at least one of them is in the
// "completed" state.
ICEConnectionStateCompleted
// ICEConnectionStateDisconnected indicates that any of the
// ICETransports are in the "disconnected" state and none of them are
// in the "failed" state.
ICEConnectionStateDisconnected
// ICEConnectionStateFailed indicates that any of the ICETransports
// are in the "failed" state.
ICEConnectionStateFailed
// ICEConnectionStateClosed indicates that the PeerConnection's
// isClosed is true.
ICEConnectionStateClosed
)
// This is done this way because of a linter.
const (
iceConnectionStateNewStr = "new"
iceConnectionStateCheckingStr = "checking"
iceConnectionStateConnectedStr = "connected"
iceConnectionStateCompletedStr = "completed"
iceConnectionStateDisconnectedStr = "disconnected"
iceConnectionStateFailedStr = "failed"
iceConnectionStateClosedStr = "closed"
)
// NewICEConnectionState takes a string and converts it to ICEConnectionState
func NewICEConnectionState(raw string) ICEConnectionState {
switch raw {
case iceConnectionStateNewStr:
return ICEConnectionStateNew
case iceConnectionStateCheckingStr:
return ICEConnectionStateChecking
case iceConnectionStateConnectedStr:
return ICEConnectionStateConnected
case iceConnectionStateCompletedStr:
return ICEConnectionStateCompleted
case iceConnectionStateDisconnectedStr:
return ICEConnectionStateDisconnected
case iceConnectionStateFailedStr:
return ICEConnectionStateFailed
case iceConnectionStateClosedStr:
return ICEConnectionStateClosed
default:
return ICEConnectionState(Unknown)
}
}
func (c ICEConnectionState) String() string {
switch c {
case ICEConnectionStateNew:
return iceConnectionStateNewStr
case ICEConnectionStateChecking:
return iceConnectionStateCheckingStr
case ICEConnectionStateConnected:
return iceConnectionStateConnectedStr
case ICEConnectionStateCompleted:
return iceConnectionStateCompletedStr
case ICEConnectionStateDisconnected:
return iceConnectionStateDisconnectedStr
case ICEConnectionStateFailed:
return iceConnectionStateFailedStr
case ICEConnectionStateClosed:
return iceConnectionStateClosedStr
default:
return ErrUnknownType.Error()
}
}