Fill in RTCSessionDescription

This commit is contained in:
Manish Goregaokar 2019-01-26 09:41:31 -08:00
parent 69931934ac
commit be48cf23f9
2 changed files with 36 additions and 8 deletions

View file

@ -3,11 +3,15 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding;
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::RTCSessionDescriptionInit;
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::RTCSessionDescriptionMethods;
use crate::dom::bindings::codegen::Bindings::RTCSessionDescriptionBinding::{
RTCSdpType, RTCSessionDescriptionInit,
};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::{DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window;
use dom_struct::dom_struct;
@ -15,18 +19,26 @@ use dom_struct::dom_struct;
#[dom_struct]
pub struct RTCSessionDescription {
reflector: Reflector,
ty: RTCSdpType,
sdp: DOMString,
}
impl RTCSessionDescription {
pub fn new_inherited() -> RTCSessionDescription {
pub fn new_inherited(ty: RTCSdpType, sdp: DOMString) -> RTCSessionDescription {
RTCSessionDescription {
reflector: Reflector::new(),
ty,
sdp,
}
}
pub fn new(global: &GlobalScope) -> DomRoot<RTCSessionDescription> {
pub fn new(
global: &GlobalScope,
ty: RTCSdpType,
sdp: DOMString,
) -> DomRoot<RTCSessionDescription> {
reflect_dom_object(
Box::new(RTCSessionDescription::new_inherited()),
Box::new(RTCSessionDescription::new_inherited(ty, sdp)),
global,
RTCSessionDescriptionBinding::Wrap,
)
@ -34,8 +46,24 @@ impl RTCSessionDescription {
pub fn Constructor(
window: &Window,
_config: &RTCSessionDescriptionInit,
config: &RTCSessionDescriptionInit,
) -> Fallible<DomRoot<RTCSessionDescription>> {
Ok(RTCSessionDescription::new(&window.global()))
Ok(RTCSessionDescription::new(
&window.global(),
config.type_,
config.sdp.clone(),
))
}
}
impl RTCSessionDescriptionMethods for RTCSessionDescription {
/// https://www.w3.org/TR/webrtc/#dom-rtcsessiondescription-type
fn Type(&self) -> RTCSdpType {
self.ty
}
/// https://www.w3.org/TR/webrtc/#dom-rtcsessiondescription-sdp
fn Sdp(&self) -> DOMString {
self.sdp.clone()
}
}

View file

@ -7,8 +7,8 @@
[Constructor(RTCSessionDescriptionInit descriptionInitDict),
Exposed=Window, Pref="dom.webrtc.enabled"]
interface RTCSessionDescription {
// readonly attribute RTCSdpType type;
// readonly attribute DOMString sdp;
readonly attribute RTCSdpType type;
readonly attribute DOMString sdp;
// [Default] object toJSON();
};