script/dom/webrtc/
rtcrtptransceiver.rs1use std::cell::Cell;
6
7use dom_struct::dom_struct;
8use js::context::JSContext;
9use script_bindings::reflector::{Reflector, reflect_dom_object};
10
11use crate::dom::bindings::codegen::Bindings::RTCRtpTransceiverBinding::{
12 RTCRtpTransceiverDirection, RTCRtpTransceiverMethods,
13};
14use crate::dom::bindings::root::{Dom, DomRoot};
15use crate::dom::globalscope::GlobalScope;
16use crate::dom::rtcrtpsender::RTCRtpSender;
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(direction: RTCRtpTransceiverDirection, sender: &RTCRtpSender) -> Self {
27 Self {
28 reflector_: Reflector::new(),
29 direction: Cell::new(direction),
30 sender: Dom::from_ref(sender),
31 }
32 }
33
34 pub(crate) fn new(
35 cx: &mut JSContext,
36 global: &GlobalScope,
37 direction: RTCRtpTransceiverDirection,
38 ) -> DomRoot<Self> {
39 let sender = RTCRtpSender::new(cx, global);
40 reflect_dom_object(
41 cx,
42 Box::new(Self::new_inherited(direction, &sender)),
43 global,
44 )
45 }
46}
47
48impl RTCRtpTransceiverMethods<crate::DomTypeHolder> for RTCRtpTransceiver {
49 fn Direction(&self) -> RTCRtpTransceiverDirection {
51 self.direction.get()
52 }
53
54 fn SetDirection(&self, direction: RTCRtpTransceiverDirection) {
56 self.direction.set(direction);
57 }
58
59 fn Sender(&self) -> DomRoot<RTCRtpSender> {
61 DomRoot::from_ref(&*self.sender)
62 }
63}