Add RTCPeerConnection::AddStream

This commit is contained in:
Manish Goregaokar 2019-01-28 13:48:04 -08:00
parent 8b0719a6f2
commit 2d8ac7825c
3 changed files with 25 additions and 2 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::MediaStreamBinding; use crate::dom::bindings::codegen::Bindings::MediaStreamBinding;
use crate::dom::bindings::reflector::reflect_dom_object; use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::root::DomRoot;
@ -9,19 +10,20 @@ use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use servo_media::webrtc::MediaStream as BackendMediaStream; use servo_media::webrtc::MediaStream as BackendMediaStream;
use std::mem;
#[dom_struct] #[dom_struct]
pub struct MediaStream { pub struct MediaStream {
eventtarget: EventTarget, eventtarget: EventTarget,
#[ignore_malloc_size_of = "defined in servo-media"] #[ignore_malloc_size_of = "defined in servo-media"]
tracks: Vec<Box<BackendMediaStream>>, tracks: DomRefCell<Vec<Box<BackendMediaStream>>>,
} }
impl MediaStream { impl MediaStream {
pub fn new_inherited(tracks: Vec<Box<BackendMediaStream>>) -> MediaStream { pub fn new_inherited(tracks: Vec<Box<BackendMediaStream>>) -> MediaStream {
MediaStream { MediaStream {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
tracks, tracks: DomRefCell::new(tracks),
} }
} }
@ -32,4 +34,12 @@ impl MediaStream {
MediaStreamBinding::Wrap, MediaStreamBinding::Wrap,
) )
} }
pub fn get_tracks(&self) -> Vec<Box<BackendMediaStream>> {
// XXXManishearth we have hard ownership constraints here so we actually empty the vec,
// ideally we should only have a media stream id here, or servo-media hands
// out Arcs
let mut tracks = self.tracks.borrow_mut();
mem::replace(&mut *tracks, vec![])
}
} }

View file

@ -22,6 +22,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom};
use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::event::{Event, EventBubbles, EventCancelable};
use crate::dom::eventtarget::EventTarget; use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::mediastream::MediaStream;
use crate::dom::promise::Promise; use crate::dom::promise::Promise;
use crate::dom::rtcicecandidate::RTCIceCandidate; use crate::dom::rtcicecandidate::RTCIceCandidate;
use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent; use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent;
@ -390,6 +391,15 @@ impl RTCPeerConnectionMethods for RTCPeerConnection {
}).into()); }).into());
p p
} }
// https://w3c.github.io/webrtc-pc/#legacy-interface-extensions
fn AddStream(&self, stream: &MediaStream) {
let mut tracks = stream.get_tracks();
for track in tracks.drain(..) {
self.controller.borrow().as_ref().unwrap().add_stream(track);
}
}
} }
impl From<SessionDescription> for RTCSessionDescriptionInit { impl From<SessionDescription> for RTCSessionDescriptionInit {

View file

@ -34,6 +34,9 @@ interface RTCPeerConnection : EventTarget {
// attribute EventHandler oniceconnectionstatechange; // attribute EventHandler oniceconnectionstatechange;
// attribute EventHandler onicegatheringstatechange; // attribute EventHandler onicegatheringstatechange;
// attribute EventHandler onconnectionstatechange; // attribute EventHandler onconnectionstatechange;
// removed from spec, but still shipped by browsers
void addStream (MediaStream stream);
}; };
dictionary RTCConfiguration { dictionary RTCConfiguration {