New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mediasoup-client

Package Overview
Dependencies
Maintainers
2
Versions
245
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mediasoup-client - npm Package Compare versions

Comparing version 3.6.80 to 3.6.81

lib/handlers/ortc/utils.d.ts

9

lib/Consumer.js

@@ -101,4 +101,5 @@ "use strict";

close() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('close()');

@@ -115,4 +116,5 @@ this._closed = true;

transportClosed() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('transportClosed()');

@@ -129,4 +131,5 @@ this._closed = true;

async getStats() {
if (this._closed)
if (this._closed) {
throw new errors_1.InvalidStateError('closed');
}
return new Promise((resolve, reject) => {

@@ -133,0 +136,0 @@ this.safeEmit('@getstats', resolve, reject);

@@ -96,4 +96,5 @@ "use strict";

close() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('close()');

@@ -110,4 +111,5 @@ this._closed = true;

transportClosed() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('transportClosed()');

@@ -122,4 +124,5 @@ this._closed = true;

this._dataChannel.addEventListener('open', () => {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('DataChannel "open" event');

@@ -129,7 +132,9 @@ this.safeEmit('open');

this._dataChannel.addEventListener('error', (event) => {
if (this._closed)
if (this._closed) {
return;
}
let { error } = event;
if (!error)
if (!error) {
error = new Error('unknown DataChannel error');
}
if (error.errorDetail === 'sctp-failure') {

@@ -144,4 +149,5 @@ logger.error('DataChannel SCTP error [sctpCauseCode:%s]: %s', error.sctpCauseCode, error.message);

this._dataChannel.addEventListener('close', () => {
if (this._closed)
if (this._closed) {
return;
}
logger.warn('DataChannel "close" event');

@@ -155,4 +161,5 @@ this._closed = true;

this._dataChannel.addEventListener('message', (event) => {
if (this._closed)
if (this._closed) {
return;
}
this.safeEmit('message', event.data);

@@ -159,0 +166,0 @@ });

@@ -96,4 +96,5 @@ "use strict";

close() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('close()');

@@ -110,4 +111,5 @@ this._closed = true;

transportClosed() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('transportClosed()');

@@ -127,4 +129,5 @@ this._closed = true;

logger.debug('send()');
if (this._closed)
if (this._closed) {
throw new errors_1.InvalidStateError('closed');
}
this._dataChannel.send(data);

@@ -134,4 +137,5 @@ }

this._dataChannel.addEventListener('open', () => {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('DataChannel "open" event');

@@ -141,7 +145,9 @@ this.safeEmit('open');

this._dataChannel.addEventListener('error', (event) => {
if (this._closed)
if (this._closed) {
return;
}
let { error } = event;
if (!error)
if (!error) {
error = new Error('unknown DataChannel error');
}
if (error.errorDetail === 'sctp-failure') {

@@ -156,4 +162,5 @@ logger.error('DataChannel SCTP error [sctpCauseCode:%s]: %s', error.sctpCauseCode, error.message);

this._dataChannel.addEventListener('close', () => {
if (this._closed)
if (this._closed) {
return;
}
logger.warn('DataChannel "close" event');

@@ -167,9 +174,11 @@ this._closed = true;

this._dataChannel.addEventListener('message', () => {
if (this._closed)
if (this._closed) {
return;
}
logger.warn('DataChannel "message" event in a DataProducer, message discarded');
});
this._dataChannel.addEventListener('bufferedamountlow', () => {
if (this._closed)
if (this._closed) {
return;
}
this.safeEmit('bufferedamountlow');

@@ -176,0 +185,0 @@ });

@@ -259,4 +259,5 @@ "use strict";

get rtpCapabilities() {
if (!this._loaded)
if (!this._loaded) {
throw new errors_1.InvalidStateError('not loaded');
}
return this._recvRtpCapabilities;

@@ -270,4 +271,5 @@ }

get sctpCapabilities() {
if (!this._loaded)
if (!this._loaded) {
throw new errors_1.InvalidStateError('not loaded');
}
return this._sctpCapabilities;

@@ -321,4 +323,5 @@ }

catch (error) {
if (handler)
if (handler) {
handler.close();
}
throw error;

@@ -334,6 +337,8 @@ }

canProduce(kind) {
if (!this._loaded)
if (!this._loaded) {
throw new errors_1.InvalidStateError('not loaded');
else if (kind !== 'audio' && kind !== 'video')
}
else if (kind !== 'audio' && kind !== 'video') {
throw new TypeError(`invalid kind "${kind}"`);
}
return this._canProduceByKind[kind];

@@ -386,16 +391,23 @@ }

createTransport({ direction, id, iceParameters, iceCandidates, dtlsParameters, sctpParameters, iceServers, iceTransportPolicy, additionalSettings, proprietaryConstraints, appData }) {
if (!this._loaded)
if (!this._loaded) {
throw new errors_1.InvalidStateError('not loaded');
else if (typeof id !== 'string')
}
else if (typeof id !== 'string') {
throw new TypeError('missing id');
else if (typeof iceParameters !== 'object')
}
else if (typeof iceParameters !== 'object') {
throw new TypeError('missing iceParameters');
else if (!Array.isArray(iceCandidates))
}
else if (!Array.isArray(iceCandidates)) {
throw new TypeError('missing iceCandidates');
else if (typeof dtlsParameters !== 'object')
}
else if (typeof dtlsParameters !== 'object') {
throw new TypeError('missing dtlsParameters');
else if (sctpParameters && typeof sctpParameters !== 'object')
}
else if (sctpParameters && typeof sctpParameters !== 'object') {
throw new TypeError('wrong sctpParameters');
else if (appData && typeof appData !== 'object')
}
else if (appData && typeof appData !== 'object') {
throw new TypeError('if given, appData must be an object');
}
// Create a new Transport.

@@ -402,0 +414,0 @@ const transport = new Transport_1.Transport({

@@ -33,2 +33,3 @@ "use strict";

const sdpUnifiedPlanUtils = __importStar(require("./sdp/unifiedPlanUtils"));
const ortcUtils = __importStar(require("./ortc/utils"));
const HandlerInterface_1 = require("./HandlerInterface");

@@ -92,2 +93,4 @@ const RemoteSdp_1 = require("./sdp/RemoteSdp");

const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
// libwebrtc supports NACK for OPUS but doesn't announce it.
ortcUtils.addNackSuppportForOpus(nativeRtpCapabilities);
return nativeRtpCapabilities;

@@ -180,4 +183,5 @@ }

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -303,4 +307,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -327,4 +332,5 @@ this._pc.removeTrack(transceiver.sender);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -344,4 +350,5 @@ this._remoteSdp.pauseMediaSection(localId);

this._remoteSdp.resumeSendingMediaSection(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'sendonly';

@@ -364,4 +371,5 @@ const offer = await this._pc.createOffer();

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -373,10 +381,13 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -396,4 +407,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -415,4 +427,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -534,4 +547,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -554,4 +568,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -572,4 +587,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'recvonly';

@@ -588,4 +604,5 @@ this._remoteSdp.resumeReceivingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -629,4 +646,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -633,0 +651,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -185,4 +185,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -257,4 +258,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -292,4 +294,5 @@ }

const track = this._mapSendLocalIdTrack.get(localId);
if (!track)
if (!track) {
throw new Error('track not found');
}
this._mapSendLocalIdTrack.delete(localId);

@@ -312,4 +315,5 @@ this._sendStream.removeTrack(track);

}
if (this._pc.signalingState === 'stable')
if (this._pc.signalingState === 'stable') {
return;
}
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };

@@ -440,4 +444,5 @@ logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);

const track = stream.getTrackById(localId);
if (!track)
if (!track) {
throw new Error('remote track not found');
}
// Insert into the map.

@@ -516,4 +521,5 @@ this._mapRecvLocalIdInfo.set(localId, { mid, rtpParameters });

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -520,0 +526,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -184,4 +184,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -257,4 +258,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -295,7 +297,9 @@ }

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
this._pc.removeTrack(rtpSender);
if (rtpSender.track)
if (rtpSender.track) {
this._sendStream.removeTrack(rtpSender.track);
}
this._mapSendLocalIdRtpSender.delete(localId);

@@ -316,4 +320,5 @@ const offer = await this._pc.createOffer();

}
if (this._pc.signalingState === 'stable')
if (this._pc.signalingState === 'stable') {
return;
}
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };

@@ -340,12 +345,15 @@ logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const oldTrack = rtpSender.track;
await rtpSender.replaceTrack(track);
// Remove the old track from the local stream.
if (oldTrack)
if (oldTrack) {
this._sendStream.removeTrack(oldTrack);
}
// Add the new track to the local stream.
if (track)
if (track) {
this._sendStream.addTrack(track);
}
}

@@ -356,10 +364,13 @@ async setMaxSpatialLayer(localId, spatialLayer) {

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -372,4 +383,5 @@ await rtpSender.setParameters(parameters);

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();

@@ -384,4 +396,5 @@ parameters.encodings.forEach((encoding, idx) => {

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
return rtpSender.getStats();

@@ -483,4 +496,5 @@ }

.find((r) => r.track && r.track.id === localId);
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('new RTCRtpReceiver not');
}
// Insert into the map.

@@ -525,4 +539,5 @@ this._mapRecvLocalIdInfo.set(localId, { mid, rtpParameters, rtpReceiver });

const { rtpReceiver } = this._mapRecvLocalIdInfo.get(localId) || {};
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('associated RTCRtpReceiver not found');
}
return rtpReceiver.getStats();

@@ -567,4 +582,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -571,0 +587,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -178,4 +178,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -261,4 +262,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

// Should not happen but just in case.
if (!desiredEncoding)
if (!desiredEncoding) {
break;
}
parameters.encodings[idx] = Object.assign(encoding, desiredEncoding);

@@ -283,4 +285,5 @@ }

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -323,4 +326,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -360,4 +364,5 @@ this._pc.removeTrack(transceiver.sender);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -369,10 +374,13 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -392,4 +400,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -411,4 +420,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -511,4 +521,5 @@ }

.find((t) => t.mid === localId);
if (!transceiver)
if (!transceiver) {
throw new Error('new RTCRtpTransceiver not found');
}
// Store in the map.

@@ -529,4 +540,5 @@ this._mapMidTransceiver.set(localId, transceiver);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -557,4 +569,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -599,4 +612,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -603,0 +617,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -33,2 +33,3 @@ "use strict";

const sdpUnifiedPlanUtils = __importStar(require("./sdp/unifiedPlanUtils"));
const ortcUtils = __importStar(require("./ortc/utils"));
const HandlerInterface_1 = require("./HandlerInterface");

@@ -92,2 +93,4 @@ const RemoteSdp_1 = require("./sdp/RemoteSdp");

const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
// libwebrtc supports NACK for OPUS but doesn't announce it.
ortcUtils.addNackSuppportForOpus(nativeRtpCapabilities);
return nativeRtpCapabilities;

@@ -180,4 +183,5 @@ }

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -274,4 +278,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

// Hack for VP9 SVC.
if (hackVp9Svc)
if (hackVp9Svc) {
newEncodings = [newEncodings[0]];
}
sendingRtpParameters.encodings = newEncodings;

@@ -320,4 +325,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -344,4 +350,5 @@ this._pc.removeTrack(transceiver.sender);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -361,4 +368,5 @@ this._remoteSdp.pauseMediaSection(localId);

this._remoteSdp.resumeSendingMediaSection(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'sendonly';

@@ -381,4 +389,5 @@ const offer = await this._pc.createOffer();

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -390,10 +399,13 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -413,4 +425,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -432,4 +445,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -551,4 +565,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -571,4 +586,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -589,4 +605,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'recvonly';

@@ -605,4 +622,5 @@ this._remoteSdp.resumeReceivingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -646,4 +664,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -650,0 +669,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -126,4 +126,5 @@ "use strict";

this._remoteIceParameters = iceParameters;
if (!this._transportReady)
if (!this._transportReady) {
return;
}
logger.debug('restartIce() | calling iceTransport.start()');

@@ -143,4 +144,5 @@ this._iceTransport.start(this._iceGatherer, iceParameters, 'controlling');

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'server' });
}
logger.debug('send() | calling new RTCRtpSender()');

@@ -152,8 +154,10 @@ const rtpSender = new RTCRtpSender(track, this._dtlsTransport);

.some((_codec) => /.+\/rtx$/i.test(_codec.mimeType));
if (!encodings)
if (!encodings) {
encodings = [{}];
}
for (const encoding of encodings) {
encoding.ssrc = utils.generateRandomNumber();
if (useRtx)
if (useRtx) {
encoding.rtx = { ssrc: utils.generateRandomNumber() };
}
}

@@ -182,4 +186,5 @@ rtpParameters.encodings = encodings;

const rtpSender = this._rtpSenders.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('RTCRtpSender not found');
}
this._rtpSenders.delete(localId);

@@ -211,4 +216,5 @@ try {

const rtpSender = this._rtpSenders.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('RTCRtpSender not found');
}
rtpSender.setTrack(track);

@@ -219,11 +225,14 @@ }

const rtpSender = this._rtpSenders.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();
parameters.encodings
.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -235,4 +244,5 @@ await rtpSender.setParameters(parameters);

const rtpSender = this._rtpSenders.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();

@@ -246,4 +256,5 @@ parameters.encodings.forEach((encoding, idx) => {

const rtpSender = this._rtpSenders.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('RTCRtpSender not found');
}
return rtpSender.getStats();

@@ -262,4 +273,5 @@ }

}
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'server' });
}
for (const options of optionsList) {

@@ -292,4 +304,5 @@ const { trackId, kind, rtpParameters } = options;

const rtpReceiver = this._rtpReceivers.get(localId);
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('RTCRtpReceiver not found');
}
this._rtpReceivers.delete(localId);

