datachannelstate.go 1.9 KB

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