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

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/esm/index.js CHANGED
@@ -482,6 +482,175 @@ var media = /*#__PURE__*/Object.freeze({
482
482
  ensureDevicePermissions: ensureDevicePermissions
483
483
  });
484
484
 
485
+ var ErrorTypes;
486
+ (function (ErrorTypes) {
487
+ ErrorTypes["DEVICE_PERMISSION_DENIED"] = "DEVICE_PERMISSION_DENIED";
488
+ ErrorTypes["CREATE_STREAM_FAILED"] = "CREATE_CAMERA_STREAM";
489
+ })(ErrorTypes || (ErrorTypes = {}));
490
+ /**
491
+ * Represents a WCME error, which contains error type and error message.
492
+ */
493
+ class WcmeError {
494
+ /**
495
+ * Creates new error.
496
+ *
497
+ * @param type - Error type.
498
+ * @param message - Error message.
499
+ */
500
+ constructor(type, message = '') {
501
+ this.type = type;
502
+ this.message = message;
503
+ }
504
+ }
505
+ /**
506
+ * Creates a camera stream. Please note that the constraint params in second getUserMedia call would NOT take effect when:
507
+ *
508
+ * 1. Previous captured video stream from the same device is not stopped.
509
+ * 2. Previous createCameraStream() call for the same device is in progress.
510
+ *
511
+ * @param constructor - Constructor for the local camera stream.
512
+ * @param constraints - Video device constraints.
513
+ * @returns A LocalCameraStream object or an error.
514
+ */
515
+ function createCameraStream(constructor, constraints) {
516
+ return __awaiter$1(this, void 0, void 0, function* () {
517
+ let stream;
518
+ try {
519
+ stream = yield getUserMedia({ video: Object.assign({}, constraints) });
520
+ }
521
+ catch (error) {
522
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create camera stream: ${error}`);
523
+ }
524
+ return new constructor(stream);
525
+ });
526
+ }
527
+ /**
528
+ * Creates a LocalMicrophoneStream with the given constraints.
529
+ *
530
+ * @param constructor - Constructor for the local microphone stream.
531
+ * @param constraints - Audio device constraints.
532
+ * @returns A LocalMicrophoneStream object or an error.
533
+ */
534
+ function createMicrophoneStream(constructor, constraints) {
535
+ return __awaiter$1(this, void 0, void 0, function* () {
536
+ let stream;
537
+ try {
538
+ stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
539
+ }
540
+ catch (error) {
541
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create microphone stream: ${error}`);
542
+ }
543
+ return new constructor(stream);
544
+ });
545
+ }
546
+ /**
547
+ * Creates a LocalDisplayStream with the given parameters.
548
+ *
549
+ * @param constructor - Constructor for the local display stream.
550
+ * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
551
+ * @returns A Promise that resolves to a LocalDisplayStream or an error.
552
+ */
553
+ function createDisplayStream(constructor, videoContentHint) {
554
+ return __awaiter$1(this, void 0, void 0, function* () {
555
+ let stream;
556
+ try {
557
+ stream = yield getDisplayMedia({ video: true });
558
+ }
559
+ catch (error) {
560
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create display stream: ${error}`);
561
+ }
562
+ const localDisplayStream = new constructor(stream);
563
+ if (videoContentHint) {
564
+ localDisplayStream.contentHint = videoContentHint;
565
+ }
566
+ return localDisplayStream;
567
+ });
568
+ }
569
+ /**
570
+ * Creates a LocalDisplayStream and a LocalSystemAudioStream with the given parameters.
571
+ *
572
+ * @param displayStreamConstructor - Constructor for the local display stream.
573
+ * @param systemAudioStreamConstructor - Constructor for the local system audio stream.
574
+ * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
575
+ * @returns A Promise that resolves to a LocalDisplayStream and a LocalSystemAudioStream or an
576
+ * error. If no system audio is available, the LocalSystemAudioStream will be resolved as null
577
+ * instead.
578
+ */
579
+ function createDisplayStreamWithAudio(displayStreamConstructor, systemAudioStreamConstructor, videoContentHint) {
580
+ return __awaiter$1(this, void 0, void 0, function* () {
581
+ let stream;
582
+ try {
583
+ stream = yield getDisplayMedia({ video: true, audio: true });
584
+ }
585
+ catch (error) {
586
+ throw new WcmeError(ErrorTypes.CREATE_STREAM_FAILED, `Failed to create display and system audio streams: ${error}`);
587
+ }
588
+ // eslint-disable-next-line new-cap
589
+ const localDisplayStream = new displayStreamConstructor(new MediaStream(stream.getVideoTracks()));
590
+ if (videoContentHint) {
591
+ localDisplayStream.contentHint = videoContentHint;
592
+ }
593
+ let localSystemAudioStream = null;
594
+ if (stream.getAudioTracks().length > 0) {
595
+ // eslint-disable-next-line new-cap
596
+ localSystemAudioStream = new systemAudioStreamConstructor(new MediaStream(stream.getAudioTracks()));
597
+ }
598
+ return [localDisplayStream, localSystemAudioStream];
599
+ });
600
+ }
601
+ /**
602
+ * Enumerates the media input and output devices available.
603
+ *
604
+ * @param deviceKind - Optional filter to return a specific device kind.
605
+ * @returns List of media devices in an array of MediaDeviceInfo objects.
606
+ */
607
+ function getDevices(deviceKind) {
608
+ return __awaiter$1(this, void 0, void 0, function* () {
609
+ let devices;
610
+ try {
611
+ devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
612
+ }
613
+ catch (error) {
614
+ throw new WcmeError(ErrorTypes.DEVICE_PERMISSION_DENIED, 'Failed to ensure device permissions');
615
+ }
616
+ return devices.filter((v) => (deviceKind ? v.kind === deviceKind : true));
617
+ });
618
+ }
619
+ /**
620
+ * Helper function to get a list of microphone devices.
621
+ *
622
+ * @returns List of microphone devices in an array of MediaDeviceInfo objects.
623
+ */
624
+ function getAudioInputDevices() {
625
+ return __awaiter$1(this, void 0, void 0, function* () {
626
+ return getDevices(DeviceKind.AudioInput);
627
+ });
628
+ }
629
+ /**
630
+ * Helper function to get a list of speaker devices.
631
+ *
632
+ * @returns List of speaker devices in an array of MediaDeviceInfo objects.
633
+ */
634
+ function getAudioOutputDevices() {
635
+ return __awaiter$1(this, void 0, void 0, function* () {
636
+ return getDevices(DeviceKind.AudioOutput);
637
+ });
638
+ }
639
+ /**
640
+ * Helper function to get a list of camera devices.
641
+ *
642
+ * @returns List of camera devices in an array of MediaDeviceInfo objects.
643
+ */
644
+ function getVideoInputDevices() {
645
+ return __awaiter$1(this, void 0, void 0, function* () {
646
+ return getDevices(DeviceKind.VideoInput);
647
+ });
648
+ }
649
+ /**
650
+ * Export the setOnDeviceChangeHandler method directly from the core lib.
651
+ */
652
+ const { setOnDeviceChangeHandler } = media;
653
+
485
654
  var events$1$1 = {exports: {}};
486
655
 
487
656
  var R$1$1 = typeof Reflect === 'object' ? Reflect : null;
@@ -1231,6 +1400,26 @@ class _LocalStream extends Stream {
1231
1400
  _a$6 = LocalStreamEventNames.ConstraintsChange, _b = LocalStreamEventNames.OutputTrackChange;
1232
1401
  const LocalStream = AddEvents(_LocalStream);
1233
1402
 
1403
+ /**
1404
+ * An audio LocalStream.
1405
+ */
1406
+ class LocalAudioStream extends LocalStream {
1407
+ /**
1408
+ * Apply constraints to the stream.
1409
+ *
1410
+ * @param constraints - The constraints to apply.
1411
+ * @returns A promise which resolves when the constraints have been successfully applied.
1412
+ */
1413
+ applyConstraints(constraints) {
1414
+ return __awaiter$1(this, void 0, void 0, function* () {
1415
+ logger$3.log(`Applying constraints to local track:`, constraints);
1416
+ return this.inputTrack.applyConstraints(constraints).then(() => {
1417
+ this[LocalStreamEventNames.ConstraintsChange].emit();
1418
+ });
1419
+ });
1420
+ }
1421
+ }
1422
+
1234
1423
  /**
1235
1424
  * A video LocalStream.
1236
1425
  */
@@ -1298,26 +1487,6 @@ class LocalCameraStream extends LocalVideoStream {
1298
1487
  class LocalDisplayStream extends LocalVideoStream {
1299
1488
  }
1300
1489
 
1301
- /**
1302
- * An audio LocalStream.
1303
- */
1304
- class LocalAudioStream extends LocalStream {
1305
- /**
1306
- * Apply constraints to the stream.
1307
- *
1308
- * @param constraints - The constraints to apply.
1309
- * @returns A promise which resolves when the constraints have been successfully applied.
1310
- */
1311
- applyConstraints(constraints) {
1312
- return __awaiter$1(this, void 0, void 0, function* () {
1313
- logger$3.log(`Applying constraints to local track:`, constraints);
1314
- return this.inputTrack.applyConstraints(constraints).then(() => {
1315
- this[LocalStreamEventNames.ConstraintsChange].emit();
1316
- });
1317
- });
1318
- }
1319
- }
1320
-
1321
1490
  /**
1322
1491
  * A local microphone stream.
1323
1492
  */
@@ -1330,156 +1499,6 @@ class LocalMicrophoneStream extends LocalAudioStream {
1330
1499
  class LocalSystemAudioStream extends LocalAudioStream {
1331
1500
  }
1332
1501
 
1333
- var ErrorTypes;
1334
- (function (ErrorTypes) {
1335
- ErrorTypes["DEVICE_PERMISSION_DENIED"] = "DEVICE_PERMISSION_DENIED";
1336
- ErrorTypes["CREATE_CAMERA_STREAM_FAILED"] = "CREATE_CAMERA_STREAM_FAILED";
1337
- ErrorTypes["CREATE_MICROPHONE_STREAM_FAILED"] = "CREATE_MICROPHONE_STREAM_FAILED";
1338
- })(ErrorTypes || (ErrorTypes = {}));
1339
- /**
1340
- * Represents a WCME error, which contains error type and error message.
1341
- */
1342
- class WcmeError {
1343
- /**
1344
- * Creates new error.
1345
- *
1346
- * @param type - Error type.
1347
- * @param message - Error message.
1348
- */
1349
- constructor(type, message = '') {
1350
- this.type = type;
1351
- this.message = message;
1352
- }
1353
- }
1354
- /**
1355
- * Creates a camera stream. Please note that the constraint params in second getUserMedia call would NOT take effect when:
1356
- *
1357
- * 1. Previous captured video stream from the same device is not stopped.
1358
- * 2. Previous createCameraStream() call for the same device is in progress.
1359
- *
1360
- * @param constraints - Video device constraints.
1361
- * @returns A LocalCameraStream object or an error.
1362
- */
1363
- function createCameraStream(constraints) {
1364
- return __awaiter$1(this, void 0, void 0, function* () {
1365
- let stream;
1366
- try {
1367
- stream = yield getUserMedia({ video: Object.assign({}, constraints) });
1368
- }
1369
- catch (error) {
1370
- throw new WcmeError(ErrorTypes.CREATE_CAMERA_STREAM_FAILED, `Failed to create camera stream ${error}`);
1371
- }
1372
- return new LocalCameraStream(stream);
1373
- });
1374
- }
1375
- /**
1376
- * Creates a LocalMicrophoneStream with the given constraints.
1377
- *
1378
- * @param constraints - Audio device constraints.
1379
- * @returns A LocalMicrophoneStream object or an error.
1380
- */
1381
- function createMicrophoneStream(constraints) {
1382
- return __awaiter$1(this, void 0, void 0, function* () {
1383
- let stream;
1384
- try {
1385
- stream = yield getUserMedia({ audio: Object.assign({}, constraints) });
1386
- }
1387
- catch (error) {
1388
- throw new WcmeError(ErrorTypes.CREATE_MICROPHONE_STREAM_FAILED, `Failed to create microphone stream ${error}`);
1389
- }
1390
- return new LocalMicrophoneStream(stream);
1391
- });
1392
- }
1393
- /**
1394
- * Creates a LocalDisplayStream with the given parameters.
1395
- *
1396
- * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
1397
- * @returns A Promise that resolves to a LocalDisplayStream.
1398
- */
1399
- function createDisplayStream(videoContentHint) {
1400
- return __awaiter$1(this, void 0, void 0, function* () {
1401
- const stream = yield getDisplayMedia({ video: true });
1402
- const localDisplayStream = new LocalDisplayStream(stream);
1403
- if (videoContentHint) {
1404
- localDisplayStream.contentHint = videoContentHint;
1405
- }
1406
- return localDisplayStream;
1407
- });
1408
- }
1409
- /**
1410
- * Creates a LocalDisplayStream and a LocalSystemAudioStream with the given parameters.
1411
- *
1412
- * @param videoContentHint - An optional parameter to give a hint for the content of the stream.
1413
- * @returns A Promise that resolves to a LocalDisplayStream and a LocalSystemAudioStream. If no system
1414
- * audio is available, the LocalSystemAudioStream will be resolved as null instead.
1415
- */
1416
- function createDisplayStreamWithAudio(videoContentHint) {
1417
- return __awaiter$1(this, void 0, void 0, function* () {
1418
- const stream = yield getDisplayMedia({ video: true, audio: true });
1419
- const localDisplayStream = new LocalDisplayStream(new MediaStream(stream.getVideoTracks()));
1420
- if (videoContentHint) {
1421
- localDisplayStream.contentHint = videoContentHint;
1422
- }
1423
- let localSystemAudioStream = null;
1424
- if (stream.getAudioTracks().length > 0) {
1425
- localSystemAudioStream = new LocalSystemAudioStream(new MediaStream(stream.getAudioTracks()));
1426
- }
1427
- return [localDisplayStream, localSystemAudioStream];
1428
- });
1429
- }
1430
- /**
1431
- * Enumerates the media input and output devices available.
1432
- *
1433
- * @param deviceKind - Optional filter to return a specific device kind.
1434
- * @returns List of media devices in an array of MediaDeviceInfo objects.
1435
- */
1436
- function getDevices(deviceKind) {
1437
- return __awaiter$1(this, void 0, void 0, function* () {
1438
- let devices;
1439
- try {
1440
- devices = yield ensureDevicePermissions([DeviceKind.AudioInput, DeviceKind.VideoInput], enumerateDevices);
1441
- }
1442
- catch (error) {
1443
- throw new WcmeError(ErrorTypes.DEVICE_PERMISSION_DENIED, 'Failed to ensure device permissions');
1444
- }
1445
- return devices.filter((v) => (deviceKind ? v.kind === deviceKind : true));
1446
- });
1447
- }
1448
- /**
1449
- * Helper function to get a list of microphone devices.
1450
- *
1451
- * @returns List of microphone devices in an array of MediaDeviceInfo objects.
1452
- */
1453
- function getAudioInputDevices() {
1454
- return __awaiter$1(this, void 0, void 0, function* () {
1455
- return getDevices(DeviceKind.AudioInput);
1456
- });
1457
- }
1458
- /**
1459
- * Helper function to get a list of speaker devices.
1460
- *
1461
- * @returns List of speaker devices in an array of MediaDeviceInfo objects.
1462
- */
1463
- function getAudioOutputDevices() {
1464
- return __awaiter$1(this, void 0, void 0, function* () {
1465
- return getDevices(DeviceKind.AudioOutput);
1466
- });
1467
- }
1468
- /**
1469
- * Helper function to get a list of camera devices.
1470
- *
1471
- * @returns List of camera devices in an array of MediaDeviceInfo objects.
1472
- */
1473
- function getVideoInputDevices() {
1474
- return __awaiter$1(this, void 0, void 0, function* () {
1475
- return getDevices(DeviceKind.VideoInput);
1476
- });
1477
- }
1478
- /**
1479
- * Export the setOnDeviceChangeHandler method directly from the core lib.
1480
- */
1481
- const { setOnDeviceChangeHandler } = media;
1482
-
1483
1502
  /**
1484
1503
  * A stream originating from a remote peer.
1485
1504
  */
@@ -13923,9 +13942,9 @@ class MultistreamConnection extends EventEmitter$2 {
13923
13942
  this.sendTransceivers.set(mediaType, transceiver);
13924
13943
  this.createJmpSession(mediaType);
13925
13944
  }
13926
- createSendSlot(mediaType) {
13945
+ createSendSlot(mediaType, active = true) {
13927
13946
  const transceiver = this.getSendTransceiverOrThrow(mediaType);
13928
- transceiver.setActive(true);
13947
+ transceiver.setActive(active);
13929
13948
  return new SendSlot(transceiver);
13930
13949
  }
13931
13950
  createJmpSession(mediaType) {