@@ -317,4 +330,5 @@ try {

const rtpReceiver = this._rtpReceivers.get(localId);
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('RTCRtpReceiver not found');
}
return rtpReceiver.getStats();

@@ -403,4 +417,5 @@ }

logger.debug('dtlsTransport "dtlsstatechange" event [state:%s]', dtlsTransport.state);
if (dtlsTransport.state === 'closed')
if (dtlsTransport.state === 'closed') {
this.emit('@connectionstatechange', 'closed');
}
});

@@ -407,0 +422,0 @@ dtlsTransport.addEventListener('error', (event) => {

@@ -125,4 +125,5 @@ "use strict";

logger.debug('send() [kind:%s, track.id:%s]', track.kind, track.id);
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'server' });
}
const rtpParameters = utils.clone(this._rtpParametersByKind[track.kind], {});

@@ -132,8 +133,10 @@ const useRtx = rtpParameters.codecs

rtpParameters.mid = `mid-${utils.generateRandomNumber()}`;
if (!encodings)
if (!encodings) {
encodings = [{}];
}
for (const encoding of encodings) {
encoding.ssrc = utils.generateRandomNumber();
if (useRtx)
if (useRtx) {
encoding.rtx = { ssrc: utils.generateRandomNumber() };
}
}

@@ -154,4 +157,5 @@ rtpParameters.encodings = encodings;

logger.debug('stopSending() [localId:%s]', localId);
if (!this._tracks.has(Number(localId)))
if (!this._tracks.has(Number(localId))) {
throw new Error('local track not found');
}
this._tracks.delete(Number(localId));

@@ -188,4 +192,5 @@ }

async sendDataChannel({ ordered, maxPacketLifeTime, maxRetransmits, label, protocol }) {
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'server' });
}
logger.debug('sendDataChannel()');

