Bug 1263312 - Make addIceCandidate, setLocal/RemoteDescription take a dictionary draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 11 Apr 2016 00:09:34 -0400
changeset 350217 61bc73849b657378f11fa01eff9424e87ac6bf71
parent 348895 d9b1a9829c8ee2862955043f28183efa07de3d2b
child 518270 f6c249adae9cc8b69521a960f39bb7b823f8e9a1
push id15270
push userjbruaroey@mozilla.com
push dateTue, 12 Apr 2016 23:26:33 +0000
bugs1263312
milestone48.0a1
Bug 1263312 - Make addIceCandidate, setLocal/RemoteDescription take a dictionary MozReview-Commit-ID: 5nyjvIiURDQ
dom/media/PeerConnection.js
dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
dom/webidl/RTCIceCandidate.webidl
dom/webidl/RTCPeerConnection.webidl
dom/webidl/RTCSessionDescription.webidl
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -238,17 +238,17 @@ RTCIceCandidate.prototype = {
   contractID: PC_ICE_CONTRACT,
   QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports,
                                          Ci.nsIDOMGlobalPropertyInitializer]),
 
   init: function(win) { this._win = win; },
 
   __init: function(dict) {
     this.candidate = dict.candidate;
-    this.sdpMid = dict.sdpMid;
+    this.sdpMid = ("sdpMid" in dict)? dict.sdpMid : null;
     this.sdpMLineIndex = ("sdpMLineIndex" in dict)? dict.sdpMLineIndex : null;
   }
 };
 
 function RTCSessionDescription() {
   this.type = this.sdp = null;
 }
 RTCSessionDescription.prototype = {
@@ -852,17 +852,17 @@ RTCPeerConnection.prototype = {
         default:
           throw new this._win.DOMException(
               "Invalid type " + desc.type + " provided to setLocalDescription",
               "InvalidParameterError");
       }
 
       if (desc.type !== "rollback" && !desc.sdp) {
         throw new this._win.DOMException(
-            "Empty or null SDP provided to setLocalDescription",
+            "No SDP provided to setLocalDescription",
             "InvalidParameterError");
       }
 
       return this._chain(() => this.getPermission()
           .then(() => new this._win.Promise((resolve, reject) => {
         this._onSetLocalDescriptionSuccess = resolve;
         this._onSetLocalDescriptionFailure = reject;
         this._impl.setLocalDescription(type, desc.sdp);
@@ -936,17 +936,17 @@ RTCPeerConnection.prototype = {
         default:
           throw new this._win.DOMException(
               "Invalid type " + desc.type + " provided to setRemoteDescription",
               "InvalidParameterError");
       }
 
       if (!desc.sdp && desc.type !== "rollback") {
         throw new this._win.DOMException(
-            "Empty or null SDP provided to setRemoteDescription",
+            "No SDP provided to setRemoteDescription",
             "InvalidParameterError");
       }
 
       // Get caller's origin before hitting the promise chain
       let origin = Cu.getWebIDLCallerPrincipal().origin;
 
       return this._chain(() => {
         let setRem = this.getPermission()
--- a/dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
+++ b/dom/media/tests/mochitest/test_peerConnection_promiseSendOnly.html
@@ -10,17 +10,20 @@
     bug: "1091898",
     title: "PeerConnection with promises (sendonly)",
     visible: true
   });
 
   var pc1 = new RTCPeerConnection();
   var pc2 = new RTCPeerConnection();
 
-  var add = (pc, can, failed) => can && pc.addIceCandidate(can).catch(failed);
+  // helper to test that addIceCandidate and setLocalDescription take dictionary
+  var dictionary = obj => JSON.parse(JSON.stringify(obj));
+
+  var add = (pc, can, fail) => can && pc.addIceCandidate(dictionary(can)).catch(fail);
   pc1.onicecandidate = e => add(pc2, e.candidate, generateErrorCallback());
   pc2.onicecandidate = e => add(pc1, e.candidate, generateErrorCallback());
 
   var v1, v2;
   var delivered = new Promise(resolve => pc2.ontrack = e => {
     // Test RTCTrackEvent here.
     ok(e.streams.length > 0, "has streams");
     ok(e.streams[0].getTracks().some(track => track == e.track), "has track");
@@ -39,21 +42,21 @@
     v2 = createMediaElement('video', 'v2');
     var canPlayThrough = new Promise(resolve => v2.canplaythrough = e => resolve());
 
     is(v2.currentTime, 0, "v2.currentTime is zero at outset");
 
     navigator.mediaDevices.getUserMedia({ video: true, audio: true })
     .then(stream => (v1.srcObject = stream).getTracks().forEach(t => pc1.addTrack(t, stream)))
     .then(() => pc1.createOffer({})) // check that createOffer accepts arg.
-    .then(offer => pc1.setLocalDescription(offer))
-    .then(() => pc2.setRemoteDescription(pc1.localDescription))
+    .then(offer => pc1.setLocalDescription(dictionary(offer)))
+    .then(() => pc2.setRemoteDescription(dictionary(pc1.localDescription)))
     .then(() => pc2.createAnswer({}))  // check that createAnswer accepts arg.
-    .then(answer => pc2.setLocalDescription(answer))
-    .then(() => pc1.setRemoteDescription(pc2.localDescription))
+    .then(answer => pc2.setLocalDescription(dictionary(answer)))
+    .then(() => pc1.setRemoteDescription(dictionary(pc2.localDescription)))
     .then(() => delivered)
 //    .then(() => canPlayThrough)    // why doesn't this fire?
     .then(() => waitUntil(() => v2.currentTime > 0 && v2.srcObject.currentTime > 0))
     .then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
     .then(() => ok(true, "Connected."))
     .catch(reason => ok(false, "unexpected failure: " + reason))
     .then(networkTestFinished);
   });
--- a/dom/webidl/RTCIceCandidate.webidl
+++ b/dom/webidl/RTCIceCandidate.webidl
@@ -3,23 +3,23 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * http://dev.w3.org/2011/webrtc/editor/webrtc.html#idl-def-RTCIceCandidate
  */
 
 dictionary RTCIceCandidateInit {
-  DOMString? candidate = null;
-  DOMString? sdpMid = null;
+  required DOMString candidate;
+  DOMString sdpMid;
   unsigned short sdpMLineIndex;
 };
 
 [Pref="media.peerconnection.enabled",
  JSImplementation="@mozilla.org/dom/rtcicecandidate;1",
  Constructor(optional RTCIceCandidateInit candidateInitDict)]
 interface RTCIceCandidate {
-  attribute DOMString?      candidate;
-  attribute DOMString?      sdpMid;
-  attribute unsigned short? sdpMLineIndex;
+  readonly attribute DOMString       candidate;
+  readonly attribute DOMString?      sdpMid;
+  readonly attribute unsigned short? sdpMLineIndex;
 
   jsonifier;
 };
--- a/dom/webidl/RTCPeerConnection.webidl
+++ b/dom/webidl/RTCPeerConnection.webidl
@@ -93,22 +93,22 @@ interface RTCPeerConnection : EventTarge
   [Pref="media.peerconnection.identity.enabled"]
   void setIdentityProvider (DOMString provider,
                             optional DOMString protocol,
                             optional DOMString username);
   [Pref="media.peerconnection.identity.enabled"]
   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);
+  Promise<void> setLocalDescription (RTCSessionDescriptionInit description);
+  Promise<void> setRemoteDescription (RTCSessionDescriptionInit 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;
 
@@ -165,21 +165,21 @@ partial interface RTCPeerConnection {
   // Dummy Promise<void> return values avoid "WebIDL.WebIDLError: error:
   // We have overloads with both Promise and non-Promise return types"
 
   Promise<void> createOffer (RTCSessionDescriptionCallback successCallback,
                              RTCPeerConnectionErrorCallback failureCallback,
                              optional RTCOfferOptions options);
   Promise<void> createAnswer (RTCSessionDescriptionCallback successCallback,
                               RTCPeerConnectionErrorCallback failureCallback);
-  Promise<void> setLocalDescription (RTCSessionDescription description,
+  Promise<void> setLocalDescription (RTCSessionDescriptionInit description,
                                      VoidFunction successCallback,
                                      RTCPeerConnectionErrorCallback failureCallback);
-  Promise<void> setRemoteDescription (RTCSessionDescription description,
+  Promise<void> setRemoteDescription (RTCSessionDescriptionInit description,
                                       VoidFunction successCallback,
                                       RTCPeerConnectionErrorCallback failureCallback);
-  Promise<void> addIceCandidate (RTCIceCandidate candidate,
+  Promise<void> addIceCandidate ((RTCIceCandidateInit or RTCIceCandidate) candidate,
                                  VoidFunction successCallback,
                                  RTCPeerConnectionErrorCallback failureCallback);
   Promise<void> getStats (MediaStreamTrack? selector,
                           RTCStatsCallback successCallback,
                           RTCPeerConnectionErrorCallback failureCallback);
 };
--- a/dom/webidl/RTCSessionDescription.webidl
+++ b/dom/webidl/RTCSessionDescription.webidl
@@ -10,21 +10,21 @@
 enum RTCSdpType {
   "offer",
   "pranswer",
   "answer",
   "rollback"
 };
 
 dictionary RTCSessionDescriptionInit {
-  RTCSdpType? type = null;
-  DOMString? sdp = "";
+  required RTCSdpType type;
+  DOMString sdp;
 };
 
 [Pref="media.peerconnection.enabled",
  JSImplementation="@mozilla.org/dom/rtcsessiondescription;1",
  Constructor(optional RTCSessionDescriptionInit descriptionInitDict)]
 interface RTCSessionDescription {
-  attribute RTCSdpType? type;
-  attribute DOMString? sdp;
+  attribute RTCSdpType type;
+  attribute DOMString sdp;
 
   jsonifier;
 };