Skip to content

Commit

Permalink
Add RTCPeerConnection.ontrack
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed May 8, 2019
1 parent 318c685 commit 72701d9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/atoms/static_atoms.txt
Expand Up @@ -108,6 +108,7 @@ text
time
timeupdate
toggle
track
transitionend
unhandledrejection
unload
Expand Down
26 changes: 25 additions & 1 deletion components/script/dom/rtcpeerconnection.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -239,6 +251,15 @@ impl RTCPeerConnection {
event.upcast::<Event>().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::<Event>().fire(self.upcast());
}

/// https://www.w3.org/TR/webrtc/#update-ice-gathering-state
fn update_gathering_state(&self, state: GatheringState) {
// step 1
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions components/script/dom/webidls/RTCPeerConnection.webidl
Expand Up @@ -114,3 +114,15 @@ enum RTCSignalingState {
"have-remote-pranswer",
"closed"
};

partial interface RTCPeerConnection {
// sequence<RTCRtpSender> getSenders();
// sequence<RTCRtpReceiver> getReceivers();
// sequence<RTCRtpTransceiver> getTransceivers();
// RTCRtpSender addTrack(MediaStreamTrack track,
// MediaStream... streams);
// void removeTrack(RTCRtpSender sender);
// RTCRtpTransceiver addTransceiver((MediaStreamTrack or DOMString) trackOrKind,
// optional RTCRtpTransceiverInit init);
attribute EventHandler ontrack;
};

0 comments on commit 72701d9

Please sign in to comment.