iceconnectionstate.go 3.2 KB

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