mediasoup-client 3.7.2 → 3.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/lib/Transport.d.ts +7 -1
- package/lib/Transport.d.ts.map +1 -1
- package/lib/Transport.js +2 -2
- package/lib/handlers/Chrome111.d.ts.map +1 -1
- package/lib/handlers/Chrome111.js +5 -1
- package/lib/handlers/Chrome55.d.ts.map +1 -1
- package/lib/handlers/Chrome55.js +5 -1
- package/lib/handlers/Chrome67.d.ts.map +1 -1
- package/lib/handlers/Chrome67.js +5 -1
- package/lib/handlers/Chrome70.d.ts.map +1 -1
- package/lib/handlers/Chrome70.js +5 -1
- package/lib/handlers/Chrome74.d.ts.map +1 -1
- package/lib/handlers/Chrome74.js +5 -1
- package/lib/handlers/Edge11.d.ts.map +1 -1
- package/lib/handlers/Edge11.js +3 -1
- package/lib/handlers/FakeHandler.d.ts.map +1 -1
- package/lib/handlers/FakeHandler.js +2 -1
- package/lib/handlers/Firefox60.d.ts.map +1 -1
- package/lib/handlers/Firefox60.js +5 -1
- package/lib/handlers/HandlerInterface.d.ts +1 -0
- package/lib/handlers/HandlerInterface.d.ts.map +1 -1
- package/lib/handlers/ReactNative.d.ts.map +1 -1
- package/lib/handlers/ReactNative.js +5 -1
- package/lib/handlers/ReactNativeUnifiedPlan.d.ts.map +1 -1
- package/lib/handlers/ReactNativeUnifiedPlan.js +5 -1
- package/lib/handlers/Safari11.d.ts.map +1 -1
- package/lib/handlers/Safari11.js +5 -1
- package/lib/handlers/Safari12.d.ts.map +1 -1
- package/lib/handlers/Safari12.js +5 -1
- package/lib/handlers/sdp/MediaSection.d.ts.map +1 -1
- package/lib/handlers/sdp/MediaSection.js +3 -1
- package/lib/handlers/sdp/commonUtils.d.ts +4 -1
- package/lib/handlers/sdp/commonUtils.d.ts.map +1 -1
- package/lib/handlers/sdp/commonUtils.js +24 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/ortc.d.ts +4 -58
- package/lib/ortc.d.ts.map +1 -1
- package/lib/ortc.js +344 -380
- package/lib/test/fakeParameters.d.ts +1 -0
- package/lib/test/fakeParameters.d.ts.map +1 -1
- package/lib/test/fakeParameters.js +10 -1
- package/lib/test/test.js +5 -3
- package/npm-scripts.mjs +6 -8
- package/package.json +11 -11
package/lib/ortc.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.canReceive = exports.canSend = exports.generateProbatorRtpParameters = exports.reduceCodecs = exports.getSendingRemoteRtpParameters = exports.getSendingRtpParameters = exports.getRecvRtpCapabilities = exports.getExtendedRtpCapabilities = exports.
|
|
26
|
+
exports.canReceive = exports.canSend = exports.generateProbatorRtpParameters = exports.reduceCodecs = exports.getSendingRemoteRtpParameters = exports.getSendingRtpParameters = exports.getRecvRtpCapabilities = exports.getExtendedRtpCapabilities = exports.validateSctpCapabilities = exports.validateSctpStreamParameters = exports.validateRtpParameters = exports.validateRtpCapabilities = void 0;
|
|
27
27
|
const h264 = __importStar(require("h264-profile-level-id"));
|
|
28
28
|
const utils = __importStar(require("./utils"));
|
|
29
29
|
const RTP_PROBATOR_MID = 'probator';
|
|
@@ -60,129 +60,6 @@ function validateRtpCapabilities(caps) {
|
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
exports.validateRtpCapabilities = validateRtpCapabilities;
|
|
63
|
-
/**
|
|
64
|
-
* Validates RtpCodecCapability. It may modify given data by adding missing
|
|
65
|
-
* fields with default values.
|
|
66
|
-
* It throws if invalid.
|
|
67
|
-
*/
|
|
68
|
-
function validateRtpCodecCapability(codec) {
|
|
69
|
-
const MimeTypeRegex = new RegExp('^(audio|video)/(.+)', 'i');
|
|
70
|
-
if (typeof codec !== 'object') {
|
|
71
|
-
throw new TypeError('codec is not an object');
|
|
72
|
-
}
|
|
73
|
-
// mimeType is mandatory.
|
|
74
|
-
if (!codec.mimeType || typeof codec.mimeType !== 'string') {
|
|
75
|
-
throw new TypeError('missing codec.mimeType');
|
|
76
|
-
}
|
|
77
|
-
const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
|
|
78
|
-
if (!mimeTypeMatch) {
|
|
79
|
-
throw new TypeError('invalid codec.mimeType');
|
|
80
|
-
}
|
|
81
|
-
// Just override kind with media component of mimeType.
|
|
82
|
-
codec.kind = mimeTypeMatch[1].toLowerCase();
|
|
83
|
-
// preferredPayloadType is optional.
|
|
84
|
-
if (codec.preferredPayloadType &&
|
|
85
|
-
typeof codec.preferredPayloadType !== 'number') {
|
|
86
|
-
throw new TypeError('invalid codec.preferredPayloadType');
|
|
87
|
-
}
|
|
88
|
-
// clockRate is mandatory.
|
|
89
|
-
if (typeof codec.clockRate !== 'number') {
|
|
90
|
-
throw new TypeError('missing codec.clockRate');
|
|
91
|
-
}
|
|
92
|
-
// channels is optional. If unset, set it to 1 (just if audio).
|
|
93
|
-
if (codec.kind === 'audio') {
|
|
94
|
-
if (typeof codec.channels !== 'number') {
|
|
95
|
-
codec.channels = 1;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
delete codec.channels;
|
|
100
|
-
}
|
|
101
|
-
// parameters is optional. If unset, set it to an empty object.
|
|
102
|
-
if (!codec.parameters || typeof codec.parameters !== 'object') {
|
|
103
|
-
codec.parameters = {};
|
|
104
|
-
}
|
|
105
|
-
for (const key of Object.keys(codec.parameters)) {
|
|
106
|
-
let value = codec.parameters[key];
|
|
107
|
-
if (value === undefined) {
|
|
108
|
-
codec.parameters[key] = '';
|
|
109
|
-
value = '';
|
|
110
|
-
}
|
|
111
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
112
|
-
throw new TypeError(`invalid codec parameter [key:${key}s, value:${value}]`);
|
|
113
|
-
}
|
|
114
|
-
// Specific parameters validation.
|
|
115
|
-
if (key === 'apt') {
|
|
116
|
-
if (typeof value !== 'number') {
|
|
117
|
-
throw new TypeError('invalid codec apt parameter');
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// rtcpFeedback is optional. If unset, set it to an empty array.
|
|
122
|
-
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback)) {
|
|
123
|
-
codec.rtcpFeedback = [];
|
|
124
|
-
}
|
|
125
|
-
for (const fb of codec.rtcpFeedback) {
|
|
126
|
-
validateRtcpFeedback(fb);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
exports.validateRtpCodecCapability = validateRtpCodecCapability;
|
|
130
|
-
/**
|
|
131
|
-
* Validates RtcpFeedback. It may modify given data by adding missing
|
|
132
|
-
* fields with default values.
|
|
133
|
-
* It throws if invalid.
|
|
134
|
-
*/
|
|
135
|
-
function validateRtcpFeedback(fb) {
|
|
136
|
-
if (typeof fb !== 'object') {
|
|
137
|
-
throw new TypeError('fb is not an object');
|
|
138
|
-
}
|
|
139
|
-
// type is mandatory.
|
|
140
|
-
if (!fb.type || typeof fb.type !== 'string') {
|
|
141
|
-
throw new TypeError('missing fb.type');
|
|
142
|
-
}
|
|
143
|
-
// parameter is optional. If unset set it to an empty string.
|
|
144
|
-
if (!fb.parameter || typeof fb.parameter !== 'string') {
|
|
145
|
-
fb.parameter = '';
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.validateRtcpFeedback = validateRtcpFeedback;
|
|
149
|
-
/**
|
|
150
|
-
* Validates RtpHeaderExtension. It may modify given data by adding missing
|
|
151
|
-
* fields with default values.
|
|
152
|
-
* It throws if invalid.
|
|
153
|
-
*/
|
|
154
|
-
function validateRtpHeaderExtension(ext) {
|
|
155
|
-
if (typeof ext !== 'object') {
|
|
156
|
-
throw new TypeError('ext is not an object');
|
|
157
|
-
}
|
|
158
|
-
// kind is mandatory.
|
|
159
|
-
if (ext.kind !== 'audio' && ext.kind !== 'video') {
|
|
160
|
-
throw new TypeError('invalid ext.kind');
|
|
161
|
-
}
|
|
162
|
-
// uri is mandatory.
|
|
163
|
-
if (!ext.uri || typeof ext.uri !== 'string') {
|
|
164
|
-
throw new TypeError('missing ext.uri');
|
|
165
|
-
}
|
|
166
|
-
// preferredId is mandatory.
|
|
167
|
-
if (typeof ext.preferredId !== 'number') {
|
|
168
|
-
throw new TypeError('missing ext.preferredId');
|
|
169
|
-
}
|
|
170
|
-
// preferredEncrypt is optional. If unset set it to false.
|
|
171
|
-
if (ext.preferredEncrypt && typeof ext.preferredEncrypt !== 'boolean') {
|
|
172
|
-
throw new TypeError('invalid ext.preferredEncrypt');
|
|
173
|
-
}
|
|
174
|
-
else if (!ext.preferredEncrypt) {
|
|
175
|
-
ext.preferredEncrypt = false;
|
|
176
|
-
}
|
|
177
|
-
// direction is optional. If unset set it to sendrecv.
|
|
178
|
-
if (ext.direction && typeof ext.direction !== 'string') {
|
|
179
|
-
throw new TypeError('invalid ext.direction');
|
|
180
|
-
}
|
|
181
|
-
else if (!ext.direction) {
|
|
182
|
-
ext.direction = 'sendrecv';
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
exports.validateRtpHeaderExtension = validateRtpHeaderExtension;
|
|
186
63
|
/**
|
|
187
64
|
* Validates RtpParameters. It may modify given data by adding missing
|
|
188
65
|
* fields with default values.
|
|
@@ -234,283 +111,75 @@ function validateRtpParameters(params) {
|
|
|
234
111
|
}
|
|
235
112
|
exports.validateRtpParameters = validateRtpParameters;
|
|
236
113
|
/**
|
|
237
|
-
* Validates
|
|
114
|
+
* Validates SctpStreamParameters. It may modify given data by adding missing
|
|
238
115
|
* fields with default values.
|
|
239
116
|
* It throws if invalid.
|
|
240
117
|
*/
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
throw new TypeError('codec is not an object');
|
|
118
|
+
function validateSctpStreamParameters(params) {
|
|
119
|
+
if (typeof params !== 'object') {
|
|
120
|
+
throw new TypeError('params is not an object');
|
|
245
121
|
}
|
|
246
|
-
//
|
|
247
|
-
if (
|
|
248
|
-
throw new TypeError('missing
|
|
122
|
+
// streamId is mandatory.
|
|
123
|
+
if (typeof params.streamId !== 'number') {
|
|
124
|
+
throw new TypeError('missing params.streamId');
|
|
249
125
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
126
|
+
// ordered is optional.
|
|
127
|
+
let orderedGiven = false;
|
|
128
|
+
if (typeof params.ordered === 'boolean') {
|
|
129
|
+
orderedGiven = true;
|
|
253
130
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
throw new TypeError('missing codec.payloadType');
|
|
131
|
+
else {
|
|
132
|
+
params.ordered = true;
|
|
257
133
|
}
|
|
258
|
-
//
|
|
259
|
-
if (
|
|
260
|
-
|
|
134
|
+
// maxPacketLifeTime is optional.
|
|
135
|
+
if (params.maxPacketLifeTime &&
|
|
136
|
+
typeof params.maxPacketLifeTime !== 'number') {
|
|
137
|
+
throw new TypeError('invalid params.maxPacketLifeTime');
|
|
261
138
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (typeof codec.channels !== 'number') {
|
|
266
|
-
codec.channels = 1;
|
|
267
|
-
}
|
|
139
|
+
// maxRetransmits is optional.
|
|
140
|
+
if (params.maxRetransmits && typeof params.maxRetransmits !== 'number') {
|
|
141
|
+
throw new TypeError('invalid params.maxRetransmits');
|
|
268
142
|
}
|
|
269
|
-
|
|
270
|
-
|
|
143
|
+
if (params.maxPacketLifeTime && params.maxRetransmits) {
|
|
144
|
+
throw new TypeError('cannot provide both maxPacketLifeTime and maxRetransmits');
|
|
271
145
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
146
|
+
if (orderedGiven &&
|
|
147
|
+
params.ordered &&
|
|
148
|
+
(params.maxPacketLifeTime || params.maxRetransmits)) {
|
|
149
|
+
throw new TypeError('cannot be ordered with maxPacketLifeTime or maxRetransmits');
|
|
275
150
|
}
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
codec.parameters[key] = '';
|
|
280
|
-
value = '';
|
|
281
|
-
}
|
|
282
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
283
|
-
throw new TypeError(`invalid codec parameter [key:${key}s, value:${value}]`);
|
|
284
|
-
}
|
|
285
|
-
// Specific parameters validation.
|
|
286
|
-
if (key === 'apt') {
|
|
287
|
-
if (typeof value !== 'number') {
|
|
288
|
-
throw new TypeError('invalid codec apt parameter');
|
|
289
|
-
}
|
|
290
|
-
}
|
|
151
|
+
else if (!orderedGiven &&
|
|
152
|
+
(params.maxPacketLifeTime || params.maxRetransmits)) {
|
|
153
|
+
params.ordered = false;
|
|
291
154
|
}
|
|
292
|
-
//
|
|
293
|
-
if (
|
|
294
|
-
|
|
155
|
+
// label is optional.
|
|
156
|
+
if (params.label && typeof params.label !== 'string') {
|
|
157
|
+
throw new TypeError('invalid params.label');
|
|
295
158
|
}
|
|
296
|
-
|
|
297
|
-
|
|
159
|
+
// protocol is optional.
|
|
160
|
+
if (params.protocol && typeof params.protocol !== 'string') {
|
|
161
|
+
throw new TypeError('invalid params.protocol');
|
|
298
162
|
}
|
|
299
163
|
}
|
|
300
|
-
exports.
|
|
164
|
+
exports.validateSctpStreamParameters = validateSctpStreamParameters;
|
|
301
165
|
/**
|
|
302
|
-
* Validates
|
|
166
|
+
* Validates SctpCapabilities. It may modify given data by adding missing
|
|
303
167
|
* fields with default values.
|
|
304
168
|
* It throws if invalid.
|
|
305
169
|
*/
|
|
306
|
-
function
|
|
307
|
-
if (typeof
|
|
308
|
-
throw new TypeError('
|
|
309
|
-
}
|
|
310
|
-
// uri is mandatory.
|
|
311
|
-
if (!ext.uri || typeof ext.uri !== 'string') {
|
|
312
|
-
throw new TypeError('missing ext.uri');
|
|
313
|
-
}
|
|
314
|
-
// id is mandatory.
|
|
315
|
-
if (typeof ext.id !== 'number') {
|
|
316
|
-
throw new TypeError('missing ext.id');
|
|
317
|
-
}
|
|
318
|
-
// encrypt is optional. If unset set it to false.
|
|
319
|
-
if (ext.encrypt && typeof ext.encrypt !== 'boolean') {
|
|
320
|
-
throw new TypeError('invalid ext.encrypt');
|
|
321
|
-
}
|
|
322
|
-
else if (!ext.encrypt) {
|
|
323
|
-
ext.encrypt = false;
|
|
324
|
-
}
|
|
325
|
-
// parameters is optional. If unset, set it to an empty object.
|
|
326
|
-
if (!ext.parameters || typeof ext.parameters !== 'object') {
|
|
327
|
-
ext.parameters = {};
|
|
170
|
+
function validateSctpCapabilities(caps) {
|
|
171
|
+
if (typeof caps !== 'object') {
|
|
172
|
+
throw new TypeError('caps is not an object');
|
|
328
173
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
ext.parameters[key] = '';
|
|
333
|
-
value = '';
|
|
334
|
-
}
|
|
335
|
-
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
336
|
-
throw new TypeError('invalid header extension parameter');
|
|
337
|
-
}
|
|
174
|
+
// numStreams is mandatory.
|
|
175
|
+
if (!caps.numStreams || typeof caps.numStreams !== 'object') {
|
|
176
|
+
throw new TypeError('missing caps.numStreams');
|
|
338
177
|
}
|
|
178
|
+
validateNumSctpStreams(caps.numStreams);
|
|
339
179
|
}
|
|
340
|
-
exports.
|
|
180
|
+
exports.validateSctpCapabilities = validateSctpCapabilities;
|
|
341
181
|
/**
|
|
342
|
-
*
|
|
343
|
-
* fields with default values.
|
|
344
|
-
* It throws if invalid.
|
|
345
|
-
*/
|
|
346
|
-
function validateRtpEncodingParameters(encoding) {
|
|
347
|
-
if (typeof encoding !== 'object') {
|
|
348
|
-
throw new TypeError('encoding is not an object');
|
|
349
|
-
}
|
|
350
|
-
// ssrc is optional.
|
|
351
|
-
if (encoding.ssrc && typeof encoding.ssrc !== 'number') {
|
|
352
|
-
throw new TypeError('invalid encoding.ssrc');
|
|
353
|
-
}
|
|
354
|
-
// rid is optional.
|
|
355
|
-
if (encoding.rid && typeof encoding.rid !== 'string') {
|
|
356
|
-
throw new TypeError('invalid encoding.rid');
|
|
357
|
-
}
|
|
358
|
-
// rtx is optional.
|
|
359
|
-
if (encoding.rtx && typeof encoding.rtx !== 'object') {
|
|
360
|
-
throw new TypeError('invalid encoding.rtx');
|
|
361
|
-
}
|
|
362
|
-
else if (encoding.rtx) {
|
|
363
|
-
// RTX ssrc is mandatory if rtx is present.
|
|
364
|
-
if (typeof encoding.rtx.ssrc !== 'number') {
|
|
365
|
-
throw new TypeError('missing encoding.rtx.ssrc');
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
// dtx is optional. If unset set it to false.
|
|
369
|
-
if (!encoding.dtx || typeof encoding.dtx !== 'boolean') {
|
|
370
|
-
encoding.dtx = false;
|
|
371
|
-
}
|
|
372
|
-
// scalabilityMode is optional.
|
|
373
|
-
if (encoding.scalabilityMode &&
|
|
374
|
-
typeof encoding.scalabilityMode !== 'string') {
|
|
375
|
-
throw new TypeError('invalid encoding.scalabilityMode');
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
exports.validateRtpEncodingParameters = validateRtpEncodingParameters;
|
|
379
|
-
/**
|
|
380
|
-
* Validates RtcpParameters. It may modify given data by adding missing
|
|
381
|
-
* fields with default values.
|
|
382
|
-
* It throws if invalid.
|
|
383
|
-
*/
|
|
384
|
-
function validateRtcpParameters(rtcp) {
|
|
385
|
-
if (typeof rtcp !== 'object') {
|
|
386
|
-
throw new TypeError('rtcp is not an object');
|
|
387
|
-
}
|
|
388
|
-
// cname is optional.
|
|
389
|
-
if (rtcp.cname && typeof rtcp.cname !== 'string') {
|
|
390
|
-
throw new TypeError('invalid rtcp.cname');
|
|
391
|
-
}
|
|
392
|
-
// reducedSize is optional. If unset set it to true.
|
|
393
|
-
if (!rtcp.reducedSize || typeof rtcp.reducedSize !== 'boolean') {
|
|
394
|
-
rtcp.reducedSize = true;
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
exports.validateRtcpParameters = validateRtcpParameters;
|
|
398
|
-
/**
|
|
399
|
-
* Validates SctpCapabilities. It may modify given data by adding missing
|
|
400
|
-
* fields with default values.
|
|
401
|
-
* It throws if invalid.
|
|
402
|
-
*/
|
|
403
|
-
function validateSctpCapabilities(caps) {
|
|
404
|
-
if (typeof caps !== 'object') {
|
|
405
|
-
throw new TypeError('caps is not an object');
|
|
406
|
-
}
|
|
407
|
-
// numStreams is mandatory.
|
|
408
|
-
if (!caps.numStreams || typeof caps.numStreams !== 'object') {
|
|
409
|
-
throw new TypeError('missing caps.numStreams');
|
|
410
|
-
}
|
|
411
|
-
validateNumSctpStreams(caps.numStreams);
|
|
412
|
-
}
|
|
413
|
-
exports.validateSctpCapabilities = validateSctpCapabilities;
|
|
414
|
-
/**
|
|
415
|
-
* Validates NumSctpStreams. It may modify given data by adding missing
|
|
416
|
-
* fields with default values.
|
|
417
|
-
* It throws if invalid.
|
|
418
|
-
*/
|
|
419
|
-
function validateNumSctpStreams(numStreams) {
|
|
420
|
-
if (typeof numStreams !== 'object') {
|
|
421
|
-
throw new TypeError('numStreams is not an object');
|
|
422
|
-
}
|
|
423
|
-
// OS is mandatory.
|
|
424
|
-
if (typeof numStreams.OS !== 'number') {
|
|
425
|
-
throw new TypeError('missing numStreams.OS');
|
|
426
|
-
}
|
|
427
|
-
// MIS is mandatory.
|
|
428
|
-
if (typeof numStreams.MIS !== 'number') {
|
|
429
|
-
throw new TypeError('missing numStreams.MIS');
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
exports.validateNumSctpStreams = validateNumSctpStreams;
|
|
433
|
-
/**
|
|
434
|
-
* Validates SctpParameters. It may modify given data by adding missing
|
|
435
|
-
* fields with default values.
|
|
436
|
-
* It throws if invalid.
|
|
437
|
-
*/
|
|
438
|
-
function validateSctpParameters(params) {
|
|
439
|
-
if (typeof params !== 'object') {
|
|
440
|
-
throw new TypeError('params is not an object');
|
|
441
|
-
}
|
|
442
|
-
// port is mandatory.
|
|
443
|
-
if (typeof params.port !== 'number') {
|
|
444
|
-
throw new TypeError('missing params.port');
|
|
445
|
-
}
|
|
446
|
-
// OS is mandatory.
|
|
447
|
-
if (typeof params.OS !== 'number') {
|
|
448
|
-
throw new TypeError('missing params.OS');
|
|
449
|
-
}
|
|
450
|
-
// MIS is mandatory.
|
|
451
|
-
if (typeof params.MIS !== 'number') {
|
|
452
|
-
throw new TypeError('missing params.MIS');
|
|
453
|
-
}
|
|
454
|
-
// maxMessageSize is mandatory.
|
|
455
|
-
if (typeof params.maxMessageSize !== 'number') {
|
|
456
|
-
throw new TypeError('missing params.maxMessageSize');
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
exports.validateSctpParameters = validateSctpParameters;
|
|
460
|
-
/**
|
|
461
|
-
* Validates SctpStreamParameters. It may modify given data by adding missing
|
|
462
|
-
* fields with default values.
|
|
463
|
-
* It throws if invalid.
|
|
464
|
-
*/
|
|
465
|
-
function validateSctpStreamParameters(params) {
|
|
466
|
-
if (typeof params !== 'object') {
|
|
467
|
-
throw new TypeError('params is not an object');
|
|
468
|
-
}
|
|
469
|
-
// streamId is mandatory.
|
|
470
|
-
if (typeof params.streamId !== 'number') {
|
|
471
|
-
throw new TypeError('missing params.streamId');
|
|
472
|
-
}
|
|
473
|
-
// ordered is optional.
|
|
474
|
-
let orderedGiven = false;
|
|
475
|
-
if (typeof params.ordered === 'boolean') {
|
|
476
|
-
orderedGiven = true;
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
params.ordered = true;
|
|
480
|
-
}
|
|
481
|
-
// maxPacketLifeTime is optional.
|
|
482
|
-
if (params.maxPacketLifeTime &&
|
|
483
|
-
typeof params.maxPacketLifeTime !== 'number') {
|
|
484
|
-
throw new TypeError('invalid params.maxPacketLifeTime');
|
|
485
|
-
}
|
|
486
|
-
// maxRetransmits is optional.
|
|
487
|
-
if (params.maxRetransmits && typeof params.maxRetransmits !== 'number') {
|
|
488
|
-
throw new TypeError('invalid params.maxRetransmits');
|
|
489
|
-
}
|
|
490
|
-
if (params.maxPacketLifeTime && params.maxRetransmits) {
|
|
491
|
-
throw new TypeError('cannot provide both maxPacketLifeTime and maxRetransmits');
|
|
492
|
-
}
|
|
493
|
-
if (orderedGiven &&
|
|
494
|
-
params.ordered &&
|
|
495
|
-
(params.maxPacketLifeTime || params.maxRetransmits)) {
|
|
496
|
-
throw new TypeError('cannot be ordered with maxPacketLifeTime or maxRetransmits');
|
|
497
|
-
}
|
|
498
|
-
else if (!orderedGiven &&
|
|
499
|
-
(params.maxPacketLifeTime || params.maxRetransmits)) {
|
|
500
|
-
params.ordered = false;
|
|
501
|
-
}
|
|
502
|
-
// label is optional.
|
|
503
|
-
if (params.label && typeof params.label !== 'string') {
|
|
504
|
-
throw new TypeError('invalid params.label');
|
|
505
|
-
}
|
|
506
|
-
// protocol is optional.
|
|
507
|
-
if (params.protocol && typeof params.protocol !== 'string') {
|
|
508
|
-
throw new TypeError('invalid params.protocol');
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
exports.validateSctpStreamParameters = validateSctpStreamParameters;
|
|
512
|
-
/**
|
|
513
|
-
* Generate extended RTP capabilities for sending and receiving.
|
|
182
|
+
* Generate extended RTP capabilities for sending and receiving.
|
|
514
183
|
*/
|
|
515
184
|
function getExtendedRtpCapabilities(localCaps, remoteCaps) {
|
|
516
185
|
const extendedRtpCapabilities = {
|
|
@@ -763,8 +432,7 @@ function getSendingRemoteRtpParameters(kind, extendedRtpCapabilities) {
|
|
|
763
432
|
codec.rtcpFeedback = (codec.rtcpFeedback || []).filter((fb) => fb.type !== 'goog-remb');
|
|
764
433
|
}
|
|
765
434
|
}
|
|
766
|
-
else if (rtpParameters.headerExtensions.some(ext => ext.uri ===
|
|
767
|
-
'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time')) {
|
|
435
|
+
else if (rtpParameters.headerExtensions.some(ext => ext.uri === 'http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time')) {
|
|
768
436
|
for (const codec of rtpParameters.codecs) {
|
|
769
437
|
codec.rtcpFeedback = (codec.rtcpFeedback || []).filter(fb => fb.type !== 'transport-cc');
|
|
770
438
|
}
|
|
@@ -856,6 +524,302 @@ function canReceive(rtpParameters, extendedRtpCapabilities) {
|
|
|
856
524
|
return extendedRtpCapabilities.codecs.some((codec) => codec.remotePayloadType === firstMediaCodec.payloadType);
|
|
857
525
|
}
|
|
858
526
|
exports.canReceive = canReceive;
|
|
527
|
+
/**
|
|
528
|
+
* Validates RtpCodecCapability. It may modify given data by adding missing
|
|
529
|
+
* fields with default values.
|
|
530
|
+
* It throws if invalid.
|
|
531
|
+
*/
|
|
532
|
+
function validateRtpCodecCapability(codec) {
|
|
533
|
+
const MimeTypeRegex = new RegExp('^(audio|video)/(.+)', 'i');
|
|
534
|
+
if (typeof codec !== 'object') {
|
|
535
|
+
throw new TypeError('codec is not an object');
|
|
536
|
+
}
|
|
537
|
+
// mimeType is mandatory.
|
|
538
|
+
if (!codec.mimeType || typeof codec.mimeType !== 'string') {
|
|
539
|
+
throw new TypeError('missing codec.mimeType');
|
|
540
|
+
}
|
|
541
|
+
const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
|
|
542
|
+
if (!mimeTypeMatch) {
|
|
543
|
+
throw new TypeError('invalid codec.mimeType');
|
|
544
|
+
}
|
|
545
|
+
// Just override kind with media component of mimeType.
|
|
546
|
+
codec.kind = mimeTypeMatch[1].toLowerCase();
|
|
547
|
+
// preferredPayloadType is optional.
|
|
548
|
+
if (codec.preferredPayloadType &&
|
|
549
|
+
typeof codec.preferredPayloadType !== 'number') {
|
|
550
|
+
throw new TypeError('invalid codec.preferredPayloadType');
|
|
551
|
+
}
|
|
552
|
+
// clockRate is mandatory.
|
|
553
|
+
if (typeof codec.clockRate !== 'number') {
|
|
554
|
+
throw new TypeError('missing codec.clockRate');
|
|
555
|
+
}
|
|
556
|
+
// channels is optional. If unset, set it to 1 (just if audio).
|
|
557
|
+
if (codec.kind === 'audio') {
|
|
558
|
+
if (typeof codec.channels !== 'number') {
|
|
559
|
+
codec.channels = 1;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
delete codec.channels;
|
|
564
|
+
}
|
|
565
|
+
// parameters is optional. If unset, set it to an empty object.
|
|
566
|
+
if (!codec.parameters || typeof codec.parameters !== 'object') {
|
|
567
|
+
codec.parameters = {};
|
|
568
|
+
}
|
|
569
|
+
for (const key of Object.keys(codec.parameters)) {
|
|
570
|
+
let value = codec.parameters[key];
|
|
571
|
+
if (value === undefined) {
|
|
572
|
+
codec.parameters[key] = '';
|
|
573
|
+
value = '';
|
|
574
|
+
}
|
|
575
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
576
|
+
throw new TypeError(`invalid codec parameter [key:${key}s, value:${value}]`);
|
|
577
|
+
}
|
|
578
|
+
// Specific parameters validation.
|
|
579
|
+
if (key === 'apt') {
|
|
580
|
+
if (typeof value !== 'number') {
|
|
581
|
+
throw new TypeError('invalid codec apt parameter');
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
// rtcpFeedback is optional. If unset, set it to an empty array.
|
|
586
|
+
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback)) {
|
|
587
|
+
codec.rtcpFeedback = [];
|
|
588
|
+
}
|
|
589
|
+
for (const fb of codec.rtcpFeedback) {
|
|
590
|
+
validateRtcpFeedback(fb);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Validates RtcpFeedback. It may modify given data by adding missing
|
|
595
|
+
* fields with default values.
|
|
596
|
+
* It throws if invalid.
|
|
597
|
+
*/
|
|
598
|
+
function validateRtcpFeedback(fb) {
|
|
599
|
+
if (typeof fb !== 'object') {
|
|
600
|
+
throw new TypeError('fb is not an object');
|
|
601
|
+
}
|
|
602
|
+
// type is mandatory.
|
|
603
|
+
if (!fb.type || typeof fb.type !== 'string') {
|
|
604
|
+
throw new TypeError('missing fb.type');
|
|
605
|
+
}
|
|
606
|
+
// parameter is optional. If unset set it to an empty string.
|
|
607
|
+
if (!fb.parameter || typeof fb.parameter !== 'string') {
|
|
608
|
+
fb.parameter = '';
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Validates RtpHeaderExtension. It may modify given data by adding missing
|
|
613
|
+
* fields with default values.
|
|
614
|
+
* It throws if invalid.
|
|
615
|
+
*/
|
|
616
|
+
function validateRtpHeaderExtension(ext) {
|
|
617
|
+
if (typeof ext !== 'object') {
|
|
618
|
+
throw new TypeError('ext is not an object');
|
|
619
|
+
}
|
|
620
|
+
// kind is mandatory.
|
|
621
|
+
if (ext.kind !== 'audio' && ext.kind !== 'video') {
|
|
622
|
+
throw new TypeError('invalid ext.kind');
|
|
623
|
+
}
|
|
624
|
+
// uri is mandatory.
|
|
625
|
+
if (!ext.uri || typeof ext.uri !== 'string') {
|
|
626
|
+
throw new TypeError('missing ext.uri');
|
|
627
|
+
}
|
|
628
|
+
// preferredId is mandatory.
|
|
629
|
+
if (typeof ext.preferredId !== 'number') {
|
|
630
|
+
throw new TypeError('missing ext.preferredId');
|
|
631
|
+
}
|
|
632
|
+
// preferredEncrypt is optional. If unset set it to false.
|
|
633
|
+
if (ext.preferredEncrypt && typeof ext.preferredEncrypt !== 'boolean') {
|
|
634
|
+
throw new TypeError('invalid ext.preferredEncrypt');
|
|
635
|
+
}
|
|
636
|
+
else if (!ext.preferredEncrypt) {
|
|
637
|
+
ext.preferredEncrypt = false;
|
|
638
|
+
}
|
|
639
|
+
// direction is optional. If unset set it to sendrecv.
|
|
640
|
+
if (ext.direction && typeof ext.direction !== 'string') {
|
|
641
|
+
throw new TypeError('invalid ext.direction');
|
|
642
|
+
}
|
|
643
|
+
else if (!ext.direction) {
|
|
644
|
+
ext.direction = 'sendrecv';
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Validates RtpCodecParameters. It may modify given data by adding missing
|
|
649
|
+
* fields with default values.
|
|
650
|
+
* It throws if invalid.
|
|
651
|
+
*/
|
|
652
|
+
function validateRtpCodecParameters(codec) {
|
|
653
|
+
const MimeTypeRegex = new RegExp('^(audio|video)/(.+)', 'i');
|
|
654
|
+
if (typeof codec !== 'object') {
|
|
655
|
+
throw new TypeError('codec is not an object');
|
|
656
|
+
}
|
|
657
|
+
// mimeType is mandatory.
|
|
658
|
+
if (!codec.mimeType || typeof codec.mimeType !== 'string') {
|
|
659
|
+
throw new TypeError('missing codec.mimeType');
|
|
660
|
+
}
|
|
661
|
+
const mimeTypeMatch = MimeTypeRegex.exec(codec.mimeType);
|
|
662
|
+
if (!mimeTypeMatch) {
|
|
663
|
+
throw new TypeError('invalid codec.mimeType');
|
|
664
|
+
}
|
|
665
|
+
// payloadType is mandatory.
|
|
666
|
+
if (typeof codec.payloadType !== 'number') {
|
|
667
|
+
throw new TypeError('missing codec.payloadType');
|
|
668
|
+
}
|
|
669
|
+
// clockRate is mandatory.
|
|
670
|
+
if (typeof codec.clockRate !== 'number') {
|
|
671
|
+
throw new TypeError('missing codec.clockRate');
|
|
672
|
+
}
|
|
673
|
+
const kind = mimeTypeMatch[1].toLowerCase();
|
|
674
|
+
// channels is optional. If unset, set it to 1 (just if audio).
|
|
675
|
+
if (kind === 'audio') {
|
|
676
|
+
if (typeof codec.channels !== 'number') {
|
|
677
|
+
codec.channels = 1;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
delete codec.channels;
|
|
682
|
+
}
|
|
683
|
+
// parameters is optional. If unset, set it to an empty object.
|
|
684
|
+
if (!codec.parameters || typeof codec.parameters !== 'object') {
|
|
685
|
+
codec.parameters = {};
|
|
686
|
+
}
|
|
687
|
+
for (const key of Object.keys(codec.parameters)) {
|
|
688
|
+
let value = codec.parameters[key];
|
|
689
|
+
if (value === undefined) {
|
|
690
|
+
codec.parameters[key] = '';
|
|
691
|
+
value = '';
|
|
692
|
+
}
|
|
693
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
694
|
+
throw new TypeError(`invalid codec parameter [key:${key}s, value:${value}]`);
|
|
695
|
+
}
|
|
696
|
+
// Specific parameters validation.
|
|
697
|
+
if (key === 'apt') {
|
|
698
|
+
if (typeof value !== 'number') {
|
|
699
|
+
throw new TypeError('invalid codec apt parameter');
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
// rtcpFeedback is optional. If unset, set it to an empty array.
|
|
704
|
+
if (!codec.rtcpFeedback || !Array.isArray(codec.rtcpFeedback)) {
|
|
705
|
+
codec.rtcpFeedback = [];
|
|
706
|
+
}
|
|
707
|
+
for (const fb of codec.rtcpFeedback) {
|
|
708
|
+
validateRtcpFeedback(fb);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
/**
|
|
712
|
+
* Validates RtpHeaderExtensionParameteters. It may modify given data by adding missing
|
|
713
|
+
* fields with default values.
|
|
714
|
+
* It throws if invalid.
|
|
715
|
+
*/
|
|
716
|
+
function validateRtpHeaderExtensionParameters(ext) {
|
|
717
|
+
if (typeof ext !== 'object') {
|
|
718
|
+
throw new TypeError('ext is not an object');
|
|
719
|
+
}
|
|
720
|
+
// uri is mandatory.
|
|
721
|
+
if (!ext.uri || typeof ext.uri !== 'string') {
|
|
722
|
+
throw new TypeError('missing ext.uri');
|
|
723
|
+
}
|
|
724
|
+
// id is mandatory.
|
|
725
|
+
if (typeof ext.id !== 'number') {
|
|
726
|
+
throw new TypeError('missing ext.id');
|
|
727
|
+
}
|
|
728
|
+
// encrypt is optional. If unset set it to false.
|
|
729
|
+
if (ext.encrypt && typeof ext.encrypt !== 'boolean') {
|
|
730
|
+
throw new TypeError('invalid ext.encrypt');
|
|
731
|
+
}
|
|
732
|
+
else if (!ext.encrypt) {
|
|
733
|
+
ext.encrypt = false;
|
|
734
|
+
}
|
|
735
|
+
// parameters is optional. If unset, set it to an empty object.
|
|
736
|
+
if (!ext.parameters || typeof ext.parameters !== 'object') {
|
|
737
|
+
ext.parameters = {};
|
|
738
|
+
}
|
|
739
|
+
for (const key of Object.keys(ext.parameters)) {
|
|
740
|
+
let value = ext.parameters[key];
|
|
741
|
+
if (value === undefined) {
|
|
742
|
+
ext.parameters[key] = '';
|
|
743
|
+
value = '';
|
|
744
|
+
}
|
|
745
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
746
|
+
throw new TypeError('invalid header extension parameter');
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Validates RtpEncodingParameters. It may modify given data by adding missing
|
|
752
|
+
* fields with default values.
|
|
753
|
+
* It throws if invalid.
|
|
754
|
+
*/
|
|
755
|
+
function validateRtpEncodingParameters(encoding) {
|
|
756
|
+
if (typeof encoding !== 'object') {
|
|
757
|
+
throw new TypeError('encoding is not an object');
|
|
758
|
+
}
|
|
759
|
+
// ssrc is optional.
|
|
760
|
+
if (encoding.ssrc && typeof encoding.ssrc !== 'number') {
|
|
761
|
+
throw new TypeError('invalid encoding.ssrc');
|
|
762
|
+
}
|
|
763
|
+
// rid is optional.
|
|
764
|
+
if (encoding.rid && typeof encoding.rid !== 'string') {
|
|
765
|
+
throw new TypeError('invalid encoding.rid');
|
|
766
|
+
}
|
|
767
|
+
// rtx is optional.
|
|
768
|
+
if (encoding.rtx && typeof encoding.rtx !== 'object') {
|
|
769
|
+
throw new TypeError('invalid encoding.rtx');
|
|
770
|
+
}
|
|
771
|
+
else if (encoding.rtx) {
|
|
772
|
+
// RTX ssrc is mandatory if rtx is present.
|
|
773
|
+
if (typeof encoding.rtx.ssrc !== 'number') {
|
|
774
|
+
throw new TypeError('missing encoding.rtx.ssrc');
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// dtx is optional. If unset set it to false.
|
|
778
|
+
if (!encoding.dtx || typeof encoding.dtx !== 'boolean') {
|
|
779
|
+
encoding.dtx = false;
|
|
780
|
+
}
|
|
781
|
+
// scalabilityMode is optional.
|
|
782
|
+
if (encoding.scalabilityMode &&
|
|
783
|
+
typeof encoding.scalabilityMode !== 'string') {
|
|
784
|
+
throw new TypeError('invalid encoding.scalabilityMode');
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Validates RtcpParameters. It may modify given data by adding missing
|
|
789
|
+
* fields with default values.
|
|
790
|
+
* It throws if invalid.
|
|
791
|
+
*/
|
|
792
|
+
function validateRtcpParameters(rtcp) {
|
|
793
|
+
if (typeof rtcp !== 'object') {
|
|
794
|
+
throw new TypeError('rtcp is not an object');
|
|
795
|
+
}
|
|
796
|
+
// cname is optional.
|
|
797
|
+
if (rtcp.cname && typeof rtcp.cname !== 'string') {
|
|
798
|
+
throw new TypeError('invalid rtcp.cname');
|
|
799
|
+
}
|
|
800
|
+
// reducedSize is optional. If unset set it to true.
|
|
801
|
+
if (!rtcp.reducedSize || typeof rtcp.reducedSize !== 'boolean') {
|
|
802
|
+
rtcp.reducedSize = true;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Validates NumSctpStreams. It may modify given data by adding missing
|
|
807
|
+
* fields with default values.
|
|
808
|
+
* It throws if invalid.
|
|
809
|
+
*/
|
|
810
|
+
function validateNumSctpStreams(numStreams) {
|
|
811
|
+
if (typeof numStreams !== 'object') {
|
|
812
|
+
throw new TypeError('numStreams is not an object');
|
|
813
|
+
}
|
|
814
|
+
// OS is mandatory.
|
|
815
|
+
if (typeof numStreams.OS !== 'number') {
|
|
816
|
+
throw new TypeError('missing numStreams.OS');
|
|
817
|
+
}
|
|
818
|
+
// MIS is mandatory.
|
|
819
|
+
if (typeof numStreams.MIS !== 'number') {
|
|
820
|
+
throw new TypeError('missing numStreams.MIS');
|
|
821
|
+
}
|
|
822
|
+
}
|
|
859
823
|
function isRtxCodec(codec) {
|
|
860
824
|
if (!codec) {
|
|
861
825
|
return false;
|