Skip to content
Permalink
Browse files

Add MediaStream.getVideoTracks(), MediaStream.getAudioTracks()

  • Loading branch information...
Manishearth committed May 7, 2019
1 parent 36abbca commit 70e1c29ae98f0dd4090c0093850ee07faba0dcbe
Showing with 23 additions and 2 deletions.
  1. +21 −0 components/script/dom/mediastream.rs
  2. +2 −2 components/script/dom/webidls/MediaStream.webidl
@@ -10,6 +10,7 @@ use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastreamtrack::MediaStreamTrack;
use dom_struct::dom_struct;
use servo_media::streams::MediaStreamType;
use std::cell::Ref;

#[dom_struct]
@@ -52,4 +53,24 @@ impl MediaStreamMethods for MediaStream {
.map(|x| DomRoot::from_ref(&**x))
.collect()
}

/// https://w3c.github.io/mediacapture-main/#dom-mediastream-getaudiotracks
fn GetAudioTracks(&self) -> Vec<DomRoot<MediaStreamTrack>> {
self.tracks
.borrow()
.iter()
.filter(|x| x.ty() == MediaStreamType::Audio)
.map(|x| DomRoot::from_ref(&**x))
.collect()
}

/// https://w3c.github.io/mediacapture-main/#dom-mediastream-getvideotracks
fn GetVideoTracks(&self) -> Vec<DomRoot<MediaStreamTrack>> {
self.tracks
.borrow()
.iter()
.filter(|x| x.ty() == MediaStreamType::Video)
.map(|x| DomRoot::from_ref(&**x))
.collect()
}
}
@@ -11,8 +11,8 @@
[Exposed=Window, Pref="dom.webrtc.enabled"]
interface MediaStream : EventTarget {
// readonly attribute DOMString id;
// sequence<MediaStreamTrack> getAudioTracks();
// sequence<MediaStreamTrack> getVideoTracks();
sequence<MediaStreamTrack> getAudioTracks();
sequence<MediaStreamTrack> getVideoTracks();
sequence<MediaStreamTrack> getTracks();
// MediaStreamTrack? getTrackById(DOMString trackId);
// void addTrack(MediaStreamTrack track);

0 comments on commit 70e1c29

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