diff --git a/release/adapter.js b/release/adapter.js index a5ca2f3af..1d001f577 100644 --- a/release/adapter.js +++ b/release/adapter.js @@ -101,6 +101,7 @@ function adapterFactory() { chromeShim.fixNegotiationNeeded(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -122,6 +123,7 @@ function adapterFactory() { firefoxShim.shimRTCDataChannel(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -1233,6 +1235,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol exports.shimRTCIceCandidate = shimRTCIceCandidate; exports.shimMaxMessageSize = shimMaxMessageSize; exports.shimSendThrowTypeError = shimSendThrowTypeError; +exports.shimConnectionState = shimConnectionState; var _sdp = require('sdp'); @@ -1455,6 +1458,67 @@ function shimSendThrowTypeError(window) { }); } +/* shims RTCConnectionState by pretending it is the same as iceConnectionState. + * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12 + * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect + * since DTLS failures would be hidden. See + * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827 + * for the Firefox tracking bug. + */ +function shimConnectionState(window) { + if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) { + return; + } + var proto = window.RTCPeerConnection.prototype; + Object.defineProperty(proto, 'connectionState', { + get: function get() { + return { + completed: 'connected', + checking: 'connecting' + }[this.iceConnectionState] || this.iceConnectionState; + }, + + enumerable: true, + configurable: true + }); + Object.defineProperty(proto, 'onconnectionstatechange', { + get: function get() { + return this._onconnectionstatechange || null; + }, + set: function set(cb) { + if (this._onconnectionstatechange) { + this.removeEventListener('connectionstatechange', this._onconnectionstatechange); + delete this._onconnectionstatechange; + } + if (cb) { + this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb); + } + }, + + enumerable: true, + configurable: true + }); + + ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) { + var origMethod = proto[method]; + proto[method] = function () { + if (!this._connectionstatechangepoly) { + this._connectionstatechangepoly = function (e) { + var pc = e.target; + if (pc._lastConnectionState !== pc.connectionState) { + pc._lastConnectionState = pc.connectionState; + var newEvent = new Event('connectionstatechange', e); + pc.dispatchEvent(newEvent); + } + return e; + }; + this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly); + } + return origMethod.apply(this, arguments); + }; + }); +} + },{"./utils":15,"sdp":17}],7:[function(require,module,exports){ /* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. diff --git a/release/adapter_no_edge.js b/release/adapter_no_edge.js index 716e01b14..110a2351b 100644 --- a/release/adapter_no_edge.js +++ b/release/adapter_no_edge.js @@ -101,6 +101,7 @@ function adapterFactory() { chromeShim.fixNegotiationNeeded(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -122,6 +123,7 @@ function adapterFactory() { firefoxShim.shimRTCDataChannel(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -1233,6 +1235,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol exports.shimRTCIceCandidate = shimRTCIceCandidate; exports.shimMaxMessageSize = shimMaxMessageSize; exports.shimSendThrowTypeError = shimSendThrowTypeError; +exports.shimConnectionState = shimConnectionState; var _sdp = require('sdp'); @@ -1455,6 +1458,67 @@ function shimSendThrowTypeError(window) { }); } +/* shims RTCConnectionState by pretending it is the same as iceConnectionState. + * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12 + * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect + * since DTLS failures would be hidden. See + * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827 + * for the Firefox tracking bug. + */ +function shimConnectionState(window) { + if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) { + return; + } + var proto = window.RTCPeerConnection.prototype; + Object.defineProperty(proto, 'connectionState', { + get: function get() { + return { + completed: 'connected', + checking: 'connecting' + }[this.iceConnectionState] || this.iceConnectionState; + }, + + enumerable: true, + configurable: true + }); + Object.defineProperty(proto, 'onconnectionstatechange', { + get: function get() { + return this._onconnectionstatechange || null; + }, + set: function set(cb) { + if (this._onconnectionstatechange) { + this.removeEventListener('connectionstatechange', this._onconnectionstatechange); + delete this._onconnectionstatechange; + } + if (cb) { + this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb); + } + }, + + enumerable: true, + configurable: true + }); + + ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) { + var origMethod = proto[method]; + proto[method] = function () { + if (!this._connectionstatechangepoly) { + this._connectionstatechangepoly = function (e) { + var pc = e.target; + if (pc._lastConnectionState !== pc.connectionState) { + pc._lastConnectionState = pc.connectionState; + var newEvent = new Event('connectionstatechange', e); + pc.dispatchEvent(newEvent); + } + return e; + }; + this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly); + } + return origMethod.apply(this, arguments); + }; + }); +} + },{"./utils":11,"sdp":13}],7:[function(require,module,exports){ /* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. diff --git a/release/adapter_no_edge_no_global.js b/release/adapter_no_edge_no_global.js index 42c0ca786..49780f3f9 100644 --- a/release/adapter_no_edge_no_global.js +++ b/release/adapter_no_edge_no_global.js @@ -101,6 +101,7 @@ function adapterFactory() { chromeShim.fixNegotiationNeeded(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -122,6 +123,7 @@ function adapterFactory() { firefoxShim.shimRTCDataChannel(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -1233,6 +1235,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol exports.shimRTCIceCandidate = shimRTCIceCandidate; exports.shimMaxMessageSize = shimMaxMessageSize; exports.shimSendThrowTypeError = shimSendThrowTypeError; +exports.shimConnectionState = shimConnectionState; var _sdp = require('sdp'); @@ -1455,6 +1458,67 @@ function shimSendThrowTypeError(window) { }); } +/* shims RTCConnectionState by pretending it is the same as iceConnectionState. + * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12 + * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect + * since DTLS failures would be hidden. See + * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827 + * for the Firefox tracking bug. + */ +function shimConnectionState(window) { + if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) { + return; + } + var proto = window.RTCPeerConnection.prototype; + Object.defineProperty(proto, 'connectionState', { + get: function get() { + return { + completed: 'connected', + checking: 'connecting' + }[this.iceConnectionState] || this.iceConnectionState; + }, + + enumerable: true, + configurable: true + }); + Object.defineProperty(proto, 'onconnectionstatechange', { + get: function get() { + return this._onconnectionstatechange || null; + }, + set: function set(cb) { + if (this._onconnectionstatechange) { + this.removeEventListener('connectionstatechange', this._onconnectionstatechange); + delete this._onconnectionstatechange; + } + if (cb) { + this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb); + } + }, + + enumerable: true, + configurable: true + }); + + ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) { + var origMethod = proto[method]; + proto[method] = function () { + if (!this._connectionstatechangepoly) { + this._connectionstatechangepoly = function (e) { + var pc = e.target; + if (pc._lastConnectionState !== pc.connectionState) { + pc._lastConnectionState = pc.connectionState; + var newEvent = new Event('connectionstatechange', e); + pc.dispatchEvent(newEvent); + } + return e; + }; + this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly); + } + return origMethod.apply(this, arguments); + }; + }); +} + },{"./utils":11,"sdp":13}],7:[function(require,module,exports){ /* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. diff --git a/release/adapter_no_global.js b/release/adapter_no_global.js index e270bedcd..e1f519f82 100644 --- a/release/adapter_no_global.js +++ b/release/adapter_no_global.js @@ -101,6 +101,7 @@ function adapterFactory() { chromeShim.fixNegotiationNeeded(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -122,6 +123,7 @@ function adapterFactory() { firefoxShim.shimRTCDataChannel(window); commonShim.shimRTCIceCandidate(window); + commonShim.shimConnectionState(window); commonShim.shimMaxMessageSize(window); commonShim.shimSendThrowTypeError(window); break; @@ -1233,6 +1235,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol exports.shimRTCIceCandidate = shimRTCIceCandidate; exports.shimMaxMessageSize = shimMaxMessageSize; exports.shimSendThrowTypeError = shimSendThrowTypeError; +exports.shimConnectionState = shimConnectionState; var _sdp = require('sdp'); @@ -1455,6 +1458,67 @@ function shimSendThrowTypeError(window) { }); } +/* shims RTCConnectionState by pretending it is the same as iceConnectionState. + * See https://bugs.chromium.org/p/webrtc/issues/detail?id=6145#c12 + * for why this is a valid hack in Chrome. In Firefox it is slightly incorrect + * since DTLS failures would be hidden. See + * https://bugzilla.mozilla.org/show_bug.cgi?id=1265827 + * for the Firefox tracking bug. + */ +function shimConnectionState(window) { + if (!window.RTCPeerConnection || 'connectionState' in window.RTCPeerConnection.prototype) { + return; + } + var proto = window.RTCPeerConnection.prototype; + Object.defineProperty(proto, 'connectionState', { + get: function get() { + return { + completed: 'connected', + checking: 'connecting' + }[this.iceConnectionState] || this.iceConnectionState; + }, + + enumerable: true, + configurable: true + }); + Object.defineProperty(proto, 'onconnectionstatechange', { + get: function get() { + return this._onconnectionstatechange || null; + }, + set: function set(cb) { + if (this._onconnectionstatechange) { + this.removeEventListener('connectionstatechange', this._onconnectionstatechange); + delete this._onconnectionstatechange; + } + if (cb) { + this.addEventListener('connectionstatechange', this._onconnectionstatechange = cb); + } + }, + + enumerable: true, + configurable: true + }); + + ['setLocalDescription', 'setRemoteDescription'].forEach(function (method) { + var origMethod = proto[method]; + proto[method] = function () { + if (!this._connectionstatechangepoly) { + this._connectionstatechangepoly = function (e) { + var pc = e.target; + if (pc._lastConnectionState !== pc.connectionState) { + pc._lastConnectionState = pc.connectionState; + var newEvent = new Event('connectionstatechange', e); + pc.dispatchEvent(newEvent); + } + return e; + }; + this.addEventListener('iceconnectionstatechange', this._connectionstatechangepoly); + } + return origMethod.apply(this, arguments); + }; + }); +} + },{"./utils":15,"sdp":17}],7:[function(require,module,exports){ /* * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.