Skip to main content

script/dom/webrtc/
rtcsessiondescription.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6use js::context::JSContext;
7use js::rust::HandleObject;
8use script_bindings::domstring::TracedDOMString;
9use script_bindings::reflector::{Reflector, reflect_dom_object_with_proto};
10
11use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
12    RTCSdpType, RTCSessionDescriptionInit, RTCSessionDescriptionMethods,
13};
14use crate::dom::bindings::error::Fallible;
15use crate::dom::bindings::root::DomRoot;
16use crate::dom::bindings::str::DOMString;
17use crate::dom::window::Window;
18
19#[dom_struct]
20pub(crate) struct RTCSessionDescription {
21    reflector: Reflector,
22    ty: RTCSdpType,
23    sdp: TracedDOMString,
24}
25
26impl RTCSessionDescription {
27    pub(crate) fn new_inherited(ty: RTCSdpType, sdp: DOMString) -> RTCSessionDescription {
28        RTCSessionDescription {
29            reflector: Reflector::new(),
30            ty,
31            sdp: sdp.traced(),
32        }
33    }
34
35    pub(crate) fn new(
36        cx: &mut JSContext,
37        window: &Window,
38        proto: Option<HandleObject>,
39        ty: RTCSdpType,
40        sdp: DOMString,
41    ) -> DomRoot<RTCSessionDescription> {
42        reflect_dom_object_with_proto(
43            cx,
44            Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
45            window,
46            proto,
47        )
48    }
49}
50
51impl RTCSessionDescriptionMethods<crate::DomTypeHolder> for RTCSessionDescription {
52    /// <https://w3c.github.io/webrtc-pc/#dom-sessiondescription>
53    fn Constructor(
54        cx: &mut JSContext,
55        window: &Window,
56        proto: Option<HandleObject>,
57        config: &RTCSessionDescriptionInit,
58    ) -> Fallible<DomRoot<RTCSessionDescription>> {
59        Ok(RTCSessionDescription::new(
60            cx,
61            window,
62            proto,
63            config.type_,
64            config.sdp.clone(),
65        ))
66    }
67
68    /// <https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-type>
69    fn Type(&self) -> RTCSdpType {
70        self.ty
71    }
72
73    /// <https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-sdp>
74    fn Sdp(&self) -> DOMString {
75        self.sdp.clone().root()
76    }
77}