@webex/web-client-media-engine 3.2.0 → 3.3.1

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/dist/cjs/index.js CHANGED
@@ -486,6 +486,175 @@ var media = /*#__PURE__*/Object.freeze({
486
486
  ensureDevicePermissions: ensureDevicePermissions
487
487
  });
488
488
 
489
+ var ErrorTypes;
490
+ (function (ErrorTypes) {
491
+ ErrorTypes["DEVICE_PERMISSION_DENIED"] = "DEVICE_PERMISSION_DENIED";
492
+ ErrorTypes["CREATE_STREAM_FAILED"] = "CREATE_CAMERA_STREAM";
493
+ })(ErrorTypes || (ErrorTypes = {}));
494
+ /**
495
+ * Represents a WCME error, which contains error type and error message.
496
+ */
497
+ class WcmeError {
498
+ /**
499
+ * Creates new error.
500
+ *
501
+ * @param type - Error type.
502
+ * @param message - Error message.
503
+ */
504
+ constructor(type, message = '') {
505
+ this.type = type;
506
+ this.message = message;
507
+ }
508
+ }
509
+ /**
510
+ * Creates a camera stream. Please note that the constraint params in second getUserMedia call would NOT take effect when:
511
+ *
512
+ * 1. Previous captured video stream from the same device is not stopped.
513
+ * 2. Previous createCameraStream() call for the same device is in progress.
514
+ *
515
+ * @param constructor - Constructor for the local camera stream.
516
+ * @param constraints - Video device constraints.
517
+ * @returns A LocalCameraStream object or an error.
518
+ */
519
+ function createCameraStream(constructor, constraints) {
520
+ return __awaiter$1(this, void 0, void 0, function* () {
521
+ let stream;
522
+ try {
523
+ stream = yield getUserMedia({ video: Object.assign({}, constraints) });
524
+ }
525
+ catch (error) {
526
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create camera stream: ${error}`);
527
+ }
528
+ return new constructor(stream);
529
+ });
530
+ }
531
+ /**
532
+ * Creates a LocalMicrophoneStream with the given constraints.
533
+ *
534
+ * @param constructor - Constructor for the local microphone stream.
535
+ * @param constraints - Audio device constraints.
536
+ * @returns A LocalMicrophoneStream object or an error.
537
+ */
538
+ function createMicrophoneStream(constructor, constraints) {
539
+ return __awaiter$1(this, void 0, void 0, function* () {
540
+ let stream;
541
+ try {
542
+ stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
543
+ }
544
+ catch (error) {
545
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create microphone stream: ${error}`);
546
+ }
547
+ return new constructor(stream);
548
+ });
549
+ }
550
+ /**
551
+ * Creates a LocalDisplayStream with the given parameters.
552
+ *
553
+ * @param constructor - Constructor for the local display stream.
554
+ * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
555
+ * @returns A Promise that resolves to a LocalDisplayStream or an error.
556
+ */
557
+ function createDisplayStream(constructor, videoContentHint) {
558
+ return __awaiter$1(this, void 0, void 0, function* () {
559
+ let stream;
560
+ try {
561
+ stream = yield getDisplayMedia({ video: true });
562
+ }
563
+ catch (error) {
564
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create display stream: ${error}`);
565
+ }
566
+ const localDisplayStream = new constructor(stream);
567
+ if (videoContentHint) {
568
+ localDisplayStream.contentHint = videoContentHint;
569
+ }
570
+ return localDisplayStream;
571
+ });
572
+ }
573
+ /**
574
+ * Creates a LocalDisplayStream and a LocalSystemAudioStream with the given parameters.
575
+ *
576
+ * @param displayStreamConstructor - Constructor for the local display stream.
577
+ * @param systemAudioStreamConstructor - Constructor for the local system audio stream.
578
+ * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
579
+ * @returns A Promise that resolves to a LocalDisplayStream and a LocalSystemAudioStream or an
580
+ * error. If no system audio is available, the LocalSystemAudioStream will be resolved as null
581
+ * instead.
582
+ */
583
+ function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStreamConstructor, videoContentHint) {
584
+ return __awaiter$1(this, void 0, void 0, function* () {
585
+ let stream;
586
+ try {
587
+ stream = yield getDisplayMedia({ video: true, audio: true });
588
+ }
589
+ catch (error) {
590
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create display and system audio streams: ${error}`);
591
+ }
592
+ // eslint-disable-next-line new-cap
593
+ const localDisplayStream = new displayStreamConstructor(new MediaStream(stream.getVideoTracks()));
594
+ if (videoContentHint) {
595
+ localDisplayStream.contentHint = videoContentHint;
596
+ }
597
+ let localSystemAudioStream = null;
598
+ if (stream.getAudioTracks().length > 0) {
599
+ // eslint-disable-next-line new-cap
600
+ localSystemAudioStream = new systemAudioStreamConstructor(new MediaStream(stream.getAudioTracks()));
601
+ }
602
+ return [localDisplayStream, localSystemAudioStream];
603
+ });
604
+ }
605
+ /**
606
+ * Enumerates the media input and output devices available.
607
+ *
608
+ * @param deviceKind - Optional filter to return a specific device kind.
609
+ * @returns List of media devices in an array of MediaDeviceInfo objects.
610
+ */
611
+ function getDevices(deviceKind) {
612
+ return __awaiter$1(this, void 0, void 0, function* () {
613
+ let devices;
614
+ try {
615
+ devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
616
+ }
617
+ catch (error) {
618
+ throw new WcmeError(ErrorTypes.DEVICE_PERMISSION_DENIED, 'Failed to ensure device permissions');
619
+ }
620
+ return devices.filter((v) => (deviceKind ? v.kind === deviceKind : true));
621
+ });
622
+ }
623
+ /**
624
+ * Helper function to get a list of microphone devices.
625
+ *
626
+ * @returns List of microphone devices in an array of MediaDeviceInfo objects.
627
+ */
628
+ function getAudioInputDevices() {
629
+ return __awaiter$1(this, void 0, void 0, function* () {
630
+ return getDevices(DeviceKind.AudioInput);
631
+ });
632
+ }
633
+ /**
634
+ * Helper function to get a list of speaker devices.
635
+ *
636
+ * @returns List of speaker devices in an array of MediaDeviceInfo objects.
637
+ */
638
+ function getAudioOutputDevices() {
639
+ return __awaiter$1(this, void 0, void 0, function* () {
640
+ return getDevices(DeviceKind.AudioOutput);
641
+ });
642
+ }
643
+ /**
644
+ * Helper function to get a list of camera devices.
645
+ *
646
+ * @returns List of camera devices in an array of MediaDeviceInfo objects.
647
+ */
648
+ function getVideoInputDevices() {
649
+ return __awaiter$1(this, void 0, void 0, function* () {
650
+ return getDevices(DeviceKind.VideoInput);
651
+ });
652
+ }
653
+ /**
654
+ * Export the setOnDeviceChangeHandler method directly from the core lib.
655
+ */
656
+ const { setOnDeviceChangeHandler } = media;
657
+
489
658
  var events$1$1 = {exports: {}};
