github.com/pion/webrtc/v4@v4.0.1/peerconnectionstate.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package webrtc 5 6 // PeerConnectionState indicates the state of the PeerConnection. 7 type PeerConnectionState int 8 9 const ( 10 // PeerConnectionStateUnknown is the enum's zero-value 11 PeerConnectionStateUnknown PeerConnectionState = iota 12 13 // PeerConnectionStateNew indicates that any of the ICETransports or 14 // DTLSTransports are in the "new" state and none of the transports are 15 // in the "connecting", "checking", "failed" or "disconnected" state, or 16 // all transports are in the "closed" state, or there are no transports. 17 PeerConnectionStateNew 18 19 // PeerConnectionStateConnecting indicates that any of the 20 // ICETransports or DTLSTransports are in the "connecting" or 21 // "checking" state and none of them is in the "failed" state. 22 PeerConnectionStateConnecting 23 24 // PeerConnectionStateConnected indicates that all ICETransports and 25 // DTLSTransports are in the "connected", "completed" or "closed" state 26 // and at least one of them is in the "connected" or "completed" state. 27 PeerConnectionStateConnected 28 29 // PeerConnectionStateDisconnected indicates that any of the 30 // ICETransports or DTLSTransports are in the "disconnected" state 31 // and none of them are in the "failed" or "connecting" or "checking" state. 32 PeerConnectionStateDisconnected 33 34 // PeerConnectionStateFailed indicates that any of the ICETransports 35 // or DTLSTransports are in a "failed" state. 36 PeerConnectionStateFailed 37 38 // PeerConnectionStateClosed indicates the peer connection is closed 39 // and the isClosed member variable of PeerConnection is true. 40 PeerConnectionStateClosed 41 ) 42 43 // This is done this way because of a linter. 44 const ( 45 peerConnectionStateNewStr = "new" 46 peerConnectionStateConnectingStr = "connecting" 47 peerConnectionStateConnectedStr = "connected" 48 peerConnectionStateDisconnectedStr = "disconnected" 49 peerConnectionStateFailedStr = "failed" 50 peerConnectionStateClosedStr = "closed" 51 ) 52 53 func newPeerConnectionState(raw string) PeerConnectionState { 54 switch raw { 55 case peerConnectionStateNewStr: 56 return PeerConnectionStateNew 57 case peerConnectionStateConnectingStr: 58 return PeerConnectionStateConnecting 59 case peerConnectionStateConnectedStr: 60 return PeerConnectionStateConnected 61 case peerConnectionStateDisconnectedStr: 62 return PeerConnectionStateDisconnected 63 case peerConnectionStateFailedStr: 64 return PeerConnectionStateFailed 65 case peerConnectionStateClosedStr: 66 return PeerConnectionStateClosed 67 default: 68 return PeerConnectionStateUnknown 69 } 70 } 71 72 func (t PeerConnectionState) String() string { 73 switch t { 74 case PeerConnectionStateNew: 75 return peerConnectionStateNewStr 76 case PeerConnectionStateConnecting: 77 return peerConnectionStateConnectingStr 78 case PeerConnectionStateConnected: 79 return peerConnectionStateConnectedStr 80 case PeerConnectionStateDisconnected: 81 return peerConnectionStateDisconnectedStr 82 case PeerConnectionStateFailed: 83 return peerConnectionStateFailedStr 84 case PeerConnectionStateClosed: 85 return peerConnectionStateClosedStr 86 default: 87 return ErrUnknownType.Error() 88 } 89 }