2
0

peerconnectionstate.go 3.3 KB

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