github.com/pion/webrtc/v4@v4.0.1/iceconnectionstate.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  // ICEConnectionState indicates signaling state of the ICE Connection.
     7  type ICEConnectionState int
     8  
     9  const (
    10  	// ICEConnectionStateUnknown is the enum's zero-value
    11  	ICEConnectionStateUnknown ICEConnectionState = iota
    12  
    13  	// ICEConnectionStateNew indicates that any of the ICETransports are
    14  	// in the "new" state and none of them are in the "checking", "disconnected"
    15  	// or "failed" state, or all ICETransports are in the "closed" state, or
    16  	// there are no transports.
    17  	ICEConnectionStateNew
    18  
    19  	// ICEConnectionStateChecking indicates that any of the ICETransports
    20  	// are in the "checking" state and none of them are in the "disconnected"
    21  	// or "failed" state.
    22  	ICEConnectionStateChecking
    23  
    24  	// ICEConnectionStateConnected indicates that all ICETransports are
    25  	// in the "connected", "completed" or "closed" state and at least one of
    26  	// them is in the "connected" state.
    27  	ICEConnectionStateConnected
    28  
    29  	// ICEConnectionStateCompleted indicates that all ICETransports are
    30  	// in the "completed" or "closed" state and at least one of them is in the
    31  	// "completed" state.
    32  	ICEConnectionStateCompleted
    33  
    34  	// ICEConnectionStateDisconnected indicates that any of the
    35  	// ICETransports are in the "disconnected" state and none of them are
    36  	// in the "failed" state.
    37  	ICEConnectionStateDisconnected
    38  
    39  	// ICEConnectionStateFailed indicates that any of the ICETransports
    40  	// are in the "failed" state.
    41  	ICEConnectionStateFailed
    42  
    43  	// ICEConnectionStateClosed indicates that the PeerConnection's
    44  	// isClosed is true.
    45  	ICEConnectionStateClosed
    46  )
    47  
    48  // This is done this way because of a linter.
    49  const (
    50  	iceConnectionStateNewStr          = "new"
    51  	iceConnectionStateCheckingStr     = "checking"
    52  	iceConnectionStateConnectedStr    = "connected"
    53  	iceConnectionStateCompletedStr    = "completed"
    54  	iceConnectionStateDisconnectedStr = "disconnected"
    55  	iceConnectionStateFailedStr       = "failed"
    56  	iceConnectionStateClosedStr       = "closed"
    57  )
    58  
    59  // NewICEConnectionState takes a string and converts it to ICEConnectionState
    60  func NewICEConnectionState(raw string) ICEConnectionState {
    61  	switch raw {
    62  	case iceConnectionStateNewStr:
    63  		return ICEConnectionStateNew
    64  	case iceConnectionStateCheckingStr:
    65  		return ICEConnectionStateChecking
    66  	case iceConnectionStateConnectedStr:
    67  		return ICEConnectionStateConnected
    68  	case iceConnectionStateCompletedStr:
    69  		return ICEConnectionStateCompleted
    70  	case iceConnectionStateDisconnectedStr:
    71  		return ICEConnectionStateDisconnected
    72  	case iceConnectionStateFailedStr:
    73  		return ICEConnectionStateFailed
    74  	case iceConnectionStateClosedStr:
    75  		return ICEConnectionStateClosed
    76  	default:
    77  		return ICEConnectionStateUnknown
    78  	}
    79  }
    80  
    81  func (c ICEConnectionState) String() string {
    82  	switch c {
    83  	case ICEConnectionStateNew:
    84  		return iceConnectionStateNewStr
    85  	case ICEConnectionStateChecking:
    86  		return iceConnectionStateCheckingStr
    87  	case ICEConnectionStateConnected:
    88  		return iceConnectionStateConnectedStr
    89  	case ICEConnectionStateCompleted:
    90  		return iceConnectionStateCompletedStr
    91  	case ICEConnectionStateDisconnected:
    92  		return iceConnectionStateDisconnectedStr
    93  	case ICEConnectionStateFailed:
    94  		return iceConnectionStateFailedStr
    95  	case ICEConnectionStateClosed:
    96  		return iceConnectionStateClosedStr
    97  	default:
    98  		return ErrUnknownType.Error()
    99  	}
   100  }