peerconnectionstate.go 3.2 KB

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