iceconnectionstate.go 3.1 KB

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