sctptransportstate.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. // SCTPTransportState indicates the state of the SCTP transport.
  5. type SCTPTransportState int
  6. const (
  7. // SCTPTransportStateConnecting indicates the SCTPTransport is in the
  8. // process of negotiating an association. This is the initial state of the
  9. // SCTPTransportState when an SCTPTransport is created.
  10. SCTPTransportStateConnecting SCTPTransportState = iota + 1
  11. // SCTPTransportStateConnected indicates the negotiation of an
  12. // association is completed.
  13. SCTPTransportStateConnected
  14. // SCTPTransportStateClosed indicates a SHUTDOWN or ABORT chunk is
  15. // received or when the SCTP association has been closed intentionally,
  16. // such as by closing the peer connection or applying a remote description
  17. // that rejects data or changes the SCTP port.
  18. SCTPTransportStateClosed
  19. )
  20. // This is done this way because of a linter.
  21. const (
  22. sctpTransportStateConnectingStr = "connecting"
  23. sctpTransportStateConnectedStr = "connected"
  24. sctpTransportStateClosedStr = "closed"
  25. )
  26. func newSCTPTransportState(raw string) SCTPTransportState {
  27. switch raw {
  28. case sctpTransportStateConnectingStr:
  29. return SCTPTransportStateConnecting
  30. case sctpTransportStateConnectedStr:
  31. return SCTPTransportStateConnected
  32. case sctpTransportStateClosedStr:
  33. return SCTPTransportStateClosed
  34. default:
  35. return SCTPTransportState(Unknown)
  36. }
  37. }
  38. func (s SCTPTransportState) String() string {
  39. switch s {
  40. case SCTPTransportStateConnecting:
  41. return sctpTransportStateConnectingStr
  42. case SCTPTransportStateConnected:
  43. return sctpTransportStateConnectedStr
  44. case SCTPTransportStateClosed:
  45. return sctpTransportStateClosedStr
  46. default:
  47. return ErrUnknownType.Error()
  48. }
  49. }