490
659
 
491
660
  var R$1$1 = typeof Reflect === 'object' ? Reflect : null;
@@ -1235,6 +1404,26 @@ class _LocalStream extends Stream {
1235
1404
  _a$6 = exports.LocalStreamEventNames.ConstraintsChange, _b = exports.LocalStreamEventNames.OutputTrackChange;
1236
1405
  const LocalStream = AddEvents(_LocalStream);
1237
1406
 
1407
+ /**
1408
+ * An audio LocalStream.
1409
+ */
1410
+ class LocalAudioStream extends LocalStream {
1411
+ /**
1412
+ * Apply constraints to the stream.
1413
+ *
1414
+ * @param constraints - The constraints to apply.
1415
+ * @returns A promise which resolves when the constraints have been successfully applied.
1416
+ */
1417
+ applyConstraints(constraints) {
1418
+ return __awaiter$1(this, void 0, void 0, function* () {
1419
+ logger$3.log(`Applying constraints to local track:`, constraints);
1420
+ return this.inputTrack.applyConstraints(constraints).then(() => {
1421
+ this[exports.LocalStreamEventNames.ConstraintsChange].emit();
1422
+ });
1423
+ });
1424
+ }
1425
+ }
1426
+
1238
1427
  /**
1239
1428
  * A video LocalStream.
1240
1429
  */
@@ -1302,26 +1491,6 @@ class LocalCameraStream extends LocalVideoStream {
1302
1491
  class LocalDisplayStream extends LocalVideoStream {
1303
1492
  }
1304
1493
 
1305
- /**
1306
- * An audio LocalStream.
1307
- */
1308
- class LocalAudioStream extends LocalStream {
1309
- /**
1310
- * Apply constraints to the stream.
1311
- *
1312
- * @param constraints - The constraints to apply.
1313
- * @returns A promise which resolves when the constraints have been successfully applied.
1314
- */
1315
- applyConstraints(constraints) {
1316
- return __awaiter$1(this, void 0, void 0, function* () {
1317
- logger$3.log(`Applying constraints to local track:`, constraints);
1318
- return this.inputTrack.applyConstraints(constraints).then(() => {
1319
- this[exports.LocalStreamEventNames.ConstraintsChange].emit();
1320
- });
1321
- });
1322
- }
1323
- }
1324
-
1325
1494
  /**
1326
1495
  * A local microphone stream.
1327
1496
  */
@@ -1334,156 +1503,6 @@ class LocalMicrophoneStream extends LocalAudioStream {
1334
1503
  class LocalSystemAudioStream extends LocalAudioStream {
1335
1504
  }
1336
1505
 
1337
- var ErrorTypes;
1338
- (function (ErrorTypes) {
1339
- ErrorTypes["DEVICE_PERMISSION_DENIED"] = "DEVICE_PERMISSION_DENIED";
1340
- ErrorTypes["CREATE_CAMERA_STREAM_FAILED"] = "CREATE_CAMERA_STREAM_FAILED";
1341
- ErrorTypes["CREATE_MICROPHONE_STREAM_FAILED"] = "CREATE_MICROPHONE_STREAM_FAILED";
1342
- })(ErrorTypes || (ErrorTypes = {}));
1343
- /**
1344
- * Represents a WCME error, which contains error type and error message.
1345
- */
1346
- class WcmeError {
1347
- /**
1348
- * Creates new error.
1349
- *
1350
- * @param type - Error type.
1351
- * @param message - Error message.
1352
- */
1353
- constructor(type, message = '') {
1354
- this.type = type;
1355
- this.message = message;
1356
- }
1357
- }
1358
- /**
1359
- * Creates a camera stream. Please note that the constraint params in second getUserMedia call would NOT take effect when:
1360
- *
1361
- * 1. Previous captured video stream from the same device is not stopped.
1362
- * 2. Previous createCameraStream() call for the same device is in progress.
1363
- *
1364
- * @param constraints - Video device constraints.
1365
- * @returns A LocalCameraStream object or an error.
1366
- */
1367
- function createCameraStream(constraints) {
1368
- return __awaiter$1(this, void 0, void 0, function* () {
1369
- let stream;
1370
- try {
1371
- stream = yield getUserMedia({ video: Object.assign({}, constraints) });
1372
- }
1373
- catch (error) {
1374
- throw new WcmeError(ErrorTypes.CREATE_CAMERA_STREAM_FAILED, `Failed to create camera stream ${error}`);
1375
- }
1376
- return new LocalCameraStream(stream);
1377
- });
1378
- }
1379
- /**
1380
- * Creates a LocalMicrophoneStream with the given constraints.
1381
- *
1382
- * @param constraints - Audio device constraints.
1383
- * @returns A LocalMicrophoneStream object or an error.
1384
- */
1385
- function createMicrophoneStream(constraints) {
1386
- return __awaiter$1(this, void 0, void 0, function* () {
1387
- let stream;
1388
- try {
1389
- stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
1390
- }
1391
- catch (error) {
1392
- throw new WcmeError(ErrorTypes.CREATE_MICROPHONE_STREAM_FAILED, `Failed to create microphone stream ${error}`);
1393
- }
1394
- return new LocalMicrophoneStream(stream);
1395
- });
1396
- }
1397
- /**
1398
- * Creates a LocalDisplayStream with the given parameters.
1399
- *
1400
- * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
1401
- * @returns A Promise that resolves to a LocalDisplayStream.
1402
- */
1403
- function createDisplayStream(videoContentHint) {
1404
- return __awaiter$1(this, void 0, void 0, function* () {
1405
- const stream = yield getDisplayMedia({ video: true });
1406
- const localDisplayStream = new LocalDisplayStream(stream);
1407
- if (videoContentHint) {
1408
- localDisplayStream.contentHint = videoContentHint;
1409
- }
1410
- return localDisplayStream;
1411
- });
1412
- }
1413
- /**
1414
- * Creates a LocalDisplayStream and a LocalSystemAudioStream with the given parameters.
1415
- *
1416
- * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
1417
- * @returns A Promise that resolves to a LocalDisplayStream and a LocalSystemAudioStream. If no system
1418
- * audio is available, the LocalSystemAudioStream will be resolved as null instead.
1419
- */
1420
- function createDisplayStreamWithAudio(videoContentHint) {
1421
- return __awaiter$1(this, void 0, void 0, function* () {
1422
- const stream = yield getDisplayMedia({ video: true, audio: true });
1423
- const localDisplayStream = new LocalDisplayStream(new MediaStream(stream.getVideoTracks()));
1424
- if (videoContentHint) {
1425
- localDisplayStream.contentHint = videoContentHint;
1426
- }
1427
- let localSystemAudioStream = null;
1428
- if (stream.getAudioTracks().length > 0) {
1429
- localSystemAudioStream = new LocalSystemAudioStream(new MediaStream(stream.getAudioTracks()));
1430
- }
1431
- return [localDisplayStream, localSystemAudioStream];
1432
- });
1433
- }
1434
- /**
1435
- * Enumerates the media input and output devices available.
1436
- *
1437
- * @param deviceKind - Optional filter to return a specific device kind.
1438
- * @returns List of media devices in an array of MediaDeviceInfo objects.
1439
- */
1440
- function getDevices(deviceKind) {
1441
- return __awaiter$1(this, void 0, void 0, function* () {
1442
- let devices;
1443
- try {
1444
- devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
1445
- }
1446
- catch (error) {
1447
- throw new WcmeError(ErrorTypes.DEVICE_PERMISSION_DENIED, 'Failed to ensure device permissions');
1448
- }
1449
- return devices.filter((v) => (deviceKind ? v.kind === deviceKind : true));
1450
- });
1451
- }
1452
- /**
1453
- * Helper function to get a list of microphone devices.
1454
- *
1455
- * @returns List of microphone devices in an array of MediaDeviceInfo objects.
1456
- */
1457
- function getAudioInputDevices() {
1458
- return __awaiter$1(this, void 0, void 0, function* () {
1459
- return getDevices(DeviceKind.AudioInput);
1460
- });
1461
- }
1462
- /**
1463
- * Helper function to get a list of speaker devices.
1464
- *
1465
- * @returns List of speaker devices in an array of MediaDeviceInfo objects.
1466
- */
1467
- function getAudioOutputDevices() {
1468
- return __awaiter$1(this, void 0, void 0, function* () {
1469
- return getDevices(DeviceKind.AudioOutput);
1470
- });
1471
- }
1472
- /**
1473
- * Helper function to get a list of camera devices.
1474
- *
1475
- * @returns List of camera devices in an array of MediaDeviceInfo objects.
1476
- */
1477
- function getVideoInputDevices() {
1478
- return __awaiter$1(this, void 0, void 0, function* () {
1479
- return getDevices(DeviceKind.VideoInput);
1480
- });
1481
- }
1482
- /**
1483
- * Export the setOnDeviceChangeHandler method directly from the core lib.
1484
- */
1485
- const { setOnDeviceChangeHandler } = media;
1486
-
1487
1506
  /**
1488
1507
  * A stream originating from a remote peer.
1489
1508
  */
@@ -9127,9 +9146,17 @@ function filterCodecs(parsedSdp, allowedCodecs) {
9127
9146
  }
9128
9147
  function filterCandidates(parsedSdp) {
9129
9148
  const supportedTransportTypes = ['udp', 'tcp'];
9149
+ let filtered = false;
9130
9150
  parsedSdp.media.forEach((mline) => {
9131
- mline.iceInfo.candidates = mline.iceInfo.candidates.filter((candidate) => supportedTransportTypes.includes(candidate.transport.toLowerCase()));
9151
+ mline.iceInfo.candidates = mline.iceInfo.candidates.filter((candidate) => {
9152
+ if (supportedTransportTypes.includes(candidate.transport.toLowerCase())) {
9153
+ return true;
9154
+ }
9155
+ filtered = true;
9156
+ return false;
9157
+ });
9132
9158
  });
9159
+ return filtered;
9133
9160
  }
9134
9161
  function setMaxBandwidth(parsedSdp, maxBandwidth) {
9135
9162
  parsedSdp.avMedia.forEach((mline) => {
@@ -9205,9 +9232,9 @@ function injectJmpAttributes(parsedSdp, csiMap, streamSignalingMode) {
9205
9232
  function injectDummyCandidates(parsedSdp) {
9206
9233
  parsedSdp.media.forEach((mLine) => {
9207
9234
  if (mLine.iceInfo.candidates.length === 0) {
9208
- mLine.addLine(new CandidateLine('dummy1', 1, 'udp', 1, '0.0.0.0', 1, 'host'));
9209
- mLine.addLine(new CandidateLine('dummy2', 2, 'tcp', 2, '0.0.0.0', 2, 'host'));
9210
- mLine.addLine(new CandidateLine('dummy3', 3, 'udp', 3, '0.0.0.0', 3, 'relay'));
9235
+ mLine.addLine(new CandidateLine('dummy1', 1, 'udp', 1, '0.0.0.0', 9, 'host'));
9236
+ mLine.addLine(new CandidateLine('dummy2', 1, 'tcp', 2, '0.0.0.0', 9, 'host'));
9237
+ mLine.addLine(new CandidateLine('dummy3', 1, 'tcp', 3, '0.0.0.0', 9, 'relay'));
9211
9238
  }
9212
9239
  });
9213
9240
  }
@@ -13927,9 +13954,9 @@ class MultistreamConnection extends EventEmitter$2 {
13927
13954
  this.sendTransceivers.set(mediaType, transceiver);
13928
13955
  this.createJmpSession(mediaType);
13929
13956
  }
13930
- createSendSlot(mediaType) {
13957
+ createSendSlot(mediaType, active = true) {
13931
13958
  const transceiver = this.getSendTransceiverOrThrow(mediaType);
13932
- transceiver.setActive(true);
13959
+ transceiver.setActive(active);
13933
13960
  return new SendSlot(transceiver);
13934
13961
  }
13935
13962
  createJmpSession(mediaType) {
@@ -14323,18 +14350,11 @@ class MultistreamConnection extends EventEmitter$2 {
14323
14350
  const parsedOffer = parse((_a = this.pc.getLocalDescription()) === null || _a === void 0 ? void 0 : _a.sdp);
14324
14351
  const recvTransceiversByMid = new Map([...this.recvTransceivers.values()].flat().map((t) => [t.mid, t]));
14325
14352
  matchMlinesInAnswer(parsedOffer, parsedAnswer, recvTransceiversByMid);
14326
- filterCandidates(parsedAnswer);
14353
+ if (filterCandidates(parsedAnswer)) {
14354
+ logger.info('Some unsupported remote candidates have been removed');
14355
+ }
14327
14356
  if (getBrowserDetails().name === 'Firefox') {
14328
14357
  setupBundle(parsedAnswer, this.options.bundlePolicy, this.midPredictor.getMidMap());
14329
- if (this.options.bundlePolicy === 'max-bundle') {
14330
- const { ufrag, pwd } = parsedAnswer.media[0].iceInfo;
14331
- parsedAnswer.media.forEach((mline, index) => {
14332
- if (index > 0) {
14333
- mline.iceInfo.ufrag = ufrag;
14334
- mline.iceInfo.pwd = pwd;
14335
- }
14336
- });
14337
- }
14338
14358
  }
14339
14359
  return parsedAnswer.toString();
14340
14360
  }