rtptransceiverdirection.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. package webrtc
  4. // RTPTransceiverDirection indicates the direction of the RTPTransceiver.
  5. type RTPTransceiverDirection int
  6. const (
  7. // RTPTransceiverDirectionSendrecv indicates the RTPSender will offer
  8. // to send RTP and the RTPReceiver will offer to receive RTP.
  9. RTPTransceiverDirectionSendrecv RTPTransceiverDirection = iota + 1
  10. // RTPTransceiverDirectionSendonly indicates the RTPSender will offer
  11. // to send RTP.
  12. RTPTransceiverDirectionSendonly
  13. // RTPTransceiverDirectionRecvonly indicates the RTPReceiver will
  14. // offer to receive RTP.
  15. RTPTransceiverDirectionRecvonly
  16. // RTPTransceiverDirectionInactive indicates the RTPSender won't offer
  17. // to send RTP and the RTPReceiver won't offer to receive RTP.
  18. RTPTransceiverDirectionInactive
  19. )
  20. // This is done this way because of a linter.
  21. const (
  22. rtpTransceiverDirectionSendrecvStr = "sendrecv"
  23. rtpTransceiverDirectionSendonlyStr = "sendonly"
  24. rtpTransceiverDirectionRecvonlyStr = "recvonly"
  25. rtpTransceiverDirectionInactiveStr = "inactive"
  26. )
  27. // NewRTPTransceiverDirection defines a procedure for creating a new
  28. // RTPTransceiverDirection from a raw string naming the transceiver direction.
  29. func NewRTPTransceiverDirection(raw string) RTPTransceiverDirection {
  30. switch raw {
  31. case rtpTransceiverDirectionSendrecvStr:
  32. return RTPTransceiverDirectionSendrecv
  33. case rtpTransceiverDirectionSendonlyStr:
  34. return RTPTransceiverDirectionSendonly
  35. case rtpTransceiverDirectionRecvonlyStr:
  36. return RTPTransceiverDirectionRecvonly
  37. case rtpTransceiverDirectionInactiveStr:
  38. return RTPTransceiverDirectionInactive
  39. default:
  40. return RTPTransceiverDirection(Unknown)
  41. }
  42. }
  43. func (t RTPTransceiverDirection) String() string {
  44. switch t {
  45. case RTPTransceiverDirectionSendrecv:
  46. return rtpTransceiverDirectionSendrecvStr
  47. case RTPTransceiverDirectionSendonly:
  48. return rtpTransceiverDirectionSendonlyStr
  49. case RTPTransceiverDirectionRecvonly:
  50. return rtpTransceiverDirectionRecvonlyStr
  51. case RTPTransceiverDirectionInactive:
  52. return rtpTransceiverDirectionInactiveStr
  53. default:
  54. return ErrUnknownType.Error()
  55. }
  56. }
  57. // Revers indicate the opposite direction
  58. func (t RTPTransceiverDirection) Revers() RTPTransceiverDirection {
  59. switch t {
  60. case RTPTransceiverDirectionSendonly:
  61. return RTPTransceiverDirectionRecvonly
  62. case RTPTransceiverDirectionRecvonly:
  63. return RTPTransceiverDirectionSendonly
  64. default:
  65. return t
  66. }
  67. }
  68. func haveRTPTransceiverDirectionIntersection(haystack []RTPTransceiverDirection, needle []RTPTransceiverDirection) bool {
  69. for _, n := range needle {
  70. for _, h := range haystack {
  71. if n == h {
  72. return true
  73. }
  74. }
  75. }
  76. return false
  77. }