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::rust::HandleObject;
7
8use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
9    RTCSdpType, RTCSessionDescriptionInit, RTCSessionDescriptionMethods,
10};
11use crate::dom::bindings::error::Fallible;
12use crate::dom::bindings::reflector::{Reflector, reflect_dom_object_with_proto};
13use crate::dom::bindings::root::DomRoot;
14use crate::dom::bindings::str::DOMString;
15use crate::dom::window::Window;
16use crate::script_runtime::CanGc;
17
18#[dom_struct]
19pub(crate) struct RTCSessionDescription {
20    reflector: Reflector,
21    ty: RTCSdpType,
22    sdp: DOMString,
23}
24
25impl RTCSessionDescription {
26    pub(crate) fn new_inherited(ty: RTCSdpType, sdp: DOMString) -> RTCSessionDescription {
27        RTCSessionDescription {
28            reflector: Reflector::new(),
29            ty,
30            sdp,
31        }
32    }
33
34    fn new(
35        window: &Window,
36        proto: Option<HandleObject>,
37        ty: RTCSdpType,
38        sdp: DOMString,
39        can_gc: CanGc,
40    ) -> DomRoot<RTCSessionDescription> {
41        reflect_dom_object_with_proto(
42            Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
43            window,
44            proto,
45            can_gc,
46        )
47    }
48}
49
50impl RTCSessionDescriptionMethods<crate::DomTypeHolder> for RTCSessionDescription {
51    /// <https://w3c.github.io/webrtc-pc/#dom-sessiondescription>
52    fn Constructor(
53        window: &Window,
54        proto: Option<HandleObject>,
55        can_gc: CanGc,
56        config: &RTCSessionDescriptionInit,
57    ) -> Fallible<DomRoot<RTCSessionDescription>> {
58        Ok(RTCSessionDescription::new(
59            window,
60            proto,
61            config.type_,
62            config.sdp.clone(),
63            can_gc,
64        ))
65    }
66
67    /// <https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-type>
68    fn Type(&self) -> RTCSdpType {
69        self.ty
70    }
71
72    /// <https://w3c.github.io/webrtc-pc/#dom-rtcsessiondescription-sdp>
73    fn Sdp(&self) -> DOMString {
74        self.sdp.clone()
75    }
76}