Skip to content
Permalink
Browse files

Add RTCPeerConnection.ontrack

  • Loading branch information...
Manishearth committed May 7, 2019
1 parent 318c685 commit 72701d96c4d59a07e03746842ed317632c34d253
@@ -108,6 +108,7 @@ text
time
timeupdate
toggle
track
transitionend
unhandledrejection
unload
@@ -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::<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
@@ -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,
@@ -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.
You can’t perform that action at this time.