github.com/pion/webrtc/v3@v3.2.24/icetransportstate.go (about)

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  import "github.com/pion/ice/v2"
     7  
     8  // ICETransportState represents the current state of the ICE transport.
     9  type ICETransportState int
    10  
    11  const (
    12  	// ICETransportStateNew indicates the ICETransport is waiting
    13  	// for remote candidates to be supplied.
    14  	ICETransportStateNew = iota + 1
    15  
    16  	// ICETransportStateChecking indicates the ICETransport has
    17  	// received at least one remote candidate, and a local and remote
    18  	// ICECandidateComplete dictionary was not added as the last candidate.
    19  	ICETransportStateChecking
    20  
    21  	// ICETransportStateConnected indicates the ICETransport has
    22  	// received a response to an outgoing connectivity check, or has
    23  	// received incoming DTLS/media after a successful response to an
    24  	// incoming connectivity check, but is still checking other candidate
    25  	// pairs to see if there is a better connection.
    26  	ICETransportStateConnected
    27  
    28  	// ICETransportStateCompleted indicates the ICETransport tested
    29  	// all appropriate candidate pairs and at least one functioning
    30  	// candidate pair has been found.
    31  	ICETransportStateCompleted
    32  
    33  	// ICETransportStateFailed indicates the ICETransport the last
    34  	// candidate was added and all appropriate candidate pairs have either
    35  	// failed connectivity checks or have lost consent.
    36  	ICETransportStateFailed
    37  
    38  	// ICETransportStateDisconnected indicates the ICETransport has received
    39  	// at least one local and remote candidate, but the final candidate was
    40  	// received yet and all appropriate candidate pairs thus far have been
    41  	// tested and failed.
    42  	ICETransportStateDisconnected
    43  
    44  	// ICETransportStateClosed indicates the ICETransport has shut down
    45  	// and is no longer responding to STUN requests.
    46  	ICETransportStateClosed
    47  )
    48  
    49  func (c ICETransportState) String() string {
    50  	switch c {
    51  	case ICETransportStateNew:
    52  		return "new"
    53  	case ICETransportStateChecking:
    54  		return "checking"
    55  	case ICETransportStateConnected:
    56  		return "connected"
    57  	case ICETransportStateCompleted:
    58  		return "completed"
    59  	case ICETransportStateFailed:
    60  		return "failed"
    61  	case ICETransportStateDisconnected:
    62  		return "disconnected"
    63  	case ICETransportStateClosed:
    64  		return "closed"
    65  	default:
    66  		return unknownStr
    67  	}
    68  }
    69  
    70  func newICETransportStateFromICE(i ice.ConnectionState) ICETransportState {
    71  	switch i {
    72  	case ice.ConnectionStateNew:
    73  		return ICETransportStateNew
    74  	case ice.ConnectionStateChecking:
    75  		return ICETransportStateChecking
    76  	case ice.ConnectionStateConnected:
    77  		return ICETransportStateConnected
    78  	case ice.ConnectionStateCompleted:
    79  		return ICETransportStateCompleted
    80  	case ice.ConnectionStateFailed:
    81  		return ICETransportStateFailed
    82  	case ice.ConnectionStateDisconnected:
    83  		return ICETransportStateDisconnected
    84  	case ice.ConnectionStateClosed:
    85  		return ICETransportStateClosed
    86  	default:
    87  		return ICETransportState(Unknown)
    88  	}
    89  }
    90  
    91  func (c ICETransportState) toICE() ice.ConnectionState {
    92  	switch c {
    93  	case ICETransportStateNew:
    94  		return ice.ConnectionStateNew
    95  	case ICETransportStateChecking:
    96  		return ice.ConnectionStateChecking
    97  	case ICETransportStateConnected:
    98  		return ice.ConnectionStateConnected
    99  	case ICETransportStateCompleted:
   100  		return ice.ConnectionStateCompleted
   101  	case ICETransportStateFailed:
   102  		return ice.ConnectionStateFailed
   103  	case ICETransportStateDisconnected:
   104  		return ice.ConnectionStateDisconnected
   105  	case ICETransportStateClosed:
   106  		return ice.ConnectionStateClosed
   107  	default:
   108  		return ice.ConnectionState(Unknown)
   109  	}
   110  }