rtptransceiverdirection.go 2.6 KB

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