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

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  // SCTPTransportState indicates the state of the SCTP transport.
     7  type SCTPTransportState int
     8  
     9  const (
    10  	// SCTPTransportStateUnknown is the enum's zero-value
    11  	SCTPTransportStateUnknown SCTPTransportState = iota
    12  
    13  	// SCTPTransportStateConnecting indicates the SCTPTransport is in the
    14  	// process of negotiating an association. This is the initial state of the
    15  	// SCTPTransportState when an SCTPTransport is created.
    16  	SCTPTransportStateConnecting
    17  
    18  	// SCTPTransportStateConnected indicates the negotiation of an
    19  	// association is completed.
    20  	SCTPTransportStateConnected
    21  
    22  	// SCTPTransportStateClosed indicates a SHUTDOWN or ABORT chunk is
    23  	// received or when the SCTP association has been closed intentionally,
    24  	// such as by closing the peer connection or applying a remote description
    25  	// that rejects data or changes the SCTP port.
    26  	SCTPTransportStateClosed
    27  )
    28  
    29  // This is done this way because of a linter.
    30  const (
    31  	sctpTransportStateConnectingStr = "connecting"
    32  	sctpTransportStateConnectedStr  = "connected"
    33  	sctpTransportStateClosedStr     = "closed"
    34  )
    35  
    36  func newSCTPTransportState(raw string) SCTPTransportState {
    37  	switch raw {
    38  	case sctpTransportStateConnectingStr:
    39  		return SCTPTransportStateConnecting
    40  	case sctpTransportStateConnectedStr:
    41  		return SCTPTransportStateConnected
    42  	case sctpTransportStateClosedStr:
    43  		return SCTPTransportStateClosed
    44  	default:
    45  		return SCTPTransportStateUnknown
    46  	}
    47  }
    48  
    49  func (s SCTPTransportState) String() string {
    50  	switch s {
    51  	case SCTPTransportStateConnecting:
    52  		return sctpTransportStateConnectingStr
    53  	case SCTPTransportStateConnected:
    54  		return sctpTransportStateConnectedStr
    55  	case SCTPTransportStateClosed:
    56  		return sctpTransportStateClosedStr
    57  	default:
    58  		return ErrUnknownType.Error()
    59  	}
    60  }