-
Notifications
You must be signed in to change notification settings - Fork 0
/
datachannelstate.go
78 lines (66 loc) · 2.24 KB
/
datachannelstate.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
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package webrtc
// DataChannelState indicates the state of a data channel.
type DataChannelState int
const (
// DataChannelStateUnknown is the enum's zero-value
DataChannelStateUnknown DataChannelState = iota
// DataChannelStateConnecting indicates that the data channel is being
// established. This is the initial state of DataChannel, whether created
// with CreateDataChannel, or dispatched as a part of an DataChannelEvent.
DataChannelStateConnecting
// DataChannelStateOpen indicates that the underlying data transport is
// established and communication is possible.
DataChannelStateOpen
// DataChannelStateClosing indicates that the procedure to close down the
// underlying data transport has started.
DataChannelStateClosing
// DataChannelStateClosed indicates that the underlying data transport
// has been closed or could not be established.
DataChannelStateClosed
)
// This is done this way because of a linter.
const (
dataChannelStateConnectingStr = "connecting"
dataChannelStateOpenStr = "open"
dataChannelStateClosingStr = "closing"
dataChannelStateClosedStr = "closed"
)
func newDataChannelState(raw string) DataChannelState {
switch raw {
case dataChannelStateConnectingStr:
return DataChannelStateConnecting
case dataChannelStateOpenStr:
return DataChannelStateOpen
case dataChannelStateClosingStr:
return DataChannelStateClosing
case dataChannelStateClosedStr:
return DataChannelStateClosed
default:
return DataChannelStateUnknown
}
}
func (t DataChannelState) String() string {
switch t {
case DataChannelStateConnecting:
return dataChannelStateConnectingStr
case DataChannelStateOpen:
return dataChannelStateOpenStr
case DataChannelStateClosing:
return dataChannelStateClosingStr
case DataChannelStateClosed:
return dataChannelStateClosedStr
default:
return ErrUnknownType.Error()
}
}
// MarshalText implements encoding.TextMarshaler
func (t DataChannelState) MarshalText() ([]byte, error) {
return []byte(t.String()), nil
}
// UnmarshalText implements encoding.TextUnmarshaler
func (t *DataChannelState) UnmarshalText(b []byte) error {
*t = newDataChannelState(string(b))
return nil
}