Bug 1063808 - Support old constraint-like RTCOfferOptions for a bit. r=smaug, r=abr, a=lmandel
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 09 Sep 2014 01:12:24 -0400
changeset 216706 d4082d3a082c
parent 216705 fdf2f580b665
child 216707 767c0d1269a9
child 216711 c43d3d833973
push id3883
push userryanvm@gmail.com
push date2014-09-11 20:34 +0000
treeherdermozilla-beta@d4082d3a082c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, abr, lmandel
bugs1063808
milestone33.0
Bug 1063808 - Support old constraint-like RTCOfferOptions for a bit. r=smaug, r=abr, a=lmandel
dom/media/PeerConnection.js
dom/media/tests/mochitest/pc.js
dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html
dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html
dom/webidl/RTCPeerConnection.webidl
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -551,17 +551,56 @@ RTCPeerConnection.prototype = {
     Object.defineProperty(this, name,
                           {
                             get:function()  { return this.getEH(name); },
                             set:function(h) { return this.setEH(name, h); }
                           });
   },
 
   createOffer: function(onSuccess, onError, options) {
-    options = options || {};
+
+    // TODO: Remove old constraint-like RTCOptions support soon (Bug 1064223).
+    function convertLegacyOptions(o) {
+      if (!(o.mandatory || o.optional) ||
+          Object.keys(o).length != ((o.mandatory && o.optional)? 2 : 1)) {
+        return false;
+      }
+      let old = o.mandatory || {};
+      if (o.mandatory) {
+        delete o.mandatory;
+      }
+      if (o.optional) {
+        o.optional.forEach(one => {
+          // The old spec had optional as an array of objects w/1 attribute each.
+          // Assumes our JS-webidl bindings only populate passed-in properties.
+          let key = Object.keys(one)[0];
+          if (key && old[key] === undefined) {
+            old[key] = one[key];
+          }
+        });
+        delete o.optional;
+      }
+      o.offerToReceiveAudio = old.OfferToReceiveAudio;
+      o.offerToReceiveVideo = old.OfferToReceiveVideo;
+      o.mozDontOfferDataChannel = old.MozDontOfferDataChannel;
+      o.mozBundleOnly = old.MozBundleOnly;
+      Object.keys(o).forEach(k => {
+        if (o[k] === undefined) {
+          delete o[k];
+        }
+      });
+      return true;
+    }
+
+    if (options && convertLegacyOptions(options)) {
+      this.logWarning(
+          "Mandatory/optional in createOffer options is deprecated! Use " +
+          JSON.stringify(options) + " instead (note the case difference)!",
+          null, 0);
+    }
     this._queueOrRun({
       func: this._createOffer,
       args: [onSuccess, onError, options],
       wait: true
     });
   },
 
   _createOffer: function(onSuccess, onError, options) {
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -1902,17 +1902,28 @@ PeerConnectionWrapper.prototype = {
    * @param options
    *        The options to be examined.
    */
   audioInOfferOptions : function
     PCW_audioInOfferOptions(options) {
     if (!options) {
       return 0;
     }
-    if (options.offerToReceiveAudio) {
+
+    var offerToReceiveAudio = options.offerToReceiveAudio;
+
+    // TODO: Remove tests of old constraint-like RTCOptions soon (Bug 1064223).
+    if (options.mandatory && options.mandatory.OfferToReceiveAudio !== undefined) {
+      offerToReceiveAudio = options.mandatory.OfferToReceiveAudio;
+    } else if (options.optional && options.optional[0] &&
+               options.optional[0].OfferToReceiveAudio !== undefined) {
+      offerToReceiveAudio = options.optional[0].OfferToReceiveAudio;
+    }
+
+    if (offerToReceiveAudio) {
       return 1;
     } else {
       return 0;
     }
   },
 
   /**
    * Counts the amount of video tracks in a given media constraint.
@@ -1940,17 +1951,28 @@ PeerConnectionWrapper.prototype = {
    * @param options
    *        The options to be examined.
    */
   videoInOfferOptions : function
     PCW_videoInOfferOptions(options) {
     if (!options) {
       return 0;
     }
-    if (options.offerToReceiveVideo) {
+
+    var offerToReceiveVideo = options.offerToReceiveVideo;
+
+    // TODO: Remove tests of old constraint-like RTCOptions soon (Bug 1064223).
+    if (options.mandatory && options.mandatory.OfferToReceiveVideo !== undefined) {
+      offerToReceiveVideo = options.mandatory.OfferToReceiveVideo;
+    } else if (options.optional && options.optional[0] &&
+               options.optional[0].OfferToReceiveVideo !== undefined) {
+      offerToReceiveVideo = options.optional[0].OfferToReceiveVideo;
+    }
+
+    if (offerToReceiveVideo) {
       return 1;
     } else {
       return 0;
     }
   },
 
   /*
    * Counts the amount of audio tracks in a given set of streams.
--- a/dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html
+++ b/dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveAudio.html
@@ -13,15 +13,18 @@
 <script type="application/javascript">
   createHTML({
     bug: "850275",
     title: "Simple offer media constraint test with audio"
   });
 
   runNetworkTest(function() {
     var test = new PeerConnectionTest();
-    test.setOfferOptions({ offerToReceiveAudio: true });
+
+    // TODO: Stop using old constraint-like RTCOptions soon (Bug 1064223).
+    // Watch out for case-difference when fixing: { offerToReceiveAudio: true }
+    test.setOfferOptions({ mandatory: { OfferToReceiveAudio: true } });
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html
+++ b/dom/media/tests/mochitest/test_peerConnection_offerRequiresReceiveVideo.html
@@ -13,15 +13,17 @@
 <script type="application/javascript">
   createHTML({
     bug: "850275",
     title: "Simple offer media constraint test with video"
   });
 
   runNetworkTest(function() {
     var test = new PeerConnectionTest();
-    test.setOfferOptions({ offerToReceiveVideo: true });
+    // TODO: Stop using old constraint-like RTCOptions soon (Bug 1064223).
+    // Watch out for case-difference when fixing: { offerToReceiveVideo: true }
+    test.setOfferOptions({ optional: [{ OfferToReceiveAudio: true }] });
     test.run();
   });
 </script>
 </pre>
 </body>
 </html>
--- a/dom/webidl/RTCPeerConnection.webidl
+++ b/dom/webidl/RTCPeerConnection.webidl
@@ -50,18 +50,29 @@ dictionary RTCDataChannelInit {
   unsigned short maxRetransmitNum; // now maxRetransmits
   boolean preset; // now negotiated
   unsigned short stream; // now id
 };
 
 dictionary RTCOfferOptions {
   long    offerToReceiveVideo;
   long    offerToReceiveAudio;
-  boolean MozDontOfferDataChannel;
-  boolean MozBundleOnly;
+  boolean mozDontOfferDataChannel;
+  boolean mozBundleOnly;
+
+  // TODO: Remove old constraint-like RTCOptions support soon (Bug 1064223).
+  DeprecatedRTCOfferOptionsSet mandatory;
+  sequence<DeprecatedRTCOfferOptionsSet> _optional;
+};
+
+dictionary DeprecatedRTCOfferOptionsSet {
+  boolean OfferToReceiveAudio;     // Note the uppercase 'O'
+  boolean OfferToReceiveVideo;     // Note the uppercase 'O'
+  boolean MozDontOfferDataChannel; // Note the uppercase 'M'
+  boolean MozBundleOnly;           // Note the uppercase 'M'
 };
 
 interface RTCDataChannel;
 
 [Pref="media.peerconnection.enabled",
  JSImplementation="@mozilla.org/dom/peerconnection;1",
  Constructor (optional RTCConfiguration configuration,
               optional object? constraints)]