Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
/* eslint-disable no-invalid-this */
// Ensure I'm not remembering onaddstream invocations from previous
// setRemoteDescription calls. I shouldn't be but... anyway.
this._onaddstreamQueue = [];
RTCPeerConnection.prototype.setRemoteDescription.call(this, description)
.then((...args) => {
let q;
try {
resolve(...args);
} finally {
q = this._onaddstreamQueue;
this._onaddstreamQueue = undefined;
}
this._invokeQueuedOnaddstream(q);
}, (...args) => {
this._onaddstreamQueue = undefined;
reject(...args);
});
function (sessionDescription, successCallback, errorCallback) {
// Ensure I'm not remembering onaddstream invocations from
// previous setRemoteDescription calls. I shouldn't be but...
// anyway.
this._onaddstreamQueue = [];
return RTCPeerConnection.prototype.setRemoteDescription.call(
this,
sessionDescription,
() => {
var r;
var q;
try {
if (successCallback) {
r = successCallback.apply(null, arguments);
}
} finally {
q = this._onaddstreamQueue;
this._onaddstreamQueue = undefined;
}
this._invokeQueuedOnaddstream(q);
return r;
},
// $FlowFixMe
Object.defineProperty(this, 'onaddstream', {
configurable: true,
enumerable: true,
get() {
return this._onaddstream;
},
set(value) {
this._onaddstream = value;
}
});
/* eslint-enable indent, no-invalid-this */
}
_RTCPeerConnection.prototype = Object.create(RTCPeerConnection.prototype);
_RTCPeerConnection.prototype.constructor = _RTCPeerConnection;
_RTCPeerConnection.prototype._invokeOnaddstream = function(...args) {
const onaddstream = this._onaddstream;
return onaddstream && onaddstream.apply(this, args);
};
_RTCPeerConnection.prototype._invokeQueuedOnaddstream = function(q) {
q && q.forEach(args => {
try {
this._invokeOnaddstream(...args);
} catch (e) {
// TODO Determine whether the combination of the standard
// setRemoteDescription and onaddstream results in a similar
// swallowing of errors.
// following approach appears to work and I understand it.
Object.defineProperty(this, 'onaddstream', {
configurable: true,
enumerable: true,
get: function () {
return this._onaddstream;
},
set: function (value) {
this._onaddstream = value;
}
});
}
/*eslint-enable no-inner-declarations */
_RTCPeerConnection.prototype =
Object.create(RTCPeerConnection.prototype);
_RTCPeerConnection.prototype.constructor = _RTCPeerConnection;
_RTCPeerConnection.prototype._invokeOnaddstream = function () {
var onaddstream = this._onaddstream;
var r;
if (onaddstream) {
r = onaddstream.apply(this, arguments);
}
return r;
};
_RTCPeerConnection.prototype._invokeQueuedOnaddstream = function (q) {
q && q.every(function (args) {
try {
this._invokeOnaddstream.apply(this, args);
} catch (e) {
// TODO Determine whether the combination of the standard
// setRemoteDescription and onaddstream results in a similar