rtptransceiver_js.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
  2. // SPDX-License-Identifier: MIT
  3. //go:build js && wasm
  4. // +build js,wasm
  5. package webrtc
  6. import (
  7. "syscall/js"
  8. )
  9. // RTPTransceiver represents a combination of an RTPSender and an RTPReceiver that share a common mid.
  10. type RTPTransceiver struct {
  11. // Pointer to the underlying JavaScript RTCRTPTransceiver object.
  12. underlying js.Value
  13. }
  14. // Direction returns the RTPTransceiver's current direction
  15. func (r *RTPTransceiver) Direction() RTPTransceiverDirection {
  16. return NewRTPTransceiverDirection(r.underlying.Get("direction").String())
  17. }
  18. // Sender returns the RTPTransceiver's RTPSender if it has one
  19. func (r *RTPTransceiver) Sender() *RTPSender {
  20. underlying := r.underlying.Get("sender")
  21. if underlying.IsNull() {
  22. return nil
  23. }
  24. return &RTPSender{underlying: underlying}
  25. }
  26. // Receiver returns the RTPTransceiver's RTPReceiver if it has one
  27. func (r *RTPTransceiver) Receiver() *RTPReceiver {
  28. underlying := r.underlying.Get("receiver")
  29. if underlying.IsNull() {
  30. return nil
  31. }
  32. return &RTPReceiver{underlying: underlying}
  33. }