github.com/pion/webrtc/v3@v3.2.24/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  	// PeerConnectionStateNew indicates that any of the ICETransports or
    11  	// DTLSTransports are in the "new" state and none of the transports are
    12  	// in the "connecting", "checking", "failed" or "disconnected" state, or
    13  	// all transports are in the "closed" state, or there are no transports.
    14  	PeerConnectionStateNew PeerConnectionState = iota + 1
    15  
    16  	// PeerConnectionStateConnecting indicates that any of the
    17  	// ICETransports or DTLSTransports are in the "connecting" or
    18  	// "checking" state and none of them is in the "failed" state.
    19  	PeerConnectionStateConnecting
    20  
    21  	// PeerConnectionStateConnected indicates that all ICETransports and
    22  	// DTLSTransports are in the "connected", "completed" or "closed" state
    23  	// and at least one of them is in the "connected" or "completed" state.
    24  	PeerConnectionStateConnected
    25  
    26  	// PeerConnectionStateDisconnected indicates that any of the
    27  	// ICETransports or DTLSTransports are in the "disconnected" state
    28  	// and none of them are in the "failed" or "connecting" or "checking" state.
    29  	PeerConnectionStateDisconnected
    30  
    31  	// PeerConnectionStateFailed indicates that any of the ICETransports
    32  	// or DTLSTransports are in a "failed" state.
    33  	PeerConnectionStateFailed
    34  
    35  	// PeerConnectionStateClosed indicates the peer connection is closed
    36  	// and the isClosed member variable of PeerConnection is true.
    37  	PeerConnectionStateClosed
    38  )
    39  
    40  // This is done this way because of a linter.
    41  const (
    42  	peerConnectionStateNewStr          = "new"
    43  	peerConnectionStateConnectingStr   = "connecting"
    44  	peerConnectionStateConnectedStr    = "connected"
    45  	peerConnectionStateDisconnectedStr = "disconnected"
    46  	peerConnectionStateFailedStr       = "failed"
    47  	peerConnectionStateClosedStr       = "closed"
    48  )
    49  
    50  func newPeerConnectionState(raw string) PeerConnectionState {
    51  	switch raw {
    52  	case peerConnectionStateNewStr:
    53  		return PeerConnectionStateNew
    54  	case peerConnectionStateConnectingStr:
    55  		return PeerConnectionStateConnecting
    56  	case peerConnectionStateConnectedStr:
    57  		return PeerConnectionStateConnected
    58  	case peerConnectionStateDisconnectedStr:
    59  		return PeerConnectionStateDisconnected
    60  	case peerConnectionStateFailedStr:
    61  		return PeerConnectionStateFailed
    62  	case peerConnectionStateClosedStr:
    63  		return PeerConnectionStateClosed
    64  	default:
    65  		return PeerConnectionState(Unknown)
    66  	}
    67  }
    68  
    69  func (t PeerConnectionState) String() string {
    70  	switch t {
    71  	case PeerConnectionStateNew:
    72  		return peerConnectionStateNewStr
    73  	case PeerConnectionStateConnecting:
    74  		return peerConnectionStateConnectingStr
    75  	case PeerConnectionStateConnected:
    76  		return peerConnectionStateConnectedStr
    77  	case PeerConnectionStateDisconnected:
    78  		return peerConnectionStateDisconnectedStr
    79  	case PeerConnectionStateFailed:
    80  		return peerConnectionStateFailedStr
    81  	case PeerConnectionStateClosed:
    82  		return peerConnectionStateClosedStr
    83  	default:
    84  		return ErrUnknownType.Error()
    85  	}
    86  }
    87  
    88  type negotiationNeededState int
    89  
    90  const (
    91  	// NegotiationNeededStateEmpty not running and queue is empty
    92  	negotiationNeededStateEmpty = iota
    93  	// NegotiationNeededStateEmpty running and queue is empty
    94  	negotiationNeededStateRun
    95  	// NegotiationNeededStateEmpty running and queue
    96  	negotiationNeededStateQueue
    97  )