Bug 1323095 - Add deprecation warnings to callback-based pc.getStats + fix w3c link.
MozReview-Commit-ID: TlVLuZDadN
--- 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) {