Bug 1323095 - Add deprecation warnings to callback-based pc.getStats + fix w3c link. draft
authorJan-Ivar Bruaroey <jib@mozilla.com>
Mon, 12 Dec 2016 19:17:38 -0500
changeset 448796 95eca5168268e731e49dd005faa1e9a566b23a27
parent 448717 f46f85dcfbc2b3098ea758825d18be6fab33cbc6
child 539373 c59e646f82e8713338ccbb075147c783b7884dc9
push id38433
push userjbruaroey@mozilla.com
push dateTue, 13 Dec 2016 00:18:58 +0000
bugs1323095
milestone53.0a1
Bug 1323095 - Add deprecation warnings to callback-based pc.getStats + fix w3c link. MozReview-Commit-ID: TlVLuZDadN
dom/media/PeerConnection.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -437,17 +437,21 @@ RTCPeerConnection.prototype = {
     this.__DOM_IMPL__._innerObject = this;
     this._observer = new this._win.PeerConnectionObserver(this.__DOM_IMPL__);
 
     var location = "" + this._win.location;
 
     // Warn just once per PeerConnection about deprecated getStats usage.
     this._warnDeprecatedStatsAccessNullable = { warn: () =>
       this.logWarning("non-maplike pc.getStats access is deprecated! " +
-                      "See http://w3c.github.io/webrtc-pc/#example for usage.") };
+                      "See http://w3c.github.io/webrtc-pc/#getstats-example for usage.") };
+
+    this._warnDeprecatedStatsCallbacksNullable = { warn: () =>
+      this.logWarning("Callback-based pc.getStats is deprecated! Use promise-version! " +
+                      "See http://w3c.github.io/webrtc-pc/#getstats-example for usage.") };
 
     // Add a reference to the PeerConnection to global list (before init).
     _globalPCList.addPC(this);
 
     this._impl.initialize(this._observer, this._win, rtcConfig,
                           Services.tm.currentThread);
 
     this._certificateReady = this._initCertificate(rtcConfig.certificates);
@@ -1208,16 +1212,21 @@ RTCPeerConnection.prototype = {
 
   changeIceConnectionState: function(state) {
     this._iceConnectionState = state;
     _globalPCList.notifyLifecycleObservers(this, "iceconnectionstatechange");
     this.dispatchEvent(new this._win.Event("iceconnectionstatechange"));
   },
 
   getStats: function(selector, onSucc, onErr) {
+    if (typeof onSucc == "function" &&
+        this._warnDeprecatedStatsCallbacksNullable.warn) {
+      this._warnDeprecatedStatsCallbacksNullable.warn();
+      this._warnDeprecatedStatsCallbacksNullable.warn = null;
+    }
     return this._auto(onSucc, onErr, () => this._getStats(selector));
   },
 
   _getStats: async function(selector) {
     // getStats is allowed even in closed state.
     return await this._chain(() => new Promise((resolve, reject) => {
       this._onGetStatsSuccess = resolve;
       this._onGetStatsFailure = reject;
@@ -1485,17 +1494,18 @@ PeerConnectionObserver.prototype = {
         break;
     }
   },
 
   onGetStatsSuccess: function(dict) {
     let pc = this._dompc;
     let chromeobj = new RTCStatsReport(pc._win, dict);
     let webidlobj = pc._win.RTCStatsReport._create(pc._win, chromeobj);
-    chromeobj.makeStatsPublic(pc._warnDeprecatedStatsAccessNullable);
+    chromeobj.makeStatsPublic(pc._warnDeprecatedStatsCallbacksNullable &&
+                              pc._warnDeprecatedStatsAccessNullable);
     pc._onGetStatsSuccess(webidlobj);
   },
 
   onGetStatsError: function(code, message) {
     this._dompc._onGetStatsFailure(this.newError(message, code));
   },
 
   onAddStream: function(stream) {