script/dom/webrtc/
rtcrtptransceiver.rs1use std::cell::Cell;
6
7use dom_struct::dom_struct;
8
9use crate::dom::bindings::codegen::Bindings::RTCRtpTransceiverBinding::{
10 RTCRtpTransceiverDirection, RTCRtpTransceiverMethods,
11};
12use crate::dom::bindings::reflector::{Reflector, reflect_dom_object};
13use crate::dom::bindings::root::{Dom, DomRoot};
14use crate::dom::globalscope::GlobalScope;
15use crate::dom::rtcrtpsender::RTCRtpSender;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct RTCRtpTransceiver {
20 reflector_: Reflector,
21 sender: Dom<RTCRtpSender>,
22 direction: Cell<RTCRtpTransceiverDirection>,
23}
24
25impl RTCRtpTransceiver {
26 fn new_inherited(
27 global: &GlobalScope,
28 direction: RTCRtpTransceiverDirection,
29 can_gc: CanGc,
30 ) -> Self {
31 let sender = RTCRtpSender::new(global, can_gc);
32 Self {
33 reflector_: Reflector::new(),
34 direction: Cell::new(direction),
35 sender: Dom::from_ref(&*sender),
36 }
37 }
38
39 pub(crate) fn new(
40 global: &GlobalScope,
41 direction: RTCRtpTransceiverDirection,
42 can_gc: CanGc,
43 ) -> DomRoot<Self> {
44 reflect_dom_object(
45 Box::new(Self::new_inherited(global, direction, can_gc)),
46 global,
47 can_gc,
48 )
49 }
50}
51
52impl RTCRtpTransceiverMethods<crate::DomTypeHolder> for RTCRtpTransceiver {
53 fn Direction(&self) -> RTCRtpTransceiverDirection {
55 self.direction.get()
56 }
57
58 fn SetDirection(&self, direction: RTCRtpTransceiverDirection) {
60 self.direction.set(direction);
61 }
62
63 fn Sender(&self) -> DomRoot<RTCRtpSender> {
65 DomRoot::from_ref(&*self.sender)
66 }
67}