Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

webrtc-adapter

Package Overview
Dependencies
Maintainers
4
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

webrtc-adapter - npm Package Compare versions

Comparing version 7.2.4 to 7.2.5

84

dist/chrome/chrome_shim.js

@@ -52,2 +52,4 @@

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function shimMediaStream(window) {

@@ -74,3 +76,3 @@ window.MediaStream = window.MediaStream || window.webkitMediaStream;

var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function () {
window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
var _this = this;

@@ -155,3 +157,3 @@

if (!window.RTCPeerConnection.prototype.getSenders) {
window.RTCPeerConnection.prototype.getSenders = function () {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
this._senders = this._senders || [];

@@ -161,3 +163,3 @@ return this._senders.slice(); // return a copy of the internal state.

var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
var sender = origAddTrack.apply(this, arguments);

@@ -172,3 +174,3 @@ if (!sender) {

var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function (sender) {
window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
origRemoveTrack.apply(this, arguments);

@@ -182,3 +184,3 @@ var idx = this._senders.indexOf(sender);

var origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function (stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
var _this2 = this;

@@ -194,3 +196,3 @@

var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function (stream) {
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
var _this3 = this;

@@ -213,3 +215,3 @@

var origGetSenders = window.RTCPeerConnection.prototype.getSenders;
window.RTCPeerConnection.prototype.getSenders = function () {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
var _this4 = this;

@@ -245,9 +247,14 @@

var origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function (selector, successCallback, errorCallback) {
window.RTCPeerConnection.prototype.getStats = function getStats() {
var _this5 = this;
var args = arguments;
var _arguments = Array.prototype.slice.call(arguments),
selector = _arguments[0],
onSucc = _arguments[1],
onErr = _arguments[2];
// If selector is a function then we are in the old style stats so just
// pass back the original getStats format to avoid breaking old users.
if (arguments.length > 0 && typeof selector === 'function') {

@@ -259,3 +266,3 @@ return origGetStats.apply(this, arguments);

// either no arguments or the selector argument is null.
if (origGetStats.length === 0 && (arguments.length === 0 || typeof arguments[0] !== 'function')) {
if (origGetStats.length === 0 && (arguments.length === 0 || typeof selector !== 'function')) {
return origGetStats.apply(this, []);

@@ -294,6 +301,6 @@ }

var successCallbackWrapper_ = function successCallbackWrapper_(response) {
args[1](makeMapStats(fixChromeStats_(response)));
onSucc(makeMapStats(fixChromeStats_(response)));
};
return origGetStats.apply(this, [successCallbackWrapper_, arguments[0]]);
return origGetStats.apply(this, [successCallbackWrapper_, selector]);
}

@@ -306,3 +313,3 @@

}, reject]);
}).then(successCallback, errorCallback);
}).then(onSucc, onErr);
};

@@ -320,3 +327,3 @@ }

if (origGetSenders) {
window.RTCPeerConnection.prototype.getSenders = function () {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
var _this6 = this;

@@ -334,3 +341,3 @@

if (origAddTrack) {
window.RTCPeerConnection.prototype.addTrack = function () {
window.RTCPeerConnection.prototype.addTrack = function addTrack() {
var sender = origAddTrack.apply(this, arguments);

@@ -341,3 +348,3 @@ sender._pc = this;

}
window.RTCRtpSender.prototype.getStats = function () {
window.RTCRtpSender.prototype.getStats = function getStats() {
var sender = this;

@@ -360,3 +367,3 @@ return this._pc.getStats().then(function (result) {

if (origGetReceivers) {
window.RTCPeerConnection.prototype.getReceivers = function () {
window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
var _this7 = this;

@@ -375,3 +382,3 @@

});
window.RTCRtpReceiver.prototype.getStats = function () {
window.RTCRtpReceiver.prototype.getStats = function getStats() {
var receiver = this;

@@ -390,3 +397,3 @@ return this._pc.getStats().then(function (result) {

var origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function () {
window.RTCPeerConnection.prototype.getStats = function getStats() {
if (arguments.length > 0 && arguments[0] instanceof window.MediaStreamTrack) {

@@ -433,3 +440,3 @@ var track = arguments[0];

// Keeps a mapping stream.id => [stream, rtpsenders...]
window.RTCPeerConnection.prototype.getLocalStreams = function () {
window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
var _this8 = this;

@@ -444,3 +451,3 @@

var origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
if (!stream) {

@@ -461,3 +468,3 @@ return origAddTrack.apply(this, arguments);

var origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function (stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
var _this9 = this;

@@ -484,3 +491,3 @@

var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function (stream) {
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};

@@ -492,3 +499,3 @@ delete this._shimmedLocalStreams[stream.id];

var origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function (sender) {
window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
var _this10 = this;

@@ -525,3 +532,3 @@

var origGetLocalStreams = window.RTCPeerConnection.prototype.getLocalStreams;
window.RTCPeerConnection.prototype.getLocalStreams = function () {
window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
var _this11 = this;

@@ -537,3 +544,3 @@

var origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function (stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
var _this12 = this;

@@ -564,3 +571,3 @@

var origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function (stream) {
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
this._streams = this._streams || {};

@@ -574,3 +581,3 @@ this._reverseStreams = this._reverseStreams || {};

window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
var _this13 = this;

@@ -650,3 +657,3 @@

var nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function () {
var methodObj = _defineProperty({}, method, function () {
var _this14 = this;

@@ -669,7 +676,8 @@

});
};
});
window.RTCPeerConnection.prototype[method] = methodObj[method];
});
var origSetLocalDescription = window.RTCPeerConnection.prototype.setLocalDescription;
window.RTCPeerConnection.prototype.setLocalDescription = function () {
window.RTCPeerConnection.prototype.setLocalDescription = function setLocalDescription() {
if (!arguments.length || !arguments[0].type) {

@@ -695,3 +703,3 @@ return origSetLocalDescription.apply(this, arguments);

window.RTCPeerConnection.prototype.removeTrack = function (sender) {
window.RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
var _this15 = this;

@@ -753,6 +761,7 @@

var nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function () {
var methodObj = _defineProperty({}, method, function () {
arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
return nativeMethod.apply(this, arguments);
};
});
window.RTCPeerConnection.prototype[method] = methodObj[method];
});

@@ -763,3 +772,3 @@ }

var nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
window.RTCPeerConnection.prototype.addIceCandidate = function () {
window.RTCPeerConnection.prototype.addIceCandidate = function addIceCandidate() {
if (!arguments[0]) {

@@ -771,2 +780,7 @@ if (arguments[1]) {

}
// Firefox 68+ emits and processes {candidate: "", ...}, ignore
// in older versions. Native support planned for Chrome M77.
if (browserDetails.version < 78 && arguments[0] && arguments[0].candidate === '') {
return Promise.resolve();
}
return nativeAddIceCandidate.apply(this, arguments);

@@ -773,0 +787,0 @@ };

@@ -28,3 +28,3 @@ /*

}
window.navigator.mediaDevices.getDisplayMedia = function (constraints) {
window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
return getSourceId(constraints).then(function (sourceId) {

@@ -31,0 +31,0 @@ var widthSpecified = constraints.video && constraints.video.width;

@@ -43,3 +43,3 @@ /*

var NativeRTCIceCandidate = window.RTCIceCandidate;
window.RTCIceCandidate = function (args) {
window.RTCIceCandidate = function RTCIceCandidate(args) {
// Remove the a= which shouldn't be part of the candidate string.

@@ -58,3 +58,3 @@ if ((typeof args === 'undefined' ? 'undefined' : _typeof(args)) === 'object' && args.candidate && args.candidate.indexOf('a=') === 0) {

// Add a serializer that does not serialize the extra attributes.
augmentedCandidate.toJSON = function () {
augmentedCandidate.toJSON = function toJSON() {
return {

@@ -87,3 +87,3 @@ candidate: augmentedCandidate.candidate,

function shimMaxMessageSize(window) {
if (window.RTCSctpTransport || !window.RTCPeerConnection) {
if (!window.RTCPeerConnection) {
return;

@@ -180,5 +180,23 @@ }

var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function () {
window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
this._sctp = null;
// Chrome decided to not expose .sctp in plan-b mode.
// As usual, adapter.js has to do an 'ugly worakaround'
// to cover up the mess.
if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) {
var _getConfiguration = this.getConfiguration(),
sdpSemantics = _getConfiguration.sdpSemantics;
if (sdpSemantics === 'plan-b') {
Object.defineProperty(this, 'sctp', {
get: function get() {
return typeof this._sctp === 'undefined' ? null : this._sctp;
},
enumerable: true,
configurable: true
});
}
}
if (sctpInDescription(arguments[0])) {

@@ -230,3 +248,3 @@ // Check if the remote is FF.

var origDataChannelSend = dc.send;
dc.send = function () {
dc.send = function send() {
var data = arguments[0];

@@ -241,3 +259,3 @@ var length = data.length || data.size || data.byteLength;

var origCreateDataChannel = window.RTCPeerConnection.prototype.createDataChannel;
window.RTCPeerConnection.prototype.createDataChannel = function () {
window.RTCPeerConnection.prototype.createDataChannel = function createDataChannel() {
var dataChannel = origCreateDataChannel.apply(this, arguments);

@@ -324,3 +342,3 @@ wrapDcSend(dataChannel, this);

var nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function (desc) {
window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription(desc) {
if (desc && desc.sdp && desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) {

@@ -327,0 +345,0 @@ desc.sdp = desc.sdp.split('\n').filter(function (line) {

@@ -55,3 +55,3 @@ /*

if (!window.RTCIceCandidate) {
window.RTCIceCandidate = function (args) {
window.RTCIceCandidate = function RTCIceCandidate(args) {
return args;

@@ -61,3 +61,3 @@ };

if (!window.RTCSessionDescription) {
window.RTCSessionDescription = function (args) {
window.RTCSessionDescription = function RTCSessionDescription(args) {
return args;

@@ -105,3 +105,3 @@ };

var RTCPeerConnectionShim = (0, _rtcpeerconnectionShim2.default)(window, browserDetails.version);
window.RTCPeerConnection = function (config) {
window.RTCPeerConnection = function RTCPeerConnection(config) {
if (config && config.iceServers) {

@@ -108,0 +108,0 @@ config.iceServers = (0, _filtericeservers.filterIceServers)(config.iceServers, browserDetails.version);

@@ -48,2 +48,4 @@ /*

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function shimOnTrack(window) {

@@ -74,6 +76,7 @@ if ((typeof window === 'undefined' ? 'undefined' : _typeof(window)) === 'object' && window.RTCTrackEvent && 'receiver' in window.RTCTrackEvent.prototype && !('transceiver' in window.RTCTrackEvent.prototype)) {

var nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function () {
var methodObj = _defineProperty({}, method, function () {
arguments[0] = new (method === 'addIceCandidate' ? window.RTCIceCandidate : window.RTCSessionDescription)(arguments[0]);
return nativeMethod.apply(this, arguments);
};
});
window.RTCPeerConnection.prototype[method] = methodObj[method];
});

@@ -84,3 +87,3 @@ }

var nativeAddIceCandidate = window.RTCPeerConnection.prototype.addIceCandidate;
window.RTCPeerConnection.prototype.addIceCandidate = function () {
window.RTCPeerConnection.prototype.addIceCandidate = function addIceCandidate() {
if (!arguments[0]) {

@@ -92,2 +95,7 @@ if (arguments[1]) {

}
// Firefox 68+ emits and processes {candidate: "", ...}, ignore
// in older versions.
if (browserDetails.version < 68 && arguments[0] && arguments[0].candidate === '') {
return Promise.resolve();
}
return nativeAddIceCandidate.apply(this, arguments);

@@ -105,3 +113,8 @@ };

var nativeGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function (selector, onSucc, onErr) {
window.RTCPeerConnection.prototype.getStats = function getStats() {
var _arguments = Array.prototype.slice.call(arguments),
selector = _arguments[0],
onSucc = _arguments[1],
onErr = _arguments[2];
return nativeGetStats.apply(this, [selector || null]).then(function (stats) {

@@ -141,3 +154,3 @@ if (browserDetails.version < 53 && !onSucc) {

if (origGetSenders) {
window.RTCPeerConnection.prototype.getSenders = function () {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
var _this = this;

@@ -155,3 +168,3 @@

if (origAddTrack) {
window.RTCPeerConnection.prototype.addTrack = function () {
window.RTCPeerConnection.prototype.addTrack = function addTrack() {
var sender = origAddTrack.apply(this, arguments);

@@ -162,3 +175,3 @@ sender._pc = this;

}
window.RTCRtpSender.prototype.getStats = function () {
window.RTCRtpSender.prototype.getStats = function getStats() {
return this.track ? this._pc.getStats(this.track) : Promise.resolve(new Map());

@@ -177,3 +190,3 @@ };

if (origGetReceivers) {
window.RTCPeerConnection.prototype.getReceivers = function () {
window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
var _this2 = this;

@@ -192,3 +205,3 @@

});
window.RTCRtpReceiver.prototype.getStats = function () {
window.RTCRtpReceiver.prototype.getStats = function getStats() {
return this._pc.getStats(this.track);

@@ -202,3 +215,3 @@ };

}
window.RTCPeerConnection.prototype.removeStream = function (stream) {
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
var _this3 = this;

@@ -205,0 +218,0 @@

@@ -22,3 +22,3 @@ /*

}
window.navigator.mediaDevices.getDisplayMedia = function (constraints) {
window.navigator.mediaDevices.getDisplayMedia = function getDisplayMedia(constraints) {
if (!(constraints && constraints.video)) {

@@ -25,0 +25,0 @@ var err = new DOMException('getDisplayMedia without video ' + 'constraints is undefined');

@@ -36,3 +36,3 @@ /*

if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.getLocalStreams = function () {
window.RTCPeerConnection.prototype.getLocalStreams = function getLocalStreams() {
if (!this._localStreams) {

@@ -46,3 +46,3 @@ this._localStreams = [];

var _addTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addStream = function (stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
var _this = this;

@@ -66,3 +66,3 @@

window.RTCPeerConnection.prototype.addTrack = function (track, stream) {
window.RTCPeerConnection.prototype.addTrack = function addTrack(track, stream) {
if (stream) {

@@ -79,3 +79,3 @@ if (!this._localStreams) {

if (!('removeStream' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.removeStream = function (stream) {
window.RTCPeerConnection.prototype.removeStream = function removeStream(stream) {
var _this2 = this;

@@ -106,3 +106,3 @@

if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.getRemoteStreams = function () {
window.RTCPeerConnection.prototype.getRemoteStreams = function getRemoteStreams() {
return this._remoteStreams ? this._remoteStreams : [];

@@ -141,3 +141,3 @@ };

var origSetRemoteDescription = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function () {
window.RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription() {
var pc = this;

@@ -170,4 +170,4 @@ if (!this._onaddstreampoly) {

var prototype = window.RTCPeerConnection.prototype;
var createOffer = prototype.createOffer;
var createAnswer = prototype.createAnswer;
var origCreateOffer = prototype.createOffer;
var origCreateAnswer = prototype.createAnswer;
var setLocalDescription = prototype.setLocalDescription;

@@ -177,5 +177,5 @@ var setRemoteDescription = prototype.setRemoteDescription;

prototype.createOffer = function (successCallback, failureCallback) {
prototype.createOffer = function createOffer(successCallback, failureCallback) {
var options = arguments.length >= 2 ? arguments[2] : arguments[0];
var promise = createOffer.apply(this, [options]);
var promise = origCreateOffer.apply(this, [options]);
if (!failureCallback) {

@@ -188,5 +188,5 @@ return promise;

prototype.createAnswer = function (successCallback, failureCallback) {
prototype.createAnswer = function createAnswer(successCallback, failureCallback) {
var options = arguments.length >= 2 ? arguments[2] : arguments[0];
var promise = createAnswer.apply(this, [options]);
var promise = origCreateAnswer.apply(this, [options]);
if (!failureCallback) {

@@ -243,3 +243,3 @@ return promise;

if (!navigator.getUserMedia && navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
navigator.getUserMedia = function (constraints, cb, errcb) {
navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) {
navigator.mediaDevices.getUserMedia(constraints).then(cb, errcb);

@@ -261,3 +261,3 @@ }.bind(navigator);

var OrigPeerConnection = window.RTCPeerConnection;
window.RTCPeerConnection = function (pcConfig, pcConstraints) {
window.RTCPeerConnection = function RTCPeerConnection(pcConfig, pcConstraints) {
if (pcConfig && pcConfig.iceServers) {

@@ -308,3 +308,3 @@ var newIceServers = [];

var origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
window.RTCPeerConnection.prototype.createOffer = function (offerOptions) {
window.RTCPeerConnection.prototype.createOffer = function createOffer(offerOptions) {
if (offerOptions) {

@@ -311,0 +311,0 @@ if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {

{
"name": "webrtc-adapter",
"version": "7.2.4",
"version": "7.2.5",
"description": "A shim to insulate apps from WebRTC spec changes and browser prefix differences",
"license": "BSD-3-Clause",
"main": "./src/js/adapter_core5.js",
"main": "./dist/adapter_core.js",
"module": "./src/js/adapter_core.js",

@@ -45,3 +45,3 @@ "repository": {

"grunt-shell": "^2.1.0",
"karma": "^3.1.3",
"karma": "^4.1.0",
"karma-browserify": "^5.2.0",

@@ -48,0 +48,0 @@ "karma-chai": "^0.1.0",

@@ -38,43 +38,44 @@

window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
if (!this._ontrackpoly) {
this._ontrackpoly = (e) => {
// onaddstream does not fire when a track is added to an existing
// stream. But stream.onaddtrack is implemented so we use that.
e.stream.addEventListener('addtrack', te => {
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) {
receiver = this.getReceivers()
.find(r => r.track && r.track.id === te.track.id);
} else {
receiver = {track: te.track};
}
window.RTCPeerConnection.prototype.setRemoteDescription =
function setRemoteDescription() {
if (!this._ontrackpoly) {
this._ontrackpoly = (e) => {
// onaddstream does not fire when a track is added to an existing
// stream. But stream.onaddtrack is implemented so we use that.
e.stream.addEventListener('addtrack', te => {
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) {
receiver = this.getReceivers()
.find(r => r.track && r.track.id === te.track.id);
} else {
receiver = {track: te.track};
}
const event = new Event('track');
event.track = te.track;
event.receiver = receiver;
event.transceiver = {receiver};
event.streams = [e.stream];
this.dispatchEvent(event);
});
e.stream.getTracks().forEach(track => {
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) {
receiver = this.getReceivers()
.find(r => r.track && r.track.id === track.id);
} else {
receiver = {track};
}
const event = new Event('track');
event.track = track;
event.receiver = receiver;
event.transceiver = {receiver};
event.streams = [e.stream];
this.dispatchEvent(event);
});
};
this.addEventListener('addstream', this._ontrackpoly);
}
return origSetRemoteDescription.apply(this, arguments);
};
const event = new Event('track');
event.track = te.track;
event.receiver = receiver;
event.transceiver = {receiver};
event.streams = [e.stream];
this.dispatchEvent(event);
});
e.stream.getTracks().forEach(track => {
let receiver;
if (window.RTCPeerConnection.prototype.getReceivers) {
receiver = this.getReceivers()
.find(r => r.track && r.track.id === track.id);
} else {
receiver = {track};
}
const event = new Event('track');
event.track = track;
event.receiver = receiver;
event.transceiver = {receiver};
event.streams = [e.stream];
this.dispatchEvent(event);
});
};
this.addEventListener('addstream', this._ontrackpoly);
}
return origSetRemoteDescription.apply(this, arguments);
};
} else {

@@ -118,3 +119,3 @@ // even if RTCRtpTransceiver is in window, it is only used and

if (!window.RTCPeerConnection.prototype.getSenders) {
window.RTCPeerConnection.prototype.getSenders = function() {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
this._senders = this._senders || [];

@@ -124,22 +125,24 @@ return this._senders.slice(); // return a copy of the internal state.

const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
let sender = origAddTrack.apply(this, arguments);
if (!sender) {
sender = shimSenderWithDtmf(this, track);
this._senders.push(sender);
}
return sender;
};
window.RTCPeerConnection.prototype.addTrack =
function addTrack(track, stream) {
let sender = origAddTrack.apply(this, arguments);
if (!sender) {
sender = shimSenderWithDtmf(this, track);
this._senders.push(sender);
}
return sender;
};
const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function(sender) {
origRemoveTrack.apply(this, arguments);
const idx = this._senders.indexOf(sender);
if (idx !== -1) {
this._senders.splice(idx, 1);
}
};
window.RTCPeerConnection.prototype.removeTrack =
function removeTrack(sender) {
origRemoveTrack.apply(this, arguments);
const idx = this._senders.indexOf(sender);
if (idx !== -1) {
this._senders.splice(idx, 1);
}
};
}
const origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function(stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
this._senders = this._senders || [];

@@ -153,13 +156,14 @@ origAddStream.apply(this, [stream]);

const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function(stream) {
this._senders = this._senders || [];
origRemoveStream.apply(this, [stream]);
window.RTCPeerConnection.prototype.removeStream =
function removeStream(stream) {
this._senders = this._senders || [];
origRemoveStream.apply(this, [stream]);
stream.getTracks().forEach(track => {
const sender = this._senders.find(s => s.track === track);
if (sender) { // remove sender
this._senders.splice(this._senders.indexOf(sender), 1);
}
});
};
stream.getTracks().forEach(track => {
const sender = this._senders.find(s => s.track === track);
if (sender) { // remove sender
this._senders.splice(this._senders.indexOf(sender), 1);
}
});
};
} else if (typeof window === 'object' && window.RTCPeerConnection &&

@@ -171,3 +175,3 @@ 'getSenders' in window.RTCPeerConnection.prototype &&

const origGetSenders = window.RTCPeerConnection.prototype.getSenders;
window.RTCPeerConnection.prototype.getSenders = function() {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
const senders = origGetSenders.apply(this, []);

@@ -199,5 +203,4 @@ senders.forEach(sender => sender._pc = this);

const origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function(selector,
successCallback, errorCallback) {
const args = arguments;
window.RTCPeerConnection.prototype.getStats = function getStats() {
const [selector, onSucc, onErr] = arguments;

@@ -213,3 +216,3 @@ // If selector is a function then we are in the old style stats so just

if (origGetStats.length === 0 && (arguments.length === 0 ||
typeof arguments[0] !== 'function')) {
typeof selector !== 'function')) {
return origGetStats.apply(this, []);

@@ -246,7 +249,7 @@ }

const successCallbackWrapper_ = function(response) {
args[1](makeMapStats(fixChromeStats_(response)));
onSucc(makeMapStats(fixChromeStats_(response)));
};
return origGetStats.apply(this, [successCallbackWrapper_,
arguments[0]]);
selector]);
}

@@ -260,3 +263,3 @@

}, reject]);
}).then(successCallback, errorCallback);
}).then(onSucc, onErr);
};

@@ -275,3 +278,3 @@ }

if (origGetSenders) {
window.RTCPeerConnection.prototype.getSenders = function() {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
const senders = origGetSenders.apply(this, []);

@@ -285,3 +288,3 @@ senders.forEach(sender => sender._pc = this);

if (origAddTrack) {
window.RTCPeerConnection.prototype.addTrack = function() {
window.RTCPeerConnection.prototype.addTrack = function addTrack() {
const sender = origAddTrack.apply(this, arguments);

@@ -292,3 +295,3 @@ sender._pc = this;

}
window.RTCRtpSender.prototype.getStats = function() {
window.RTCRtpSender.prototype.getStats = function getStats() {
const sender = this;

@@ -308,7 +311,8 @@ return this._pc.getStats().then(result =>

if (origGetReceivers) {
window.RTCPeerConnection.prototype.getReceivers = function() {
const receivers = origGetReceivers.apply(this, []);
receivers.forEach(receiver => receiver._pc = this);
return receivers;
};
window.RTCPeerConnection.prototype.getReceivers =
function getReceivers() {
const receivers = origGetReceivers.apply(this, []);
receivers.forEach(receiver => receiver._pc = this);
return receivers;
};
}

@@ -319,3 +323,3 @@ utils.wrapPeerConnectionEvent(window, 'track', e => {

});
window.RTCRtpReceiver.prototype.getStats = function() {
window.RTCRtpReceiver.prototype.getStats = function getStats() {
const receiver = this;

@@ -334,3 +338,3 @@ return this._pc.getStats().then(result =>

const origGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function() {
window.RTCPeerConnection.prototype.getStats = function getStats() {
if (arguments.length > 0 &&

@@ -382,26 +386,28 @@ arguments[0] instanceof window.MediaStreamTrack) {

// Keeps a mapping stream.id => [stream, rtpsenders...]
window.RTCPeerConnection.prototype.getLocalStreams = function() {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
return Object.keys(this._shimmedLocalStreams)
.map(streamId => this._shimmedLocalStreams[streamId][0]);
};
window.RTCPeerConnection.prototype.getLocalStreams =
function getLocalStreams() {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
return Object.keys(this._shimmedLocalStreams)
.map(streamId => this._shimmedLocalStreams[streamId][0]);
};
const origAddTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
if (!stream) {
return origAddTrack.apply(this, arguments);
}
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
window.RTCPeerConnection.prototype.addTrack =
function addTrack(track, stream) {
if (!stream) {
return origAddTrack.apply(this, arguments);
}
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
const sender = origAddTrack.apply(this, arguments);
if (!this._shimmedLocalStreams[stream.id]) {
this._shimmedLocalStreams[stream.id] = [stream, sender];
} else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {
this._shimmedLocalStreams[stream.id].push(sender);
}
return sender;
};
const sender = origAddTrack.apply(this, arguments);
if (!this._shimmedLocalStreams[stream.id]) {
this._shimmedLocalStreams[stream.id] = [stream, sender];
} else if (this._shimmedLocalStreams[stream.id].indexOf(sender) === -1) {
this._shimmedLocalStreams[stream.id].push(sender);
}
return sender;
};
const origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function(stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};

@@ -424,24 +430,26 @@

const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
delete this._shimmedLocalStreams[stream.id];
return origRemoveStream.apply(this, arguments);
};
window.RTCPeerConnection.prototype.removeStream =
function removeStream(stream) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
delete this._shimmedLocalStreams[stream.id];
return origRemoveStream.apply(this, arguments);
};
const origRemoveTrack = window.RTCPeerConnection.prototype.removeTrack;
window.RTCPeerConnection.prototype.removeTrack = function(sender) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
if (sender) {
Object.keys(this._shimmedLocalStreams).forEach(streamId => {
const idx = this._shimmedLocalStreams[streamId].indexOf(sender);
if (idx !== -1) {
this._shimmedLocalStreams[streamId].splice(idx, 1);
}
if (this._shimmedLocalStreams[streamId].length === 1) {
delete this._shimmedLocalStreams[streamId];
}
});
}
return origRemoveTrack.apply(this, arguments);
};
window.RTCPeerConnection.prototype.removeTrack =
function removeTrack(sender) {
this._shimmedLocalStreams = this._shimmedLocalStreams || {};
if (sender) {
Object.keys(this._shimmedLocalStreams).forEach(streamId => {
const idx = this._shimmedLocalStreams[streamId].indexOf(sender);
if (idx !== -1) {
this._shimmedLocalStreams[streamId].splice(idx, 1);
}
if (this._shimmedLocalStreams[streamId].length === 1) {
delete this._shimmedLocalStreams[streamId];
}
});
}
return origRemoveTrack.apply(this, arguments);
};
}

@@ -464,10 +472,11 @@

.getLocalStreams;
window.RTCPeerConnection.prototype.getLocalStreams = function() {
const nativeStreams = origGetLocalStreams.apply(this);
this._reverseStreams = this._reverseStreams || {};
return nativeStreams.map(stream => this._reverseStreams[stream.id]);
};
window.RTCPeerConnection.prototype.getLocalStreams =
function getLocalStreams() {
const nativeStreams = origGetLocalStreams.apply(this);
this._reverseStreams = this._reverseStreams || {};
return nativeStreams.map(stream => this._reverseStreams[stream.id]);
};
const origAddStream = window.RTCPeerConnection.prototype.addStream;
window.RTCPeerConnection.prototype.addStream = function(stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
this._streams = this._streams || {};

@@ -495,57 +504,59 @@ this._reverseStreams = this._reverseStreams || {};

const origRemoveStream = window.RTCPeerConnection.prototype.removeStream;
window.RTCPeerConnection.prototype.removeStream = function(stream) {
this._streams = this._streams || {};
this._reverseStreams = this._reverseStreams || {};
window.RTCPeerConnection.prototype.removeStream =
function removeStream(stream) {
this._streams = this._streams || {};
this._reverseStreams = this._reverseStreams || {};
origRemoveStream.apply(this, [(this._streams[stream.id] || stream)]);
delete this._reverseStreams[(this._streams[stream.id] ?
this._streams[stream.id].id : stream.id)];
delete this._streams[stream.id];
};
origRemoveStream.apply(this, [(this._streams[stream.id] || stream)]);
delete this._reverseStreams[(this._streams[stream.id] ?
this._streams[stream.id].id : stream.id)];
delete this._streams[stream.id];
};
window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
if (this.signalingState === 'closed') {
throw new DOMException(
'The RTCPeerConnection\'s signalingState is \'closed\'.',
'InvalidStateError');
}
const streams = [].slice.call(arguments, 1);
if (streams.length !== 1 ||
!streams[0].getTracks().find(t => t === track)) {
// this is not fully correct but all we can manage without
// [[associated MediaStreams]] internal slot.
throw new DOMException(
'The adapter.js addTrack polyfill only supports a single ' +
' stream which is associated with the specified track.',
'NotSupportedError');
}
window.RTCPeerConnection.prototype.addTrack =
function addTrack(track, stream) {
if (this.signalingState === 'closed') {
throw new DOMException(
'The RTCPeerConnection\'s signalingState is \'closed\'.',
'InvalidStateError');
}
const streams = [].slice.call(arguments, 1);
if (streams.length !== 1 ||
!streams[0].getTracks().find(t => t === track)) {
// this is not fully correct but all we can manage without
// [[associated MediaStreams]] internal slot.
throw new DOMException(
'The adapter.js addTrack polyfill only supports a single ' +
' stream which is associated with the specified track.',
'NotSupportedError');
}
const alreadyExists = this.getSenders().find(s => s.track === track);
if (alreadyExists) {
throw new DOMException('Track already exists.',
'InvalidAccessError');
}
const alreadyExists = this.getSenders().find(s => s.track === track);
if (alreadyExists) {
throw new DOMException('Track already exists.',
'InvalidAccessError');
}
this._streams = this._streams || {};
this._reverseStreams = this._reverseStreams || {};
const oldStream = this._streams[stream.id];
if (oldStream) {
// this is using odd Chrome behaviour, use with caution:
// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
// Note: we rely on the high-level addTrack/dtmf shim to
// create the sender with a dtmf sender.
oldStream.addTrack(track);
this._streams = this._streams || {};
this._reverseStreams = this._reverseStreams || {};
const oldStream = this._streams[stream.id];
if (oldStream) {
// this is using odd Chrome behaviour, use with caution:
// https://bugs.chromium.org/p/webrtc/issues/detail?id=7815
// Note: we rely on the high-level addTrack/dtmf shim to
// create the sender with a dtmf sender.
oldStream.addTrack(track);
// Trigger ONN async.
Promise.resolve().then(() => {
this.dispatchEvent(new Event('negotiationneeded'));
});
} else {
const newStream = new window.MediaStream([track]);
this._streams[stream.id] = newStream;
this._reverseStreams[newStream.id] = stream;
this.addStream(newStream);
}
return this.getSenders().find(s => s.track === track);
};
// Trigger ONN async.
Promise.resolve().then(() => {
this.dispatchEvent(new Event('negotiationneeded'));
});
} else {
const newStream = new window.MediaStream([track]);
this._streams[stream.id] = newStream;
this._reverseStreams[newStream.id] = stream;
this.addStream(newStream);
}
return this.getSenders().find(s => s.track === track);
};

@@ -582,3 +593,3 @@ // replace the internal stream id with the external one and

const nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function() {
const methodObj = {[method]() {
const args = arguments;

@@ -602,3 +613,4 @@ const isLegacyCall = arguments.length &&

.then(description => replaceInternalStreamId(this, description));
};
}};
window.RTCPeerConnection.prototype[method] = methodObj[method];
});

@@ -608,9 +620,10 @@

window.RTCPeerConnection.prototype.setLocalDescription;
window.RTCPeerConnection.prototype.setLocalDescription = function() {
if (!arguments.length || !arguments[0].type) {
window.RTCPeerConnection.prototype.setLocalDescription =
function setLocalDescription() {
if (!arguments.length || !arguments[0].type) {
return origSetLocalDescription.apply(this, arguments);
}
arguments[0] = replaceExternalStreamId(this, arguments[0]);
return origSetLocalDescription.apply(this, arguments);
}
arguments[0] = replaceExternalStreamId(this, arguments[0]);
return origSetLocalDescription.apply(this, arguments);
};
};

@@ -632,43 +645,44 @@ // TODO: mangle getStats: https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamstats-streamidentifier

window.RTCPeerConnection.prototype.removeTrack = function(sender) {
if (this.signalingState === 'closed') {
throw new DOMException(
'The RTCPeerConnection\'s signalingState is \'closed\'.',
'InvalidStateError');
}
// We can not yet check for sender instanceof RTCRtpSender
// since we shim RTPSender. So we check if sender._pc is set.
if (!sender._pc) {
throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' +
'does not implement interface RTCRtpSender.', 'TypeError');
}
const isLocal = sender._pc === this;
if (!isLocal) {
throw new DOMException('Sender was not created by this connection.',
'InvalidAccessError');
}
// Search for the native stream the senders track belongs to.
this._streams = this._streams || {};
let stream;
Object.keys(this._streams).forEach(streamid => {
const hasTrack = this._streams[streamid].getTracks()
.find(track => sender.track === track);
if (hasTrack) {
stream = this._streams[streamid];
window.RTCPeerConnection.prototype.removeTrack =
function removeTrack(sender) {
if (this.signalingState === 'closed') {
throw new DOMException(
'The RTCPeerConnection\'s signalingState is \'closed\'.',
'InvalidStateError');
}
});
// We can not yet check for sender instanceof RTCRtpSender
// since we shim RTPSender. So we check if sender._pc is set.
if (!sender._pc) {
throw new DOMException('Argument 1 of RTCPeerConnection.removeTrack ' +
'does not implement interface RTCRtpSender.', 'TypeError');
}
const isLocal = sender._pc === this;
if (!isLocal) {
throw new DOMException('Sender was not created by this connection.',
'InvalidAccessError');
}
if (stream) {
if (stream.getTracks().length === 1) {
// if this is the last track of the stream, remove the stream. This
// takes care of any shimmed _senders.
this.removeStream(this._reverseStreams[stream.id]);
} else {
// relying on the same odd chrome behaviour as above.
stream.removeTrack(sender.track);
// Search for the native stream the senders track belongs to.
this._streams = this._streams || {};
let stream;
Object.keys(this._streams).forEach(streamid => {
const hasTrack = this._streams[streamid].getTracks()
.find(track => sender.track === track);
if (hasTrack) {
stream = this._streams[streamid];
}
});
if (stream) {
if (stream.getTracks().length === 1) {
// if this is the last track of the stream, remove the stream. This
// takes care of any shimmed _senders.
this.removeStream(this._reverseStreams[stream.id]);
} else {
// relying on the same odd chrome behaviour as above.
stream.removeTrack(sender.track);
}
this.dispatchEvent(new Event('negotiationneeded'));
}
this.dispatchEvent(new Event('negotiationneeded'));
}
};
};
}

@@ -692,3 +706,3 @@

const nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function() {
const methodObj = {[method]() {
arguments[0] = new ((method === 'addIceCandidate') ?

@@ -698,3 +712,4 @@ window.RTCIceCandidate :

return nativeMethod.apply(this, arguments);
};
}};
window.RTCPeerConnection.prototype[method] = methodObj[method];
});

@@ -706,11 +721,18 @@ }

window.RTCPeerConnection.prototype.addIceCandidate;
window.RTCPeerConnection.prototype.addIceCandidate = function() {
if (!arguments[0]) {
if (arguments[1]) {
arguments[1].apply(null);
window.RTCPeerConnection.prototype.addIceCandidate =
function addIceCandidate() {
if (!arguments[0]) {
if (arguments[1]) {
arguments[1].apply(null);
}
return Promise.resolve();
}
return Promise.resolve();
}
return nativeAddIceCandidate.apply(this, arguments);
};
// Firefox 68+ emits and processes {candidate: "", ...}, ignore
// in older versions. Native support planned for Chrome M77.
if (browserDetails.version < 78 &&
arguments[0] && arguments[0].candidate === '') {
return Promise.resolve();
}
return nativeAddIceCandidate.apply(this, arguments);
};
}

@@ -717,0 +739,0 @@

@@ -25,25 +25,27 @@ /*

}
window.navigator.mediaDevices.getDisplayMedia = function(constraints) {
return getSourceId(constraints)
.then(sourceId => {
const widthSpecified = constraints.video && constraints.video.width;
const heightSpecified = constraints.video && constraints.video.height;
const frameRateSpecified = constraints.video &&
constraints.video.frameRate;
constraints.video = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceId,
maxFrameRate: frameRateSpecified || 3
window.navigator.mediaDevices.getDisplayMedia =
function getDisplayMedia(constraints) {
return getSourceId(constraints)
.then(sourceId => {
const widthSpecified = constraints.video && constraints.video.width;
const heightSpecified = constraints.video &&
constraints.video.height;
const frameRateSpecified = constraints.video &&
constraints.video.frameRate;
constraints.video = {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: sourceId,
maxFrameRate: frameRateSpecified || 3
}
};
if (widthSpecified) {
constraints.video.mandatory.maxWidth = widthSpecified;
}
};
if (widthSpecified) {
constraints.video.mandatory.maxWidth = widthSpecified;
}
if (heightSpecified) {
constraints.video.mandatory.maxHeight = heightSpecified;
}
return window.navigator.mediaDevices.getUserMedia(constraints);
});
};
if (heightSpecified) {
constraints.video.mandatory.maxHeight = heightSpecified;
}
return window.navigator.mediaDevices.getUserMedia(constraints);
});
};
}

@@ -23,3 +23,3 @@ /*

const NativeRTCIceCandidate = window.RTCIceCandidate;
window.RTCIceCandidate = function(args) {
window.RTCIceCandidate = function RTCIceCandidate(args) {
// Remove the a= which shouldn't be part of the candidate string.

@@ -40,3 +40,3 @@ if (typeof args === 'object' && args.candidate &&

// Add a serializer that does not serialize the extra attributes.
augmentedCandidate.toJSON = function() {
augmentedCandidate.toJSON = function toJSON() {
return {

@@ -69,3 +69,3 @@ candidate: augmentedCandidate.candidate,

export function shimMaxMessageSize(window) {
if (window.RTCSctpTransport || !window.RTCPeerConnection) {
if (!window.RTCPeerConnection) {
return;

@@ -168,38 +168,54 @@ }

window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
this._sctp = null;
window.RTCPeerConnection.prototype.setRemoteDescription =
function setRemoteDescription() {
this._sctp = null;
// Chrome decided to not expose .sctp in plan-b mode.
// As usual, adapter.js has to do an 'ugly worakaround'
// to cover up the mess.
if (browserDetails.browser === 'chrome' && browserDetails.version >= 76) {
const {sdpSemantics} = this.getConfiguration();
if (sdpSemantics === 'plan-b') {
Object.defineProperty(this, 'sctp', {
get() {
return typeof this._sctp === 'undefined' ? null : this._sctp;
},
enumerable: true,
configurable: true,
});
}
}
if (sctpInDescription(arguments[0])) {
// Check if the remote is FF.
const isFirefox = getRemoteFirefoxVersion(arguments[0]);
if (sctpInDescription(arguments[0])) {
// Check if the remote is FF.
const isFirefox = getRemoteFirefoxVersion(arguments[0]);
// Get the maximum message size the local peer is capable of sending
const canSendMMS = getCanSendMaxMessageSize(isFirefox);
// Get the maximum message size the local peer is capable of sending
const canSendMMS = getCanSendMaxMessageSize(isFirefox);
// Get the maximum message size of the remote peer.
const remoteMMS = getMaxMessageSize(arguments[0], isFirefox);
// Get the maximum message size of the remote peer.
const remoteMMS = getMaxMessageSize(arguments[0], isFirefox);
// Determine final maximum message size
let maxMessageSize;
if (canSendMMS === 0 && remoteMMS === 0) {
maxMessageSize = Number.POSITIVE_INFINITY;
} else if (canSendMMS === 0 || remoteMMS === 0) {
maxMessageSize = Math.max(canSendMMS, remoteMMS);
} else {
maxMessageSize = Math.min(canSendMMS, remoteMMS);
// Determine final maximum message size
let maxMessageSize;
if (canSendMMS === 0 && remoteMMS === 0) {
maxMessageSize = Number.POSITIVE_INFINITY;
} else if (canSendMMS === 0 || remoteMMS === 0) {
maxMessageSize = Math.max(canSendMMS, remoteMMS);
} else {
maxMessageSize = Math.min(canSendMMS, remoteMMS);
}
// Create a dummy RTCSctpTransport object and the 'maxMessageSize'
// attribute.
const sctp = {};
Object.defineProperty(sctp, 'maxMessageSize', {
get() {
return maxMessageSize;
}
});
this._sctp = sctp;
}
// Create a dummy RTCSctpTransport object and the 'maxMessageSize'
// attribute.
const sctp = {};
Object.defineProperty(sctp, 'maxMessageSize', {
get() {
return maxMessageSize;
}
});
this._sctp = sctp;
}
return origSetRemoteDescription.apply(this, arguments);
};
return origSetRemoteDescription.apply(this, arguments);
};
}

@@ -219,3 +235,3 @@

const origDataChannelSend = dc.send;
dc.send = function() {
dc.send = function send() {
const data = arguments[0];

@@ -233,7 +249,8 @@ const length = data.length || data.size || data.byteLength;

window.RTCPeerConnection.prototype.createDataChannel;
window.RTCPeerConnection.prototype.createDataChannel = function() {
const dataChannel = origCreateDataChannel.apply(this, arguments);
wrapDcSend(dataChannel, this);
return dataChannel;
};
window.RTCPeerConnection.prototype.createDataChannel =
function createDataChannel() {
const dataChannel = origCreateDataChannel.apply(this, arguments);
wrapDcSend(dataChannel, this);
return dataChannel;
};
utils.wrapPeerConnectionEvent(window, 'datachannel', e => {

@@ -319,3 +336,4 @@ wrapDcSend(e.channel, e.target);

const nativeSRD = window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function(desc) {
window.RTCPeerConnection.prototype.setRemoteDescription =
function setRemoteDescription(desc) {
if (desc && desc.sdp && desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) {

@@ -322,0 +340,0 @@ desc.sdp = desc.sdp.split('\n').filter((line) => {

@@ -23,3 +23,3 @@ /*

if (!window.RTCIceCandidate) {
window.RTCIceCandidate = function(args) {
window.RTCIceCandidate = function RTCIceCandidate(args) {
return args;

@@ -29,3 +29,3 @@ };

if (!window.RTCSessionDescription) {
window.RTCSessionDescription = function(args) {
window.RTCSessionDescription = function RTCSessionDescription(args) {
return args;

@@ -75,3 +75,3 @@ };

browserDetails.version);
window.RTCPeerConnection = function(config) {
window.RTCPeerConnection = function RTCPeerConnection(config) {
if (config && config.iceServers) {

@@ -78,0 +78,0 @@ config.iceServers = filterIceServers(config.iceServers,

@@ -44,3 +44,3 @@ /*

const nativeMethod = window.RTCPeerConnection.prototype[method];
window.RTCPeerConnection.prototype[method] = function() {
const methodObj = {[method]() {
arguments[0] = new ((method === 'addIceCandidate') ?

@@ -50,3 +50,4 @@ window.RTCIceCandidate :

return nativeMethod.apply(this, arguments);
};
}};
window.RTCPeerConnection.prototype[method] = methodObj[method];
});

@@ -58,3 +59,4 @@ }

window.RTCPeerConnection.prototype.addIceCandidate;
window.RTCPeerConnection.prototype.addIceCandidate = function() {
window.RTCPeerConnection.prototype.addIceCandidate =
function addIceCandidate() {
if (!arguments[0]) {

@@ -66,2 +68,8 @@ if (arguments[1]) {

}
// Firefox 68+ emits and processes {candidate: "", ...}, ignore
// in older versions.
if (browserDetails.version < 68 &&
arguments[0] && arguments[0].candidate === '') {
return Promise.resolve();
}
return nativeAddIceCandidate.apply(this, arguments);

@@ -79,7 +87,4 @@ };

const nativeGetStats = window.RTCPeerConnection.prototype.getStats;
window.RTCPeerConnection.prototype.getStats = function(
selector,
onSucc,
onErr
) {
window.RTCPeerConnection.prototype.getStats = function getStats() {
const [selector, onSucc, onErr] = arguments;
return nativeGetStats.apply(this, [selector || null])

@@ -122,3 +127,3 @@ .then(stats => {

if (origGetSenders) {
window.RTCPeerConnection.prototype.getSenders = function() {
window.RTCPeerConnection.prototype.getSenders = function getSenders() {
const senders = origGetSenders.apply(this, []);

@@ -132,3 +137,3 @@ senders.forEach(sender => sender._pc = this);

if (origAddTrack) {
window.RTCPeerConnection.prototype.addTrack = function() {
window.RTCPeerConnection.prototype.addTrack = function addTrack() {
const sender = origAddTrack.apply(this, arguments);

@@ -139,3 +144,3 @@ sender._pc = this;

}
window.RTCRtpSender.prototype.getStats = function() {
window.RTCRtpSender.prototype.getStats = function getStats() {
return this.track ? this._pc.getStats(this.track) :

@@ -156,3 +161,3 @@ Promise.resolve(new Map());

if (origGetReceivers) {
window.RTCPeerConnection.prototype.getReceivers = function() {
window.RTCPeerConnection.prototype.getReceivers = function getReceivers() {
const receivers = origGetReceivers.apply(this, []);

@@ -167,3 +172,3 @@ receivers.forEach(receiver => receiver._pc = this);

});
window.RTCRtpReceiver.prototype.getStats = function() {
window.RTCRtpReceiver.prototype.getStats = function getStats() {
return this._pc.getStats(this.track);

@@ -178,10 +183,11 @@ };

}
window.RTCPeerConnection.prototype.removeStream = function(stream) {
utils.deprecated('removeStream', 'removeTrack');
this.getSenders().forEach(sender => {
if (sender.track && stream.getTracks().includes(sender.track)) {
this.removeTrack(sender);
}
});
};
window.RTCPeerConnection.prototype.removeStream =
function removeStream(stream) {
utils.deprecated('removeStream', 'removeTrack');
this.getSenders().forEach(sender => {
if (sender.track && stream.getTracks().includes(sender.track)) {
this.removeTrack(sender);
}
});
};
}

@@ -188,0 +194,0 @@

@@ -19,18 +19,19 @@ /*

}
window.navigator.mediaDevices.getDisplayMedia = function(constraints) {
if (!(constraints && constraints.video)) {
const err = new DOMException('getDisplayMedia without video ' +
'constraints is undefined');
err.name = 'NotFoundError';
// from https://heycam.github.io/webidl/#idl-DOMException-error-names
err.code = 8;
return Promise.reject(err);
}
if (constraints.video === true) {
constraints.video = {mediaSource: preferredMediaSource};
} else {
constraints.video.mediaSource = preferredMediaSource;
}
return window.navigator.mediaDevices.getUserMedia(constraints);
};
window.navigator.mediaDevices.getDisplayMedia =
function getDisplayMedia(constraints) {
if (!(constraints && constraints.video)) {
const err = new DOMException('getDisplayMedia without video ' +
'constraints is undefined');
err.name = 'NotFoundError';
// from https://heycam.github.io/webidl/#idl-DOMException-error-names
err.code = 8;
return Promise.reject(err);
}
if (constraints.video === true) {
constraints.video = {mediaSource: preferredMediaSource};
} else {
constraints.video.mediaSource = preferredMediaSource;
}
return window.navigator.mediaDevices.getUserMedia(constraints);
};
}

@@ -16,12 +16,13 @@ /*

if (!('getLocalStreams' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.getLocalStreams = function() {
if (!this._localStreams) {
this._localStreams = [];
}
return this._localStreams;
};
window.RTCPeerConnection.prototype.getLocalStreams =
function getLocalStreams() {
if (!this._localStreams) {
this._localStreams = [];
}
return this._localStreams;
};
}
if (!('addStream' in window.RTCPeerConnection.prototype)) {
const _addTrack = window.RTCPeerConnection.prototype.addTrack;
window.RTCPeerConnection.prototype.addStream = function(stream) {
window.RTCPeerConnection.prototype.addStream = function addStream(stream) {
if (!this._localStreams) {

@@ -41,30 +42,32 @@ this._localStreams = [];

window.RTCPeerConnection.prototype.addTrack = function(track, stream) {
if (stream) {
if (!this._localStreams) {
this._localStreams = [stream];
} else if (!this._localStreams.includes(stream)) {
this._localStreams.push(stream);
window.RTCPeerConnection.prototype.addTrack =
function addTrack(track, stream) {
if (stream) {
if (!this._localStreams) {
this._localStreams = [stream];
} else if (!this._localStreams.includes(stream)) {
this._localStreams.push(stream);
}
}
}
return _addTrack.call(this, track, stream);
};
return _addTrack.call(this, track, stream);
};
}
if (!('removeStream' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.removeStream = function(stream) {
if (!this._localStreams) {
this._localStreams = [];
}
const index = this._localStreams.indexOf(stream);
if (index === -1) {
return;
}
this._localStreams.splice(index, 1);
const tracks = stream.getTracks();
this.getSenders().forEach(sender => {
if (tracks.includes(sender.track)) {
this.removeTrack(sender);
window.RTCPeerConnection.prototype.removeStream =
function removeStream(stream) {
if (!this._localStreams) {
this._localStreams = [];
}
});
};
const index = this._localStreams.indexOf(stream);
if (index === -1) {
return;
}
this._localStreams.splice(index, 1);
const tracks = stream.getTracks();
this.getSenders().forEach(sender => {
if (tracks.includes(sender.track)) {
this.removeTrack(sender);
}
});
};
}

@@ -78,5 +81,6 @@ }

if (!('getRemoteStreams' in window.RTCPeerConnection.prototype)) {
window.RTCPeerConnection.prototype.getRemoteStreams = function() {
return this._remoteStreams ? this._remoteStreams : [];
};
window.RTCPeerConnection.prototype.getRemoteStreams =
function getRemoteStreams() {
return this._remoteStreams ? this._remoteStreams : [];
};
}

@@ -112,22 +116,23 @@ if (!('onaddstream' in window.RTCPeerConnection.prototype)) {

window.RTCPeerConnection.prototype.setRemoteDescription;
window.RTCPeerConnection.prototype.setRemoteDescription = function() {
const pc = this;
if (!this._onaddstreampoly) {
this.addEventListener('track', this._onaddstreampoly = function(e) {
e.streams.forEach(stream => {
if (!pc._remoteStreams) {
pc._remoteStreams = [];
}
if (pc._remoteStreams.indexOf(stream) >= 0) {
return;
}
pc._remoteStreams.push(stream);
const event = new Event('addstream');
event.stream = stream;
pc.dispatchEvent(event);
window.RTCPeerConnection.prototype.setRemoteDescription =
function setRemoteDescription() {
const pc = this;
if (!this._onaddstreampoly) {
this.addEventListener('track', this._onaddstreampoly = function(e) {
e.streams.forEach(stream => {
if (!pc._remoteStreams) {
pc._remoteStreams = [];
}
if (pc._remoteStreams.indexOf(stream) >= 0) {
return;
}
pc._remoteStreams.push(stream);
const event = new Event('addstream');
event.stream = stream;
pc.dispatchEvent(event);
});
});
});
}
return origSetRemoteDescription.apply(pc, arguments);
};
}
return origSetRemoteDescription.apply(pc, arguments);
};
}

@@ -141,4 +146,4 @@ }

const prototype = window.RTCPeerConnection.prototype;
const createOffer = prototype.createOffer;
const createAnswer = prototype.createAnswer;
const origCreateOffer = prototype.createOffer;
const origCreateAnswer = prototype.createAnswer;
const setLocalDescription = prototype.setLocalDescription;

@@ -148,21 +153,23 @@ const setRemoteDescription = prototype.setRemoteDescription;

prototype.createOffer = function(successCallback, failureCallback) {
const options = (arguments.length >= 2) ? arguments[2] : arguments[0];
const promise = createOffer.apply(this, [options]);
if (!failureCallback) {
return promise;
}
promise.then(successCallback, failureCallback);
return Promise.resolve();
};
prototype.createOffer =
function createOffer(successCallback, failureCallback) {
const options = (arguments.length >= 2) ? arguments[2] : arguments[0];
const promise = origCreateOffer.apply(this, [options]);
if (!failureCallback) {
return promise;
}
promise.then(successCallback, failureCallback);
return Promise.resolve();
};
prototype.createAnswer = function(successCallback, failureCallback) {
const options = (arguments.length >= 2) ? arguments[2] : arguments[0];
const promise = createAnswer.apply(this, [options]);
if (!failureCallback) {
return promise;
}
promise.then(successCallback, failureCallback);
return Promise.resolve();
};
prototype.createAnswer =
function createAnswer(successCallback, failureCallback) {
const options = (arguments.length >= 2) ? arguments[2] : arguments[0];
const promise = origCreateAnswer.apply(this, [options]);
if (!failureCallback) {
return promise;
}
promise.then(successCallback, failureCallback);
return Promise.resolve();
};

@@ -214,3 +221,3 @@ let withCallback = function(description, successCallback, failureCallback) {

navigator.mediaDevices.getUserMedia) {
navigator.getUserMedia = function(constraints, cb, errcb) {
navigator.getUserMedia = function getUserMedia(constraints, cb, errcb) {
navigator.mediaDevices.getUserMedia(constraints)

@@ -236,22 +243,23 @@ .then(cb, errcb);

const OrigPeerConnection = window.RTCPeerConnection;
window.RTCPeerConnection = function(pcConfig, pcConstraints) {
if (pcConfig && pcConfig.iceServers) {
const newIceServers = [];
for (let i = 0; i < pcConfig.iceServers.length; i++) {
let server = pcConfig.iceServers[i];
if (!server.hasOwnProperty('urls') &&
server.hasOwnProperty('url')) {
utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
server = JSON.parse(JSON.stringify(server));
server.urls = server.url;
delete server.url;
newIceServers.push(server);
} else {
newIceServers.push(pcConfig.iceServers[i]);
window.RTCPeerConnection =
function RTCPeerConnection(pcConfig, pcConstraints) {
if (pcConfig && pcConfig.iceServers) {
const newIceServers = [];
for (let i = 0; i < pcConfig.iceServers.length; i++) {
let server = pcConfig.iceServers[i];
if (!server.hasOwnProperty('urls') &&
server.hasOwnProperty('url')) {
utils.deprecated('RTCIceServer.url', 'RTCIceServer.urls');
server = JSON.parse(JSON.stringify(server));
server.urls = server.url;
delete server.url;
newIceServers.push(server);
} else {
newIceServers.push(pcConfig.iceServers[i]);
}
}
pcConfig.iceServers = newIceServers;
}
pcConfig.iceServers = newIceServers;
}
return new OrigPeerConnection(pcConfig, pcConstraints);
};
return new OrigPeerConnection(pcConfig, pcConstraints);
};
window.RTCPeerConnection.prototype = OrigPeerConnection.prototype;

@@ -285,56 +293,59 @@ // wrap static methods. Currently just generateCertificate.

const origCreateOffer = window.RTCPeerConnection.prototype.createOffer;
window.RTCPeerConnection.prototype.createOffer = function(offerOptions) {
if (offerOptions) {
if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {
// support bit values
offerOptions.offerToReceiveAudio = !!offerOptions.offerToReceiveAudio;
}
const audioTransceiver = this.getTransceivers().find(transceiver =>
transceiver.receiver.track.kind === 'audio');
if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
if (audioTransceiver.direction === 'sendrecv') {
if (audioTransceiver.setDirection) {
audioTransceiver.setDirection('sendonly');
} else {
audioTransceiver.direction = 'sendonly';
window.RTCPeerConnection.prototype.createOffer =
function createOffer(offerOptions) {
if (offerOptions) {
if (typeof offerOptions.offerToReceiveAudio !== 'undefined') {
// support bit values
offerOptions.offerToReceiveAudio =
!!offerOptions.offerToReceiveAudio;
}
const audioTransceiver = this.getTransceivers().find(transceiver =>
transceiver.receiver.track.kind === 'audio');
if (offerOptions.offerToReceiveAudio === false && audioTransceiver) {
if (audioTransceiver.direction === 'sendrecv') {
if (audioTransceiver.setDirection) {
audioTransceiver.setDirection('sendonly');
} else {
audioTransceiver.direction = 'sendonly';
}
} else if (audioTransceiver.direction === 'recvonly') {
if (audioTransceiver.setDirection) {
audioTransceiver.setDirection('inactive');
} else {
audioTransceiver.direction = 'inactive';
}
}
} else if (audioTransceiver.direction === 'recvonly') {
if (audioTransceiver.setDirection) {
audioTransceiver.setDirection('inactive');
} else {
audioTransceiver.direction = 'inactive';
}
} else if (offerOptions.offerToReceiveAudio === true &&
!audioTransceiver) {
this.addTransceiver('audio');
}
} else if (offerOptions.offerToReceiveAudio === true &&
!audioTransceiver) {
this.addTransceiver('audio');
}
if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {
// support bit values
offerOptions.offerToReceiveVideo = !!offerOptions.offerToReceiveVideo;
}
const videoTransceiver = this.getTransceivers().find(transceiver =>
transceiver.receiver.track.kind === 'video');
if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
if (videoTransceiver.direction === 'sendrecv') {
if (videoTransceiver.setDirection) {
videoTransceiver.setDirection('sendonly');
} else {
videoTransceiver.direction = 'sendonly';
if (typeof offerOptions.offerToReceiveVideo !== 'undefined') {
// support bit values
offerOptions.offerToReceiveVideo =
!!offerOptions.offerToReceiveVideo;
}
const videoTransceiver = this.getTransceivers().find(transceiver =>
transceiver.receiver.track.kind === 'video');
if (offerOptions.offerToReceiveVideo === false && videoTransceiver) {
if (videoTransceiver.direction === 'sendrecv') {
if (videoTransceiver.setDirection) {
videoTransceiver.setDirection('sendonly');
} else {
videoTransceiver.direction = 'sendonly';
}
} else if (videoTransceiver.direction === 'recvonly') {
if (videoTransceiver.setDirection) {
videoTransceiver.setDirection('inactive');
} else {
videoTransceiver.direction = 'inactive';
}
}
} else if (videoTransceiver.direction === 'recvonly') {
if (videoTransceiver.setDirection) {
videoTransceiver.setDirection('inactive');
} else {
videoTransceiver.direction = 'inactive';
}
} else if (offerOptions.offerToReceiveVideo === true &&
!videoTransceiver) {
this.addTransceiver('video');
}
} else if (offerOptions.offerToReceiveVideo === true &&
!videoTransceiver) {
this.addTransceiver('video');
}
}
return origCreateOffer.apply(this, arguments);
};
return origCreateOffer.apply(this, arguments);
};
}

@@ -53,3 +53,7 @@ /*

);
it('resolves when called with {candidate: \'\'}', () =>
pc.addIceCandidate({candidate: '', sdpMid: 'mid1'})
);
});
});

@@ -181,2 +181,3 @@ /*

fakeWindow.RTCPeerConnection.prototype.setRemoteDescription = () => {};
fakeWindow.RTCPeerConnection.prototype.getConfiguration = () => ({});
window.adapter.commonShim.shimMaxMessageSize(fakeWindow);

@@ -183,0 +184,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc