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

     1  // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
     2  // SPDX-License-Identifier: MIT
     3  
     4  package webrtc
     5  
     6  // ICEGatheringState describes the state of the candidate gathering process.
     7  type ICEGatheringState int
     8  
     9  const (
    10  	// ICEGatheringStateUnknown is the enum's zero-value
    11  	ICEGatheringStateUnknown ICEGatheringState = iota
    12  
    13  	// ICEGatheringStateNew indicates that any of the ICETransports are
    14  	// in the "new" gathering state and none of the transports are in the
    15  	// "gathering" state, or there are no transports.
    16  	ICEGatheringStateNew
    17  
    18  	// ICEGatheringStateGathering indicates that any of the ICETransports
    19  	// are in the "gathering" state.
    20  	ICEGatheringStateGathering
    21  
    22  	// ICEGatheringStateComplete indicates that at least one ICETransport
    23  	// exists, and all ICETransports are in the "completed" gathering state.
    24  	ICEGatheringStateComplete
    25  )
    26  
    27  // This is done this way because of a linter.
    28  const (
    29  	iceGatheringStateNewStr       = "new"
    30  	iceGatheringStateGatheringStr = "gathering"
    31  	iceGatheringStateCompleteStr  = "complete"
    32  )
    33  
    34  // NewICEGatheringState takes a string and converts it to ICEGatheringState
    35  func NewICEGatheringState(raw string) ICEGatheringState {
    36  	switch raw {
    37  	case iceGatheringStateNewStr:
    38  		return ICEGatheringStateNew
    39  	case iceGatheringStateGatheringStr:
    40  		return ICEGatheringStateGathering
    41  	case iceGatheringStateCompleteStr:
    42  		return ICEGatheringStateComplete
    43  	default:
    44  		return ICEGatheringStateUnknown
    45  	}
    46  }
    47  
    48  func (t ICEGatheringState) String() string {
    49  	switch t {
    50  	case ICEGatheringStateNew:
    51  		return iceGatheringStateNewStr
    52  	case ICEGatheringStateGathering:
    53  		return iceGatheringStateGatheringStr
    54  	case ICEGatheringStateComplete:
    55  		return iceGatheringStateCompleteStr
    56  	default:
    57  		return ErrUnknownType.Error()
    58  	}
    59  }