Skip to content
Permalink
Browse files

Add constructors for MediaStream

  • Loading branch information...
Manishearth committed May 7, 2019
1 parent 72701d9 commit b4ddf6837f53f126f4b26dea5fedc07ca826ff6f
Showing with 28 additions and 5 deletions.
  1. +23 −0 components/script/dom/mediastream.rs
  2. +5 −5 components/script/dom/webidls/MediaStream.webidl
@@ -4,12 +4,14 @@

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::MediaStreamBinding::{self, MediaStreamMethods};
use crate::dom::bindings::error::Fallible;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastreamtrack::MediaStreamTrack;
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_media::streams::MediaStreamType;
use std::cell::Ref;
@@ -36,6 +38,27 @@ impl MediaStream {
)
}

pub fn Constructor(global: &Window) -> Fallible<DomRoot<MediaStream>> {
Ok(MediaStream::new(&global.global()))
}

pub fn Constructor_(_: &Window, stream: &MediaStream) -> Fallible<DomRoot<MediaStream>> {
Ok(stream.Clone())
}

pub fn Constructor__(
global: &Window,
tracks: Vec<DomRoot<MediaStreamTrack>>,
) -> Fallible<DomRoot<MediaStream>> {
let new = MediaStream::new(&global.global());
for track in tracks {
// this is quadratic, but shouldn't matter much
// if this becomes a problem we can use a hash map
new.AddTrack(&track)
}
Ok(new)
}

pub fn get_tracks(&self) -> Ref<[Dom<MediaStreamTrack>]> {
Ref::map(self.tracks.borrow(), |tracks| &**tracks)
}
@@ -4,11 +4,11 @@

// https://w3c.github.io/mediacapture-main/#dom-mediastream

// [Exposed=Window,
// Constructor,
// Constructor(MediaStream stream),
// Constructor(sequence<MediaStreamTrack> tracks)]
[Exposed=Window, Pref="dom.webrtc.enabled"]
[Exposed=Window,
Constructor,
Constructor(MediaStream stream),
Constructor(sequence<MediaStreamTrack> tracks),
Pref="dom.webrtc.enabled"]
interface MediaStream : EventTarget {
// readonly attribute DOMString id;
sequence<MediaStreamTrack> getAudioTracks();

0 comments on commit b4ddf68

Please sign in to comment.
You can’t perform that action at this time.