summaryrefslogtreecommitdiff
path: root/vendor/github.com/pion/webrtc/v3/datachannelstate.go
blob: a2c7b95de30376cbc8f6227336a3c141f8383c92 (plain)
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
package webrtc

// DataChannelState indicates the state of a data channel.
type DataChannelState int

const (
	// 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 DataChannelState = iota + 1

	// 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 DataChannelState(Unknown)
	}
}

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()
	}
}