@@ -213,4 +218,5 @@ const dataChannel = new FakeDataChannel({

const { trackId, kind } = options;
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client' });
}
logger.debug('receive() [trackId:%s, kind:%s]', trackId, kind);

@@ -245,4 +251,5 @@ const localId = this._nextLocalId++;

async receiveDataChannel({ sctpStreamParameters, label, protocol }) {
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client' });
}
logger.debug('receiveDataChannel()');

@@ -265,4 +272,5 @@ const dataChannel = new FakeDataChannel({

// Set our DTLS role.
if (localDtlsRole)
if (localDtlsRole) {
dtlsParameters.role = localDtlsRole;
}
// Assume we are connecting now.

@@ -269,0 +277,0 @@ this.emit('@connectionstatechange', 'connecting');

@@ -200,4 +200,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -262,4 +263,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

// Firefox does not respect ICE-Lite.
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
}
const layers = (0, scalabilityModes_1.parse)((encodings || [{}])[0].scalabilityMode);

@@ -329,4 +331,5 @@ logger.debug('send() | calling pc.setLocalDescription() [offer:%o]', offer);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated transceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -359,4 +362,5 @@ // NOTE: Cannot use stop() the transceiver due to the the note above in

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -376,4 +380,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'sendonly';

@@ -397,4 +402,5 @@ this._remoteSdp.resumeSendingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -406,4 +412,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated transceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -414,6 +421,8 @@ // NOTE: We require encodings given from low to high, however Firefox

parameters.encodings.forEach((encoding, idx) => {
if (idx >= spatialLayer)
if (idx >= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -433,4 +442,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -452,4 +462,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -479,4 +490,5 @@ }

.find((m) => m.type === 'application');
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
}
logger.debug('sendDataChannel() | calling pc.setLocalDescription() [offer:%o]', offer);

@@ -535,4 +547,5 @@ await this._pc.setLocalDescription(offer);

}
if (!this._transportReady)
if (!this._transportReady) {
await this.setupTransport({ localDtlsRole: 'client', localSdpObject });
}
logger.debug('receive() | calling pc.setLocalDescription() [answer:%o]', answer);

@@ -545,4 +558,5 @@ await this._pc.setLocalDescription(answer);

.find((t) => t.mid === localId);
if (!transceiver)
if (!transceiver) {
throw new Error('new RTCRtpTransceiver not found');
}
// Store in the map.

@@ -563,4 +577,5 @@ this._mapMidTransceiver.set(localId, transceiver);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -583,4 +598,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -601,4 +617,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'recvonly';

@@ -617,4 +634,5 @@ this._remoteSdp.resumeReceivingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -654,4 +672,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -658,0 +677,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -44,11 +44,14 @@ "use strict";

const parameters = codec.parameters;
if (parameters.apt)
if (parameters.apt) {
parameters.apt = Number(parameters.apt);
if (parameters['packetization-mode'])
}
if (parameters['packetization-mode']) {
parameters['packetization-mode'] = Number(parameters['packetization-mode']);
}
}
// Delete emty parameter String in rtcpFeedback.
for (const feedback of codec.rtcpFeedback || []) {
if (!feedback.parameter)
if (!feedback.parameter) {
feedback.parameter = '';
}
}

@@ -76,4 +79,5 @@ }

// Add codec.name (requried by Edge).
if (codec.mimeType && !codec.name)
if (codec.mimeType && !codec.name) {
codec.name = codec.mimeType.split('/')[1];
}
// Remove mimeType.

@@ -80,0 +84,0 @@ delete codec.mimeType;

@@ -189,4 +189,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -262,4 +263,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -298,4 +300,5 @@ }

const track = this._mapSendLocalIdTrack.get(localId);
if (!track)
if (!track) {
throw new Error('track not found');
}
this._mapSendLocalIdTrack.delete(localId);

@@ -318,4 +321,5 @@ this._sendStream.removeTrack(track);

}
if (this._pc.signalingState === 'stable')
if (this._pc.signalingState === 'stable') {
return;
}
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };

@@ -456,4 +460,5 @@ logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);

const track = stream.getTrackById(localId);
if (!track)
if (!track) {
throw new Error('remote track not found');
}
// Insert into the map.

@@ -532,4 +537,5 @@ this._mapRecvLocalIdInfo.set(localId, { mid, rtpParameters });

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -536,0 +542,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -33,2 +33,3 @@ "use strict";

const sdpUnifiedPlanUtils = __importStar(require("./sdp/unifiedPlanUtils"));
const ortcUtils = __importStar(require("./ortc/utils"));
const HandlerInterface_1 = require("./HandlerInterface");

@@ -96,2 +97,4 @@ const RemoteSdp_1 = require("./sdp/RemoteSdp");

const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
// libwebrtc supports NACK for OPUS but doesn't announce it.
ortcUtils.addNackSuppportForOpus(nativeRtpCapabilities);
return nativeRtpCapabilities;

@@ -184,4 +187,5 @@ }

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -278,4 +282,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

// Hack for VP9 SVC.
if (hackVp9Svc)
if (hackVp9Svc) {
newEncodings = [newEncodings[0]];
}
sendingRtpParameters.encodings = newEncodings;

@@ -324,4 +329,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -348,4 +354,5 @@ this._pc.removeTrack(transceiver.sender);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -365,4 +372,5 @@ this._remoteSdp.pauseMediaSection(localId);

this._remoteSdp.resumeSendingMediaSection(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'sendonly';

@@ -385,4 +393,5 @@ const offer = await this._pc.createOffer();

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -394,10 +403,13 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -417,4 +429,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -436,4 +449,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -555,4 +569,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -575,4 +590,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -593,4 +609,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'recvonly';

@@ -609,4 +626,5 @@ this._remoteSdp.resumeReceivingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -650,4 +668,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -654,0 +673,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -183,4 +183,5 @@ "use strict";

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -255,4 +256,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -292,6 +294,8 @@ }

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
if (rtpSender.track)
}
if (rtpSender.track) {
this._sendStream.removeTrack(rtpSender.track);
}
this._mapSendLocalIdRtpSender.delete(localId);

@@ -312,4 +316,5 @@ const offer = await this._pc.createOffer();

}
if (this._pc.signalingState === 'stable')
if (this._pc.signalingState === 'stable') {
return;
}
const answer = { type: 'answer', sdp: this._remoteSdp.getSdp() };

@@ -336,12 +341,15 @@ logger.debug('stopSending() | calling pc.setRemoteDescription() [answer:%o]', answer);

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const oldTrack = rtpSender.track;
await rtpSender.replaceTrack(track);
// Remove the old track from the local stream.
if (oldTrack)
if (oldTrack) {
this._sendStream.removeTrack(oldTrack);
}
// Add the new track to the local stream.
if (track)
if (track) {
this._sendStream.addTrack(track);
}
}

@@ -352,10 +360,13 @@ async setMaxSpatialLayer(localId, spatialLayer) {

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -368,4 +379,5 @@ await rtpSender.setParameters(parameters);

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
const parameters = rtpSender.getParameters();

@@ -380,4 +392,5 @@ parameters.encodings.forEach((encoding, idx) => {

const rtpSender = this._mapSendLocalIdRtpSender.get(localId);
if (!rtpSender)
if (!rtpSender) {
throw new Error('associated RTCRtpSender not found');
}
return rtpSender.getStats();

@@ -478,4 +491,5 @@ }

.find((r) => r.track && r.track.id === localId);
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('new RTCRtpReceiver not');
}
// Insert into the map.

@@ -510,4 +524,5 @@ this._mapRecvLocalIdInfo.set(localId, { mid, rtpParameters, rtpReceiver });

const { rtpReceiver } = this._mapRecvLocalIdInfo.get(localId) || {};
if (!rtpReceiver)
if (!rtpReceiver) {
throw new Error('associated RTCRtpReceiver not found');
}
return rtpReceiver.getStats();

@@ -561,4 +576,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -565,0 +581,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -33,2 +33,3 @@ "use strict";

const sdpUnifiedPlanUtils = __importStar(require("./sdp/unifiedPlanUtils"));
const ortcUtils = __importStar(require("./ortc/utils"));
const HandlerInterface_1 = require("./HandlerInterface");

@@ -91,2 +92,4 @@ const RemoteSdp_1 = require("./sdp/RemoteSdp");

const nativeRtpCapabilities = sdpCommonUtils.extractRtpCapabilities({ sdpObject });
// libwebrtc supports NACK for OPUS but doesn't announce it.
ortcUtils.addNackSuppportForOpus(nativeRtpCapabilities);
return nativeRtpCapabilities;

@@ -178,4 +181,5 @@ }

this._remoteSdp.updateIceParameters(iceParameters);
if (!this._transportReady)
if (!this._transportReady) {
return;
}
if (this._direction === 'send') {

@@ -252,4 +256,5 @@ const offer = await this._pc.createOffer({ iceRestart: true });

for (let idx = 0; idx < sendingRtpParameters.encodings.length; ++idx) {
if (encodings[idx])
if (encodings[idx]) {
Object.assign(sendingRtpParameters.encodings[idx], encodings[idx]);
}
}

@@ -293,4 +298,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.sender.replaceTrack(null);

@@ -318,4 +324,5 @@ this._pc.removeTrack(transceiver.sender);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -335,4 +342,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'sendonly';

@@ -356,4 +364,5 @@ this._remoteSdp.resumeSendingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
await transceiver.sender.replaceTrack(track);

@@ -365,10 +374,13 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();
parameters.encodings.forEach((encoding, idx) => {
if (idx <= spatialLayer)
if (idx <= spatialLayer) {
encoding.active = true;
else
}
else {
encoding.active = false;
}
});

@@ -388,4 +400,5 @@ await transceiver.sender.setParameters(parameters);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
const parameters = transceiver.sender.getParameters();

@@ -407,4 +420,5 @@ parameters.encodings.forEach((encoding, idx) => {

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.sender.getStats();

@@ -506,4 +520,5 @@ }

.find((t) => t.mid === localId);
if (!transceiver)
if (!transceiver) {
throw new Error('new RTCRtpTransceiver not found');
}
// Store in the map.

@@ -524,4 +539,5 @@ this._mapMidTransceiver.set(localId, transceiver);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
this._remoteSdp.closeMediaSection(transceiver.mid);

@@ -544,4 +560,5 @@ }

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'inactive';

@@ -562,4 +579,5 @@ this._remoteSdp.pauseMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
transceiver.direction = 'recvonly';

@@ -578,4 +596,5 @@ this._remoteSdp.resumeReceivingMediaSection(localId);

const transceiver = this._mapMidTransceiver.get(localId);
if (!transceiver)
if (!transceiver) {
throw new Error('associated RTCRtpTransceiver not found');
}
return transceiver.receiver.getStats();

@@ -619,4 +638,5 @@ }

