Bug 1246310 - Add a method for attaching local tracks rather than full streams. r=drno
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 18 Apr 2016 17:48:32 +0200
changeset 331883 21fbd1600568cde426d38a5768e2eb0cc925e06f
parent 331882 f569192eb5e826c0bcc4787bf941df459bb484d7
child 331884 cc01ccccdedcc384176c1fa3694d79d0e3213ac0
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno
bugs1246310
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1246310 - Add a method for attaching local tracks rather than full streams. r=drno MozReview-Commit-ID: IdE7H1ItQTR
dom/media/tests/mochitest/pc.js
--- 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,69 @@ 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("Got 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");
+    ok(stream.id, "stream has id");
+    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 this.observedNegotiationNeeded;
+    }
+
+    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