From 72701d96c4d59a07e03746842ed317632c34d253 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 7 May 2019 15:26:20 -0700 Subject: [PATCH] Add RTCPeerConnection.ontrack --- components/atoms/static_atoms.txt | 1 + components/script/dom/rtcpeerconnection.rs | 26 ++++++++++++++++++- .../dom/webidls/RTCPeerConnection.webidl | 12 +++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/components/atoms/static_atoms.txt b/components/atoms/static_atoms.txt index 7a6022cb64cc..a42e998c958b 100644 --- a/components/atoms/static_atoms.txt +++ b/components/atoms/static_atoms.txt @@ -108,6 +108,7 @@ text time timeupdate toggle +track transitionend unhandledrejection unload diff --git a/components/script/dom/rtcpeerconnection.rs b/components/script/dom/rtcpeerconnection.rs index 3e8cb8eba43c..9ec1940bbb3c 100644 --- a/components/script/dom/rtcpeerconnection.rs +++ b/components/script/dom/rtcpeerconnection.rs @@ -26,10 +26,12 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; use crate::dom::globalscope::GlobalScope; use crate::dom::mediastream::MediaStream; +use crate::dom::mediastreamtrack::MediaStreamTrack; use crate::dom::promise::Promise; use crate::dom::rtcicecandidate::RTCIceCandidate; use crate::dom::rtcpeerconnectioniceevent::RTCPeerConnectionIceEvent; use crate::dom::rtcsessiondescription::RTCSessionDescription; +use crate::dom::rtctrackevent::RTCTrackEvent; use crate::dom::window::Window; use crate::task::TaskCanceller; use crate::task_source::networking::NetworkingTaskSource; @@ -129,7 +131,17 @@ impl WebRtcSignaller for RTCSignaller { ); } - fn on_add_stream(&self, _: &MediaStreamId, _: MediaStreamType) {} + fn on_add_stream(&self, id: &MediaStreamId, ty: MediaStreamType) { + let this = self.trusted.clone(); + let id = *id; + let _ = self.task_source.queue_with_canceller( + task!(on_add_stream: move || { + let this = this.root(); + this.on_add_stream(id, ty); + }), + &self.canceller, + ); + } fn close(&self) { // do nothing @@ -239,6 +251,15 @@ impl RTCPeerConnection { event.upcast::().fire(self.upcast()); } + fn on_add_stream(&self, id: MediaStreamId, ty: MediaStreamType) { + if self.closed.get() { + return; + } + let track = MediaStreamTrack::new(&self.global(), id, ty); + let event = RTCTrackEvent::new(&self.global(), atom!("track"), false, false, &track); + event.upcast::().fire(self.upcast()); + } + /// https://www.w3.org/TR/webrtc/#update-ice-gathering-state fn update_gathering_state(&self, state: GatheringState) { // step 1 @@ -400,6 +421,9 @@ impl RTCPeerConnectionMethods for RTCPeerConnection { /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-icecandidate event_handler!(icecandidate, GetOnicecandidate, SetOnicecandidate); + /// https://www.w3.org/TR/webrtc/#dom-rtcpeerconnection-ontrack + event_handler!(track, GetOntrack, SetOntrack); + /// https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-iceconnectionstatechange event_handler!( iceconnectionstatechange, diff --git a/components/script/dom/webidls/RTCPeerConnection.webidl b/components/script/dom/webidls/RTCPeerConnection.webidl index 0f00f3b5b950..58cb7301ea35 100644 --- a/components/script/dom/webidls/RTCPeerConnection.webidl +++ b/components/script/dom/webidls/RTCPeerConnection.webidl @@ -114,3 +114,15 @@ enum RTCSignalingState { "have-remote-pranswer", "closed" }; + +partial interface RTCPeerConnection { + // sequence getSenders(); + // sequence getReceivers(); + // sequence getTransceivers(); + // RTCRtpSender addTrack(MediaStreamTrack track, + // MediaStream... streams); + // void removeTrack(RTCRtpSender sender); + // RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind, + // optional RTCRtpTransceiverInit init); + attribute EventHandler ontrack; +};