async setupTransport({ localDtlsRole, localSdpObject }) {
if (!localSdpObject)
if (!localSdpObject) {
localSdpObject = sdpTransform.parse(this._pc.localDescription.sdp);
}
// Get our local DTLS parameters.

@@ -623,0 +643,0 @@ const dtlsParameters = sdpCommonUtils.extractDtlsParameters({ sdpObject: localSdpObject });

@@ -45,4 +45,5 @@ "use strict";

{
if (gotAudio)
if (gotAudio) {
continue;
}
gotAudio = true;

@@ -53,4 +54,5 @@ break;

{
if (gotVideo)
if (gotVideo) {
continue;
}
gotVideo = true;

@@ -81,7 +83,9 @@ break;

const codec = codecsMap.get(fmtp.payload);
if (!codec)
if (!codec) {
continue;
}
// Specials case to convert parameter value to string.
if (parameters && parameters.hasOwnProperty('profile-level-id'))
if (parameters && parameters.hasOwnProperty('profile-level-id')) {
parameters['profile-level-id'] = String(parameters['profile-level-id']);
}
codec.parameters = parameters;

@@ -95,4 +99,5 @@ }

};
if (!feedback.parameter)
if (!feedback.parameter) {
delete feedback.parameter;
}
// rtcp-fb payload is not '*', so just apply it to its corresponding

@@ -102,4 +107,5 @@ // codec.

const codec = codecsMap.get(fb.payload);
if (!codec)
if (!codec) {
continue;
}
codec.rtcpFeedback.push(feedback);

@@ -120,4 +126,5 @@ }

// Ignore encrypted extensions (not yet supported in mediasoup).
if (ext['encrypt-uri'])
if (ext['encrypt-uri']) {
continue;
}
const headerExtension = {

@@ -141,4 +148,5 @@ kind: kind,

.find((m) => (m.iceUfrag && m.port !== 0));
if (!mediaObject)
if (!mediaObject) {
throw new Error('no active media section found');
}
const fingerprint = mediaObject.fingerprint || sdpObject.fingerprint;

@@ -172,4 +180,5 @@ let role;

.find((line) => line.attribute === 'cname');
if (!ssrcCnameLine)
if (!ssrcCnameLine) {
return '';
}
return ssrcCnameLine.value;

@@ -186,8 +195,10 @@ }

// Avoid parsing codec parameters for unhandled codecs.
if (mimeType !== 'audio/opus')
if (mimeType !== 'audio/opus') {
continue;
}
const rtp = (answerMediaObject.rtp || [])
.find((r) => r.payload === codec.payloadType);
if (!rtp)
if (!rtp) {
continue;
}
// Just in case.

@@ -206,4 +217,5 @@ answerMediaObject.fmtp = answerMediaObject.fmtp || [];

const spropStereo = codec.parameters['sprop-stereo'];
if (spropStereo !== undefined)
if (spropStereo !== undefined) {
parameters.stereo = spropStereo ? 1 : 0;
}
break;

@@ -215,4 +227,5 @@ }

for (const key of Object.keys(parameters)) {
if (fmtp.config)
if (fmtp.config) {
fmtp.config += ';';
}
fmtp.config += `${key}=${parameters[key]}`;

@@ -219,0 +232,0 @@ }

@@ -49,4 +49,5 @@ "use strict";

candidateObject.type = candidate.type;
if (candidate.tcpType)
if (candidate.tcpType) {
candidateObject.tcptype = candidate.tcpType;
}
this._mediaObject.candidates.push(candidateObject);

