Bug 1263312 - Have addIceCandidate take a dictionary. draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 08 Nov 2016 21:36:04 -0500
changeset 439942 defa38ee870e9b39fa59a9011cd6f8459404e25b
parent 439941 c53972e0312feed55dfbf127c9675bb110e7f116
child 439943 4da8dfb6dba52bd5ca9865e1a2f13d695956888b
push id36139
push userjbruaroey@mozilla.com
push dateWed, 16 Nov 2016 21:34:07 +0000
bugs1263312
milestone53.0a1
Bug 1263312 - Have addIceCandidate take a dictionary. MozReview-Commit-ID: HuWYZkGS2Wg
dom/media/PeerConnection.js
dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
dom/webidl/RTCPeerConnection.webidl
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1014,22 +1014,25 @@ RTCPeerConnection.prototype = {
     }
 
     let sections = desc.sdp.split(/(?:\r\n?|\n)m=/);
     let topSection = sections.shift();
     this._canTrickle =
       containsTrickle(topSection) || sections.every(containsTrickle);
   },
 
-
   addIceCandidate: function(c, onSuccess, onError) {
     return this._legacyCatchAndCloseGuard(onSuccess, onError, () => {
-      if (!c.candidate && !c.sdpMLineIndex) {
-        throw new this._win.DOMException("Invalid candidate passed to addIceCandidate!",
-                                         "InvalidParameterError");
+      if (!c) {
+        // TODO: Implement processing for end-of-candidates indication
+        return Promise.resolve();
+      }
+      if (c.sdpMid === null && c.sdpMLineIndex === null) {
+        throw new this._win.DOMException("Invalid candidate (both sdpMid and sdpMLineIndex are null).",
+                                         "TypeError");
       }
       return this._chain(() => new this._win.Promise((resolve, reject) => {
         this._onAddIceCandidateSuccess = resolve;
         this._onAddIceCandidateError = reject;
         this._impl.addIceCandidate(c.candidate, c.sdpMid || "", c.sdpMLineIndex);
       }));
     });
   },
--- a/dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
+++ b/dom/media/tests/mochitest/test_peerConnection_addIceCandidate.html
@@ -50,24 +50,24 @@
         .then(
           generateErrorCallback("addIceCandidate should have failed."),
           err => {
             is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
           }
         );
       },
       function PC_REMOTE_ADD_CANDIDATE_MISSING_INDEX(test) {
-        // Note: it is probably not a good idea to automatically fill a missing
-        //       MLineIndex with a default value of zero, see bug 1157034
         var broken = new RTCIceCandidate(
           {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host"});
         return test.pcRemote._pc.addIceCandidate(broken)
         .then(
-          // FIXME this needs to be updated once bug 1157034 is fixed
-          todo(false, "Missing index in got automatically set to a valid value bz://1157034")
+          generateErrorCallback("addIceCandidate should have failed."),
+          err => {
+            is(err.name, "TypeError", "Error is TypeError");
+          }
         );
       },
       function PC_REMOTE_ADD_VALID_CANDIDATE(test) {
         var candidate = new RTCIceCandidate(
           {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
            sdpMLineIndex: 0});
         return test.pcRemote._pc.addIceCandidate(candidate)
         .then(ok(true, "Successfully added valid ICE candidate"));
@@ -81,16 +81,28 @@
         return test.pcRemote._pc.addIceCandidate(bogus)
         .then(
           generateErrorCallback("addIceCandidate should have failed."),
           err => {
             is(err.name, "InvalidCandidateError", "Error is InvalidCandidateError");
           }
         );
       },
+      function PC_REMOTE_ADD_MATCHING_MID_AND_MISSING_INDEX(test) {
+        // Note: it is probably not a good idea to automatically fill a missing
+        //       MLineIndex with a default value of zero, see bug 1157034
+        var broken = new RTCIceCandidate(
+          {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
+           sdpMid: "sdparta_0"});
+        return test.pcRemote._pc.addIceCandidate(broken)
+        .then(
+          // FIXME this needs to be updated once bug 1157034 is fixed
+          todo(false, "Missing index in got automatically set to a valid value bz://1157034")
+        );
+      },
       function PC_REMOTE_ADD_MATCHING_MID_AND_LEVEL_CANDIDATE(test) {
         var candidate = new mozRTCIceCandidate(
           {candidate:"candidate:1 1 UDP 2130706431 192.168.2.1 50005 typ host",
            sdpMLineIndex: 0,
            sdpMid: "sdparta_0"});
         return test.pcRemote._pc.addIceCandidate(candidate)
         .then(ok(true, "Successfully added valid ICE candidate with matching mid and level"));
       }
--- a/dom/webidl/RTCPeerConnection.webidl
+++ b/dom/webidl/RTCPeerConnection.webidl
@@ -98,17 +98,17 @@ interface RTCPeerConnection : EventTarge
   Promise<DOMString> getIdentityAssertion();
   Promise<RTCSessionDescription> createOffer (optional RTCOfferOptions options);
   Promise<RTCSessionDescription> createAnswer (optional RTCAnswerOptions options);
   Promise<void> setLocalDescription (RTCSessionDescription description);
   Promise<void> setRemoteDescription (RTCSessionDescription description);
   readonly attribute RTCSessionDescription? localDescription;
   readonly attribute RTCSessionDescription? remoteDescription;
   readonly attribute RTCSignalingState signalingState;
-  Promise<void> addIceCandidate (RTCIceCandidate candidate);
+  Promise<void> addIceCandidate ((RTCIceCandidateInit or RTCIceCandidate)? candidate);
   readonly attribute boolean? canTrickleIceCandidates;
   readonly attribute RTCIceGatheringState iceGatheringState;
   readonly attribute RTCIceConnectionState iceConnectionState;
   [Pref="media.peerconnection.identity.enabled"]
   readonly attribute Promise<RTCIdentityAssertion> peerIdentity;
   [Pref="media.peerconnection.identity.enabled"]
   readonly attribute DOMString? idpLoginUrl;