Bug 1246310 - Add a method for attaching local tracks rather than full streams. r?drno
MozReview-Commit-ID: IdE7H1ItQTR
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -707,16 +707,17 @@ function PeerConnectionWrapper(label, co
label = label + "_" + configuration.label_suffix;
}
this.label = label;
this.whenCreated = Date.now();
this.constraints = [ ];
this.offerOptions = {};
this.streams = [ ];
+ this.streamsForLocalTracks = [ ];
this.mediaElements = [ ];
this.dataChannels = [ ];
this._local_ice_candidates = [];
this._remote_ice_candidates = [];
this.localRequiresTrickleIce = false;
this.remoteRequiresTrickleIce = false;
@@ -816,16 +817,68 @@ PeerConnectionWrapper.prototype = {
return this._pc.iceConnectionState;
},
setIdentityProvider: function(provider, protocol, identity) {
this._pc.setIdentityProvider(provider, protocol, identity);
},
/**
+ * Attaches a local track to this RTCPeerConnection using
+ * RTCPeerConnection.addTrack().
+ *
+ * Also creates a media element playing a MediaStream containing all
+ * tracks that have been added to `stream` using `attachLocalTrack()`.
+ *
+ * @param {MediaStreamTrack} track
+ * MediaStreamTrack to handle
+ * @param {MediaStream} stream
+ * MediaStream to use as container for `track` on remote side
+ */
+ attachLocalTrack : function(track, stream) {
+ info("Get a local " + track.kind + " track");
+
+ this.expectNegotiationNeeded();
+ var sender = this._pc.addTrack(track, stream);
+ is(sender.track, track, "addTrack returns sender");
+
+ ok(track.id, "track has id");
+ ok(track.kind, "track has kind");
+ this.expectedLocalTrackInfoById[track.id] = {
+ type: track.kind,
+ streamId: stream.id,
+ };
+
+ var mappedStream =
+ this.streamsForLocalTracks.find(o => o.fromStreamId == stream.id);
+
+ if (mappedStream) {
+ mappedStream.stream.addTrack(track);
+ return;
+ }
+
+ mappedStream = new MediaStream([track]);
+ this.streamsForLocalTracks.push(
+ { fromStreamId: stream.id
+ , stream: mappedStream
+ }
+ );
+
+ var element = createMediaElement(track.kind, this.label + '_tracks_' + this.streamsForLocalTracks.length);
+ this.mediaElements.push(element);
+ element.srcObject = mappedStream;
+ element.play();
+
+ // Store local media elements so that we can stop them when done.
+ // Don't store remote ones because they should stop when the PC does.
+ this.localMediaElements.push(element);
+ return this.observedNegotiationNeeded;
+ },
+
+ /**
* Callback when we get media from either side. Also an appropriate
* HTML media element will be created.
*
* @param {MediaStream} stream
* Media stream to handle
* @param {string} type
* The type of media stream ('audio' or 'video')
* @param {string} side