@@ -125,8 +126,10 @@ }

};
if (codec.channels > 1)
if (codec.channels > 1) {
rtp.encoding = codec.channels;
}
this._mediaObject.rtp.push(rtp);
const codecParameters = utils.clone(codec.parameters, {});
let codecRtcpFeedback = utils.clone(codec.rtcpFeedback, []);
if (codecOptions) {
const { opusStereo, opusFec, opusDtx, opusMaxPlaybackRate, opusMaxAverageBitrate, opusPtime, videoGoogleStartBitrate, videoGoogleMaxBitrate, videoGoogleMinBitrate } = codecOptions;
const { opusStereo, opusFec, opusDtx, opusMaxPlaybackRate, opusMaxAverageBitrate, opusPtime, opusNack, videoGoogleStartBitrate, videoGoogleMaxBitrate, videoGoogleMinBitrate } = codecOptions;
const offerCodec = offerRtpParameters.codecs

@@ -136,2 +139,3 @@ .find((c) => (c.payloadType === codec.payloadType));

case 'audio/opus':
case 'audio/multiopus':
{

@@ -160,2 +164,12 @@ if (opusStereo !== undefined) {

}
// If opusNack is not set, we must remove NACK support for OPUS.
// Otherwise it would be enabled for those handlers that artificially
// announce it in their RTP capabilities.
if (!opusNack) {
offerCodec.rtcpFeedback = offerCodec
.rtcpFeedback
.filter((fb) => fb.type !== 'nack' || fb.parameter);
codecRtcpFeedback = codecRtcpFeedback
.filter((fb) => fb.type !== 'nack' || fb.parameter);
}
break;

@@ -168,8 +182,11 @@ }

{
if (videoGoogleStartBitrate !== undefined)
if (videoGoogleStartBitrate !== undefined) {
codecParameters['x-google-start-bitrate'] = videoGoogleStartBitrate;
if (videoGoogleMaxBitrate !== undefined)
}
if (videoGoogleMaxBitrate !== undefined) {
codecParameters['x-google-max-bitrate'] = videoGoogleMaxBitrate;
if (videoGoogleMinBitrate !== undefined)
}
if (videoGoogleMinBitrate !== undefined) {
codecParameters['x-google-min-bitrate'] = videoGoogleMinBitrate;
}
break;

@@ -184,9 +201,11 @@ }

for (const key of Object.keys(codecParameters)) {
if (fmtp.config)
if (fmtp.config) {
fmtp.config += ';';
}
fmtp.config += `${key}=${codecParameters[key]}`;
}
if (fmtp.config)
if (fmtp.config) {
this._mediaObject.fmtp.push(fmtp);
for (const fb of codec.rtcpFeedback) {
}
for (const fb of codecRtcpFeedback) {
this._mediaObject.rtcpFb.push({

@@ -207,4 +226,5 @@ payload: codec.payloadType,

.some((localExt) => localExt.uri === ext.uri);
if (!found)
if (!found) {
continue;
}
this._mediaObject.ext.push({

@@ -229,4 +249,5 @@ uri: ext.uri,

for (const rid of offerMediaObject.rids || []) {
if (rid.direction !== 'send')
if (rid.direction !== 'send') {
continue;
}
this._mediaObject.rids.push({

@@ -247,4 +268,5 @@ id: rid.id,

for (const rid of offerMediaObject.rids || []) {
if (rid.direction !== 'send')
if (rid.direction !== 'send') {
continue;
}
this._mediaObject.rids.push({

@@ -258,4 +280,5 @@ id: rid.id,

this._mediaObject.rtcpRsize = 'rtcp-rsize';
if (this._planB && this._mediaObject.type === 'video')
if (this._planB && this._mediaObject.type === 'video') {
this._mediaObject.xGoogleFlag = 'conference';
}
break;

@@ -333,6 +356,8 @@ }

this._mediaObject.connection = { ip: '127.0.0.1', version: 4 };
if (!sctpParameters)
if (!sctpParameters) {
this._mediaObject.protocol = 'UDP/TLS/RTP/SAVPF';
else
}
else {
this._mediaObject.protocol = 'UDP/DTLS/SCTP';
}
this._mediaObject.port = 7;

@@ -357,4 +382,5 @@ }

this._mediaObject.fmtp = [];
if (!this._planB)
if (!this._planB) {
this._mediaObject.msid = `${streamId || '-'} ${trackId}`;
}
for (const codec of offerRtpParameters.codecs) {

@@ -366,4 +392,5 @@ const rtp = {

};
if (codec.channels > 1)
if (codec.channels > 1) {
rtp.encoding = codec.channels;
}
this._mediaObject.rtp.push(rtp);

@@ -375,8 +402,10 @@ const fmtp = {

for (const key of Object.keys(codec.parameters)) {
if (fmtp.config)
if (fmtp.config) {
fmtp.config += ';';
}
fmtp.config += `${key}=${codec.parameters[key]}`;
}
if (fmtp.config)
if (fmtp.config) {
this._mediaObject.fmtp.push(fmtp);
}
for (const fb of codec.rtcpFeedback) {

@@ -492,4 +521,5 @@ this._mediaObject.rtcpFb.push({

};
if (codec.channels > 1)
if (codec.channels > 1) {
rtp.encoding = codec.channels;
}
this._mediaObject.rtp.push(rtp);

@@ -501,8 +531,10 @@ const fmtp = {

for (const key of Object.keys(codec.parameters)) {
if (fmtp.config)
if (fmtp.config) {
fmtp.config += ';';
}
fmtp.config += `${key}=${codec.parameters[key]}`;
}
if (fmtp.config)
if (fmtp.config) {
this._mediaObject.fmtp.push(fmtp);
}
for (const fb of codec.rtcpFeedback) {

@@ -572,5 +604,6 @@ this._mediaObject.rtcpFb.push({

const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
if (!mimeTypeMatch)
if (!mimeTypeMatch) {
throw new TypeError('invalid codec.mimeType');
}
return mimeTypeMatch[2];
}

@@ -7,4 +7,5 @@ "use strict";

.find((m) => m.type === kind);
if (!mediaObject)
if (!mediaObject) {
throw new Error(`m=${kind} section not found`);
}
const connectionObject = mediaObject.connection || sdpObject.connection;

@@ -21,11 +22,14 @@ return {

.find((m) => m.type === kind);
if (!mediaObject)
if (!mediaObject) {
throw new Error(`m=${kind} section not found`);
}
const ssrcCnameLine = (mediaObject.ssrcs || [])[0];
const ssrc = ssrcCnameLine ? ssrcCnameLine.id : null;
if (ssrc)
if (ssrc) {
return [{ ssrc }];
else
}
else {
return [];
}
}
exports.getRtpEncodings = getRtpEncodings;

@@ -9,4 +9,5 @@ "use strict";

for (const line of offerMediaObject.ssrcs || []) {
if (line.attribute !== 'msid')
if (line.attribute !== 'msid') {
continue;
}
const trackId = line.value.split(' ')[1];

@@ -16,13 +17,16 @@ if (trackId === track.id) {

ssrcs.add(ssrc);
if (!firstSsrc)
if (!firstSsrc) {
firstSsrc = ssrc;
}
}
}
if (ssrcs.size === 0)
if (ssrcs.size === 0) {
throw new Error(`a=ssrc line with msid information not found [track.id:${track.id}]`);
}
const ssrcToRtxSsrc = new Map();
// First assume RTX is used.
for (const line of offerMediaObject.ssrcGroups || []) {
if (line.semantics !== 'FID')
if (line.semantics !== 'FID') {
continue;
}
let [ssrc, rtxSsrc] = line.ssrcs.split(/\s+/);

@@ -49,4 +53,5 @@ ssrc = Number(ssrc);

const encoding = { ssrc };
if (rtxSsrc)
if (rtxSsrc) {
encoding.rtx = { ssrc: rtxSsrc };
}
encodings.push(encoding);

@@ -61,4 +66,5 @@ }

function addLegacySimulcast({ offerMediaObject, track, numStreams }) {
if (numStreams <= 1)
if (numStreams <= 1) {
throw new TypeError('numStreams must be greater than 1');
}
let firstSsrc;

@@ -70,4 +76,5 @@ let firstRtxSsrc;

.find((line) => {
if (line.attribute !== 'msid')
if (line.attribute !== 'msid') {
return false;
}
const trackId = line.value.split(' ')[1];

@@ -83,9 +90,11 @@ if (trackId === track.id) {

});
if (!ssrcMsidLine)
if (!ssrcMsidLine) {
throw new Error(`a=ssrc line with msid information not found [track.id:${track.id}]`);
}
// Get the SSRC for RTX.
(offerMediaObject.ssrcGroups || [])
.some((line) => {
if (line.semantics !== 'FID')
if (line.semantics !== 'FID') {
return false;
}
const ssrcs = line.ssrcs.split(/\s+/);

@@ -102,4 +111,5 @@ if (Number(ssrcs[0]) === firstSsrc) {

.find((line) => (line.attribute === 'cname' && line.id === firstSsrc));
if (!ssrcCnameLine)
if (!ssrcCnameLine) {
throw new Error(`a=ssrc line with cname information not found [track.id:${track.id}]`);
}
const cname = ssrcCnameLine.value;

@@ -110,4 +120,5 @@ const ssrcs = [];

ssrcs.push(firstSsrc + i);
if (firstRtxSsrc)
if (firstRtxSsrc) {
rtxSsrcs.push(firstRtxSsrc + i);
}
}

@@ -114,0 +125,0 @@ offerMediaObject.ssrcGroups = offerMediaObject.ssrcGroups || [];

@@ -99,4 +99,5 @@ "use strict";

const mediaSection = this._mediaSections[idx];
if (mediaSection.closed)
if (mediaSection.closed) {
return { idx, reuseMid: mediaSection.mid };
}
}

@@ -135,4 +136,5 @@ // If no closed media section is found, return next one.

let mediaSection;
if (idx !== undefined)
if (idx !== undefined) {
mediaSection = this._mediaSections[idx];
}
// Unified-Plan or different media kind.

@@ -245,4 +247,5 @@ if (!mediaSection) {

_addMediaSection(newMediaSection) {
if (!this._firstMid)
if (!this._firstMid) {
this._firstMid = newMediaSection.mid;
}
// Add to the vector.

@@ -294,4 +297,5 @@ this._mediaSections.push(newMediaSection);

_regenerateBundleMids() {
if (!this._dtlsParameters)
if (!this._dtlsParameters) {
return;
}
this._sdpObject.groups[0].mids = this._mediaSections

@@ -298,0 +302,0 @@ .filter((mediaSection) => !mediaSection.closed)

@@ -10,9 +10,11 @@ "use strict";

}
if (ssrcs.size === 0)
if (ssrcs.size === 0) {
throw new Error('no a=ssrc lines found');
}
const ssrcToRtxSsrc = new Map();
// First assume RTX is used.
for (const line of offerMediaObject.ssrcGroups || []) {
if (line.semantics !== 'FID')
if (line.semantics !== 'FID') {
continue;
}
let [ssrc, rtxSsrc] = line.ssrcs.split(/\s+/);

@@ -39,4 +41,5 @@ ssrc = Number(ssrc);

const encoding = { ssrc };
if (rtxSsrc)
if (rtxSsrc) {
encoding.rtx = { ssrc: rtxSsrc };
}
encodings.push(encoding);

@@ -51,9 +54,11 @@ }

function addLegacySimulcast({ offerMediaObject, numStreams }) {
if (numStreams <= 1)
if (numStreams <= 1) {
throw new TypeError('numStreams must be greater than 1');
}
// Get the SSRC.
const ssrcMsidLine = (offerMediaObject.ssrcs || [])
.find((line) => line.attribute === 'msid');
if (!ssrcMsidLine)
if (!ssrcMsidLine) {
throw new Error('a=ssrc line with msid information not found');
}
const [streamId, trackId] = ssrcMsidLine.value.split(' ');

@@ -65,4 +70,5 @@ const firstSsrc = ssrcMsidLine.id;

.some((line) => {
if (line.semantics !== 'FID')
if (line.semantics !== 'FID') {
return false;
}
const ssrcs = line.ssrcs.split(/\s+/);

@@ -79,4 +85,5 @@ if (Number(ssrcs[0]) === firstSsrc) {

.find((line) => line.attribute === 'cname');
if (!ssrcCnameLine)
if (!ssrcCnameLine) {
throw new Error('a=ssrc line with cname information not found');
}
const cname = ssrcCnameLine.value;

@@ -87,4 +94,5 @@ const ssrcs = [];

ssrcs.push(firstSsrc + i);
if (firstRtxSsrc)
if (firstRtxSsrc) {
rtxSsrcs.push(firstRtxSsrc + i);
}
}

@@ -91,0 +99,0 @@ offerMediaObject.ssrcGroups = [];

@@ -11,3 +11,3 @@ import debug from 'debug';

*/
export declare const version = "3.6.80";
export declare const version = "3.6.81";
/**

@@ -14,0 +14,0 @@ * Expose Device class and detectDevice() helper.

@@ -40,3 +40,3 @@ "use strict";

*/
exports.version = '3.6.80';
exports.version = '3.6.81';
/**

@@ -43,0 +43,0 @@ * Expose parseScalabilityMode() function.

@@ -38,9 +38,12 @@ "use strict";

function validateRtpCapabilities(caps) {
if (typeof caps !== 'object')
if (typeof caps !== 'object') {
throw new TypeError('caps is not an object');
}
// codecs is optional. If unset, fill with an empty array.
if (caps.codecs && !Array.isArray(caps.codecs))
if (caps.codecs && !Array.isArray(caps.codecs)) {
throw new TypeError('caps.codecs is not an array');
else if (!caps.codecs)
}
else if (!caps.codecs) {
caps.codecs = [];
}
for (const codec of caps.codecs) {

@@ -50,6 +53,8 @@ validateRtpCodecCapability(codec);

// headerExtensions is optional. If unset, fill with an empty array.
if (caps.headerExtensions && !Array.isArray(caps.headerExtensions))
if (caps.headerExtensions && !Array.isArray(caps.headerExtensions)) {
throw new TypeError('caps.headerExtensions is not an array');
else if (!caps.headerExtensions)
}
else if (!caps.headerExtensions) {
caps.headerExtensions = [];
}
for (const ext of caps.headerExtensions) {

@@ -67,22 +72,28 @@ validateRtpHeaderExtension(ext);

const MimeTypeRegex = new RegExp('^(audio|video)/(.+)', 'i');
if (typeof codec !== 'object')
if (typeof codec !== 'object') {
throw new TypeError('codec is not an object');
}
// mimeType is mandatory.
if (!codec.mimeType || typeof codec.mimeType !== 'string')
if (!codec.mimeType || typeof codec.mimeType !== 'string') {
throw new TypeError('missing codec.mimeType');
}
const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
if (!mimeTypeMatch)
if (!mimeTypeMatch) {
throw new TypeError('invalid codec.mimeType');
}
// Just override kind with media component of mimeType.
codec.kind = mimeTypeMatch[1].toLowerCase();
// preferredPayloadType is optional.
if (codec.preferredPayloadType && typeof codec.preferredPayloadType !== 'number')
if (codec.preferredPayloadType && typeof codec.preferredPayloadType !== 'number') {
throw new TypeError('invalid codec.preferredPayloadType');
}
// clockRate is mandatory.
if (typeof codec.clockRate !== 'number')
if (typeof codec.clockRate !== 'number') {
throw new TypeError('missing codec.clockRate');
}
// channels is optional. If unset, set it to 1 (just if audio).
if (codec.kind === 'audio') {
if (typeof codec.channels !== 'number')
if (typeof codec.channels !== 'number') {
codec.channels = 1;
}
}

@@ -93,4 +104,5 @@ else {

// parameters is optional. If unset, set it to an empty object.
if (!codec.parameters || typeof codec.parameters !== 'object')
if (!codec.parameters || typeof codec.parameters !== 'object') {
codec.parameters = {};
}
for (const key of Object.keys(codec.parameters)) {

@@ -107,9 +119,11 @@ let value = codec.parameters[key];

if (key === 'apt') {
if (typeof value !== 'number')
if (typeof value !== 'number') {
throw new TypeError('invalid codec apt parameter');
}
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback))
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback)) {
codec.rtcpFeedback = [];
}
for (const fb of codec.rtcpFeedback) {

@@ -126,10 +140,13 @@ validateRtcpFeedback(fb);

function validateRtcpFeedback(fb) {
if (typeof fb !== 'object')
if (typeof fb !== 'object') {
throw new TypeError('fb is not an object');
}
// type is mandatory.
if (!fb.type || typeof fb.type !== 'string')
if (!fb.type || typeof fb.type !== 'string') {
throw new TypeError('missing fb.type');
}
// parameter is optional. If unset set it to an empty string.
if (!fb.parameter || typeof fb.parameter !== 'string')
if (!fb.parameter || typeof fb.parameter !== 'string') {
fb.parameter = '';
}
}

@@ -143,23 +160,31 @@ exports.validateRtcpFeedback = validateRtcpFeedback;

function validateRtpHeaderExtension(ext) {
if (typeof ext !== 'object')
if (typeof ext !== 'object') {
throw new TypeError('ext is not an object');
}
// kind is mandatory.
if (ext.kind !== 'audio' && ext.kind !== 'video')
if (ext.kind !== 'audio' && ext.kind !== 'video') {
throw new TypeError('invalid ext.kind');
}
// uri is mandatory.
if (!ext.uri || typeof ext.uri !== 'string')
if (!ext.uri || typeof ext.uri !== 'string') {
throw new TypeError('missing ext.uri');
}
// preferredId is mandatory.
if (typeof ext.preferredId !== 'number')
if (typeof ext.preferredId !== 'number') {
throw new TypeError('missing ext.preferredId');
}
// preferredEncrypt is optional. If unset set it to false.
if (ext.preferredEncrypt && typeof ext.preferredEncrypt !== 'boolean')
if (ext.preferredEncrypt && typeof ext.preferredEncrypt !== 'boolean') {
throw new TypeError('invalid ext.preferredEncrypt');
else if (!ext.preferredEncrypt)
}
else if (!ext.preferredEncrypt) {
ext.preferredEncrypt = false;
}
// direction is optional. If unset set it to sendrecv.
if (ext.direction && typeof ext.direction !== 'string')
if (ext.direction && typeof ext.direction !== 'string') {
throw new TypeError('invalid ext.direction');
else if (!ext.direction)
}
else if (!ext.direction) {
ext.direction = 'sendrecv';
}
}

@@ -173,10 +198,13 @@ exports.validateRtpHeaderExtension = validateRtpHeaderExtension;

function validateRtpParameters(params) {
if (typeof params !== 'object')
if (typeof params !== 'object') {
throw new TypeError('params is not an object');
}
// mid is optional.
if (params.mid && typeof params.mid !== 'string')
if (params.mid && typeof params.mid !== 'string') {
throw new TypeError('params.mid is not a string');
}
// codecs is mandatory.
if (!Array.isArray(params.codecs))
if (!Array.isArray(params.codecs)) {
throw new TypeError('missing params.codecs');
}
for (const codec of params.codecs) {

@@ -186,6 +214,8 @@ validateRtpCodecParameters(codec);

// headerExtensions is optional. If unset, fill with an empty array.
if (params.headerExtensions && !Array.isArray(params.headerExtensions))
if (params.headerExtensions && !Array.isArray(params.headerExtensions)) {
throw new TypeError('params.headerExtensions is not an array');
else if (!params.headerExtensions)
}
else if (!params.headerExtensions) {
params.headerExtensions = [];
}
for (const ext of params.headerExtensions) {

@@ -195,6 +225,8 @@ validateRtpHeaderExtensionParameters(ext);

// encodings is optional. If unset, fill with an empty array.
if (params.encodings && !Array.isArray(params.encodings))
if (params.encodings && !Array.isArray(params.encodings)) {
throw new TypeError('params.encodings is not an array');
else if (!params.encodings)
}
else if (!params.encodings) {
params.encodings = [];
}
for (const encoding of params.encodings) {

@@ -204,6 +236,8 @@ validateRtpEncodingParameters(encoding);

// rtcp is optional. If unset, fill with an empty object.
if (params.rtcp && typeof params.rtcp !== 'object')
if (params.rtcp && typeof params.rtcp !== 'object') {
throw new TypeError('params.rtcp is not an object');
else if (!params.rtcp)
}
else if (!params.rtcp) {
params.rtcp = {};
}
validateRtcpParameters(params.rtcp);

@@ -219,21 +253,27 @@ }

const MimeTypeRegex = new RegExp('^(audio|video)/(.+)', 'i');
if (typeof codec !== 'object')
if (typeof codec !== 'object') {
throw new TypeError('codec is not an object');
}
// mimeType is mandatory.
if (!codec.mimeType || typeof codec.mimeType !== 'string')
if (!codec.mimeType || typeof codec.mimeType !== 'string') {
throw new TypeError('missing codec.mimeType');
}
const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
if (!mimeTypeMatch)
if (!mimeTypeMatch) {
throw new TypeError('invalid codec.mimeType');
}
// payloadType is mandatory.
if (typeof codec.payloadType !== 'number')
if (typeof codec.payloadType !== 'number') {
throw new TypeError('missing codec.payloadType');
}
// clockRate is mandatory.
if (typeof codec.clockRate !== 'number')
if (typeof codec.clockRate !== 'number') {
throw new TypeError('missing codec.clockRate');
}
const kind = mimeTypeMatch[1].toLowerCase();
// channels is optional. If unset, set it to 1 (just if audio).
if (kind === 'audio') {
if (typeof codec.channels !== 'number')
if (typeof codec.channels !== 'number') {
codec.channels = 1;
}
}

@@ -244,4 +284,5 @@ else {

// parameters is optional. If unset, set it to an empty object.
if (!codec.parameters || typeof codec.parameters !== 'object')
if (!codec.parameters || typeof codec.parameters !== 'object') {
codec.parameters = {};
}
for (const key of Object.keys(codec.parameters)) {

@@ -258,9 +299,11 @@ let value = codec.parameters[key];

if (key === 'apt') {
if (typeof value !== 'number')
if (typeof value !== 'number') {
throw new TypeError('invalid codec apt parameter');
}
}
}
// rtcpFeedback is optional. If unset, set it to an empty array.
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback))
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback)) {
codec.rtcpFeedback = [];
}
for (const fb of codec.rtcpFeedback) {

@@ -277,18 +320,24 @@ validateRtcpFeedback(fb);

function validateRtpHeaderExtensionParameters(ext) {
if (typeof ext !== 'object')
if (typeof ext !== 'object') {
throw new TypeError('ext is not an object');
}
// uri is mandatory.
if (!ext.uri || typeof ext.uri !== 'string')
if (!ext.uri || typeof ext.uri !== 'string') {
throw new TypeError('missing ext.uri');
}
// id is mandatory.
if (typeof ext.id !== 'number')
if (typeof ext.id !== 'number') {
throw new TypeError('missing ext.id');
}
// encrypt is optional. If unset set it to false.
if (ext.encrypt && typeof ext.encrypt !== 'boolean')
if (ext.encrypt && typeof ext.encrypt !== 'boolean') {
throw new TypeError('invalid ext.encrypt');
else if (!ext.encrypt)
}
else if (!ext.encrypt) {
ext.encrypt = false;
}
// parameters is optional. If unset, set it to an empty object.
if (!ext.parameters || typeof ext.parameters !== 'object')
if (!ext.parameters || typeof ext.parameters !== 'object') {
ext.parameters = {};
}
for (const key of Object.keys(ext.parameters)) {

@@ -300,4 +349,5 @@ let value = ext.parameters[key];

}
if (typeof value !== 'string' && typeof value !== 'number')
if (typeof value !== 'string' && typeof value !== 'number') {
throw new TypeError('invalid header extension parameter');
}
}

@@ -312,10 +362,13 @@ }

function validateRtpEncodingParameters(encoding) {
if (typeof encoding !== 'object')
if (typeof encoding !== 'object') {
throw new TypeError('encoding is not an object');
}
// ssrc is optional.
if (encoding.ssrc && typeof encoding.ssrc !== 'number')
if (encoding.ssrc && typeof encoding.ssrc !== 'number') {
throw new TypeError('invalid encoding.ssrc');
}
// rid is optional.
if (encoding.rid && typeof encoding.rid !== 'string')
if (encoding.rid && typeof encoding.rid !== 'string') {
throw new TypeError('invalid encoding.rid');
}
// rtx is optional.

@@ -327,11 +380,14 @@ if (encoding.rtx && typeof encoding.rtx !== 'object') {

// RTX ssrc is mandatory if rtx is present.
if (typeof encoding.rtx.ssrc !== 'number')
if (typeof encoding.rtx.ssrc !== 'number') {
throw new TypeError('missing encoding.rtx.ssrc');
}
}
// dtx is optional. If unset set it to false.
if (!encoding.dtx || typeof encoding.dtx !== 'boolean')
if (!encoding.dtx || typeof encoding.dtx !== 'boolean') {
encoding.dtx = false;
}
// scalabilityMode is optional.
if (encoding.scalabilityMode && typeof encoding.scalabilityMode !== 'string')
if (encoding.scalabilityMode && typeof encoding.scalabilityMode !== 'string') {
throw new TypeError('invalid encoding.scalabilityMode');
}
}

@@ -345,10 +401,13 @@ exports.validateRtpEncodingParameters = validateRtpEncodingParameters;

function validateRtcpParameters(rtcp) {
if (typeof rtcp !== 'object')
if (typeof rtcp !== 'object') {
throw new TypeError('rtcp is not an object');
}
// cname is optional.
if (rtcp.cname && typeof rtcp.cname !== 'string')
if (rtcp.cname && typeof rtcp.cname !== 'string') {
throw new TypeError('invalid rtcp.cname');
}
// reducedSize is optional. If unset set it to true.
if (!rtcp.reducedSize || typeof rtcp.reducedSize !== 'boolean')
if (!rtcp.reducedSize || typeof rtcp.reducedSize !== 'boolean') {
rtcp.reducedSize = true;
}
}

@@ -362,7 +421,9 @@ exports.validateRtcpParameters = validateRtcpParameters;

function validateSctpCapabilities(caps) {
if (typeof caps !== 'object')
if (typeof caps !== 'object') {
throw new TypeError('caps is not an object');
}
// numStreams is mandatory.
if (!caps.numStreams || typeof caps.numStreams !== 'object')
if (!caps.numStreams || typeof caps.numStreams !== 'object') {
throw new TypeError('missing caps.numStreams');
}
validateNumSctpStreams(caps.numStreams);

@@ -377,10 +438,13 @@ }

function validateNumSctpStreams(numStreams) {
if (typeof numStreams !== 'object')
if (typeof numStreams !== 'object') {
throw new TypeError('numStreams is not an object');
}
// OS is mandatory.
if (typeof numStreams.OS !== 'number')
if (typeof numStreams.OS !== 'number') {
throw new TypeError('missing numStreams.OS');
}
// MIS is mandatory.
if (typeof numStreams.MIS !== 'number')
if (typeof numStreams.MIS !== 'number') {
throw new TypeError('missing numStreams.MIS');
}
}

@@ -394,16 +458,21 @@ exports.validateNumSctpStreams = validateNumSctpStreams;

function validateSctpParameters(params) {
if (typeof params !== 'object')
if (typeof params !== 'object') {
throw new TypeError('params is not an object');
}
// port is mandatory.
if (typeof params.port !== 'number')
if (typeof params.port !== 'number') {
throw new TypeError('missing params.port');
}
// OS is mandatory.
if (typeof params.OS !== 'number')
if (typeof params.OS !== 'number') {
throw new TypeError('missing params.OS');
}
// MIS is mandatory.
if (typeof params.MIS !== 'number')
if (typeof params.MIS !== 'number') {
throw new TypeError('missing params.MIS');
}
// maxMessageSize is mandatory.
if (typeof params.maxMessageSize !== 'number')
if (typeof params.maxMessageSize !== 'number') {
throw new TypeError('missing params.maxMessageSize');
}
}

@@ -417,21 +486,28 @@ exports.validateSctpParameters = validateSctpParameters;

function validateSctpStreamParameters(params) {
if (typeof params !== 'object')
if (typeof params !== 'object') {
throw new TypeError('params is not an object');
}
// streamId is mandatory.
if (typeof params.streamId !== 'number')
if (typeof params.streamId !== 'number') {
throw new TypeError('missing params.streamId');
}
// ordered is optional.
let orderedGiven = false;
if (typeof params.ordered === 'boolean')
if (typeof params.ordered === 'boolean') {
orderedGiven = true;
else
}
else {
params.ordered = true;
}
// maxPacketLifeTime is optional.
if (params.maxPacketLifeTime && typeof params.maxPacketLifeTime !== 'number')
if (params.maxPacketLifeTime && typeof params.maxPacketLifeTime !== 'number') {
throw new TypeError('invalid params.maxPacketLifeTime');
}
// maxRetransmits is optional.
if (params.maxRetransmits && typeof params.maxRetransmits !== 'number')
if (params.maxRetransmits && typeof params.maxRetransmits !== 'number') {
throw new TypeError('invalid params.maxRetransmits');
if (params.maxPacketLifeTime && params.maxRetransmits)
}
if (params.maxPacketLifeTime && params.maxRetransmits) {
throw new TypeError('cannot provide both maxPacketLifeTime and maxRetransmits');
}
if (orderedGiven &&

@@ -446,7 +522,9 @@ params.ordered &&

// label is optional.
if (params.label && typeof params.label !== 'string')
if (params.label && typeof params.label !== 'string') {
throw new TypeError('invalid params.label');
}
// protocol is optional.
if (params.protocol && typeof params.protocol !== 'string')
if (params.protocol && typeof params.protocol !== 'string') {
throw new TypeError('invalid params.protocol');
}
}

@@ -464,8 +542,10 @@ exports.validateSctpStreamParameters = validateSctpStreamParameters;

for (const remoteCodec of remoteCaps.codecs || []) {
if (isRtxCodec(remoteCodec))
if (isRtxCodec(remoteCodec)) {
continue;
}
const matchingLocalCodec = (localCaps.codecs || [])
.find((localCodec) => (matchCodecs(localCodec, remoteCodec, { strict: true, modify: true })));
if (!matchingLocalCodec)
if (!matchingLocalCodec) {
continue;
}
const extendedCodec = {

@@ -503,4 +583,5 @@ mimeType: matchingLocalCodec.mimeType,

.find((localExt) => (matchHeaderExtensions(localExt, remoteExt)));
if (!matchingLocalExt)
if (!matchingLocalExt) {
continue;
}
const extendedExt = {

@@ -554,4 +635,5 @@ kind: remoteExt.kind,

// Add RTX codec.
if (!extendedCodec.remoteRtxPayloadType)
if (!extendedCodec.remoteRtxPayloadType) {
continue;
}
const rtxCodec = {

@@ -601,4 +683,5 @@ mimeType: `${extendedCodec.kind}/rtx`,

for (const extendedCodec of extendedRtpCapabilities.codecs) {
if (extendedCodec.kind !== kind)
if (extendedCodec.kind !== kind) {
continue;
}
const codec = {

@@ -657,4 +740,5 @@ mimeType: extendedCodec.mimeType,

for (const extendedCodec of extendedRtpCapabilities.codecs) {
if (extendedCodec.kind !== kind)
if (extendedCodec.kind !== kind) {
continue;
}
const codec = {

@@ -736,4 +820,5 @@ mimeType: extendedCodec.mimeType,

filteredCodecs.push(codecs[0]);
if (isRtxCodec(codecs[1]))
if (isRtxCodec(codecs[1])) {
filteredCodecs.push(codecs[1]);
}
}

@@ -745,9 +830,11 @@ // Otherwise look for a compatible set of codecs.

filteredCodecs.push(codecs[idx]);
if (isRtxCodec(codecs[idx + 1]))
if (isRtxCodec(codecs[idx + 1])) {
filteredCodecs.push(codecs[idx + 1]);
}
break;
}
}
if (filteredCodecs.length === 0)
if (filteredCodecs.length === 0) {
throw new TypeError('no matching codec found');
}
}

@@ -793,4 +880,5 @@ return filteredCodecs;

validateRtpParameters(rtpParameters);
if (rtpParameters.codecs.length === 0)
if (rtpParameters.codecs.length === 0) {
return false;
}
const firstMediaCodec = rtpParameters.codecs[0];

@@ -802,4 +890,5 @@ return extendedRtpCapabilities.codecs

function isRtxCodec(codec) {
if (!codec)
if (!codec) {
return false;
}
return /.+\/rtx$/i.test(codec.mimeType);

@@ -810,8 +899,11 @@ }

const bMimeType = bCodec.mimeType.toLowerCase();
if (aMimeType !== bMimeType)
if (aMimeType !== bMimeType) {
return false;
if (aCodec.clockRate !== bCodec.clockRate)
}
if (aCodec.clockRate !== bCodec.clockRate) {
return false;
if (aCodec.channels !== bCodec.channels)
}
if (aCodec.channels !== bCodec.channels) {
return false;
}
// Per codec special checks.

@@ -824,6 +916,8 @@ switch (aMimeType) {

const bPacketizationMode = bCodec.parameters['packetization-mode'] || 0;
if (aPacketizationMode !== bPacketizationMode)
if (aPacketizationMode !== bPacketizationMode) {
return false;
if (!h264.isSameProfile(aCodec.parameters, bCodec.parameters))
}
if (!h264.isSameProfile(aCodec.parameters, bCodec.parameters)) {
return false;
}
let selectedProfileLevelId;

@@ -855,4 +949,5 @@ try {

const bProfileId = bCodec.parameters['profile-id'] || 0;
if (aProfileId !== bProfileId)
if (aProfileId !== bProfileId) {
return false;
}
}

@@ -865,6 +960,8 @@ break;

function matchHeaderExtensions(aExt, bExt) {
if (aExt.kind && bExt.kind && aExt.kind !== bExt.kind)
if (aExt.kind && bExt.kind && aExt.kind !== bExt.kind) {
return false;
if (aExt.uri !== bExt.uri)
}
if (aExt.uri !== bExt.uri) {
return false;
}
return true;

@@ -878,6 +975,7 @@ }

(bFb.parameter === aFb.parameter || (!bFb.parameter && !aFb.parameter))));
if (matchingBFb)
if (matchingBFb) {
reducedRtcpFeedback.push(matchingBFb);
}
}
return reducedRtcpFeedback;
}

@@ -20,2 +20,3 @@ import { EnhancedEventEmitter } from './EnhancedEventEmitter';

opusPtime?: number;
opusNack?: boolean;
videoGoogleStartBitrate?: number;

@@ -22,0 +23,0 @@ videoGoogleMaxBitrate?: number;

@@ -109,4 +109,5 @@ "use strict";

close() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('close()');

@@ -123,4 +124,5 @@ this._closed = true;

transportClosed() {
if (this._closed)
if (this._closed) {
return;
}
logger.debug('transportClosed()');

@@ -137,4 +139,5 @@ this._closed = true;

async getStats() {
if (this._closed)
if (this._closed) {
throw new errors_1.InvalidStateError('closed');
}
return new Promise((resolve, reject) => {

@@ -220,6 +223,8 @@ this.safeEmit('@getstats', resolve, reject);

if (this._track && this._disableTrackOnPause) {
if (!this._paused)
if (!this._paused) {
this._track.enabled = true;
else if (this._paused)
}
else if (this._paused) {
this._track.enabled = false;
}
}

@@ -233,10 +238,14 @@ // Handle the effective track.

async setMaxSpatialLayer(spatialLayer) {
if (this._closed)
if (this._closed) {
throw new errors_1.InvalidStateError('closed');
else if (this._kind !== 'video')
}
else if (this._kind !== 'video') {
throw new errors_1.UnsupportedError('not a video Producer');
else if (typeof spatialLayer !== 'number')
}
else if (typeof spatialLayer !== 'number') {
throw new TypeError('invalid spatialLayer');
if (spatialLayer === this._maxSpatialLayer)
}
if (spatialLayer === this._maxSpatialLayer) {
return;
}
await new Promise((resolve, reject) => {

@@ -248,6 +257,8 @@ this.safeEmit('@setmaxspatiallayer', spatialLayer, resolve, reject);

async setRtpEncodingParameters(params) {
if (this._closed)
if (this._closed) {
throw new errors_1.InvalidStateError('closed');
else if (typeof params !== 'object')
}
else if (typeof params !== 'object') {
throw new TypeError('invalid params');
}
await new Promise((resolve, reject) => {

@@ -264,14 +275,17 @@ this.safeEmit('@setrtpencodingparameters', params, resolve, reject);

handleTrack() {
if (!this._track)
if (!this._track) {
return;
}
this._track.addEventListener('ended', this.onTrackEnded);
}
destroyTrack() {
if (!this._track)
if (!this._track) {
return;
}
try {
this._track.removeEventListener('ended', this.onTrackEnded);
// Just stop the track unless the app set stopTracks: false.
if (this._stopTracks)
if (this._stopTracks) {
this._track.stop();
}
}

@@ -278,0 +292,0 @@ catch (error) { }

@@ -8,4 +8,5 @@ "use strict";

function clone(data, defaultValue) {
if (typeof data === 'undefined')
if (typeof data === 'undefined') {
return defaultValue;
}
return JSON.parse(JSON.stringify(data));

@@ -12,0 +13,0 @@ }

{
"name": "mediasoup-client",
"version": "3.6.80",
"version": "3.6.81",
"description": "mediasoup client side JavaScript library",

@@ -78,4 +78,4 @@ "contributors": [

"@types/sdp-transform": "^2.4.5",
"@typescript-eslint/eslint-plugin": "^5.52.0",
"@typescript-eslint/parser": "^5.52.0",
"@typescript-eslint/eslint-plugin": "^5.53.0",
"@typescript-eslint/parser": "^5.53.0",
"eslint": "^8.34.0",

@@ -82,0 +82,0 @@ "eslint-plugin-jest": "^27.2.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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