datachannelstate.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package webrtc
  2. // DataChannelState indicates the state of a data channel.
  3. type DataChannelState int
  4. const (
  5. // DataChannelStateConnecting indicates that the data channel is being
  6. // established. This is the initial state of DataChannel, whether created
  7. // with CreateDataChannel, or dispatched as a part of an DataChannelEvent.
  8. DataChannelStateConnecting DataChannelState = iota + 1
  9. // DataChannelStateOpen indicates that the underlying data transport is
  10. // established and communication is possible.
  11. DataChannelStateOpen
  12. // DataChannelStateClosing indicates that the procedure to close down the
  13. // underlying data transport has started.
  14. DataChannelStateClosing
  15. // DataChannelStateClosed indicates that the underlying data transport
  16. // has been closed or could not be established.
  17. DataChannelStateClosed
  18. )
  19. // This is done this way because of a linter.
  20. const (
  21. dataChannelStateConnectingStr = "connecting"
  22. dataChannelStateOpenStr = "open"
  23. dataChannelStateClosingStr = "closing"
  24. dataChannelStateClosedStr = "closed"
  25. )
  26. func newDataChannelState(raw string) DataChannelState {
  27. switch raw {
  28. case dataChannelStateConnectingStr:
  29. return DataChannelStateConnecting
  30. case dataChannelStateOpenStr:
  31. return DataChannelStateOpen
  32. case dataChannelStateClosingStr:
  33. return DataChannelStateClosing
  34. case dataChannelStateClosedStr:
  35. return DataChannelStateClosed
  36. default:
  37. return DataChannelState(Unknown)
  38. }
  39. }
  40. func (t DataChannelState) String() string {
  41. switch t {
  42. case DataChannelStateConnecting:
  43. return dataChannelStateConnectingStr
  44. case DataChannelStateOpen:
  45. return dataChannelStateOpenStr
  46. case DataChannelStateClosing:
  47. return dataChannelStateClosingStr
  48. case DataChannelStateClosed:
  49. return dataChannelStateClosedStr
  50. default:
  51. return ErrUnknownType.Error()
  52. }
  53. }