@webex/web-client-media-engine 3.1.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
  */
@@ -9844,6 +9863,11 @@ class TypedEvent {
9844
9863
  }
9845
9864
  }
9846
9865
 
9866
+ var OfferAnswerType;
9867
+ (function (OfferAnswerType) {
9868
+ OfferAnswerType[OfferAnswerType["LocalOnly"] = 0] = "LocalOnly";
9869
+ OfferAnswerType[OfferAnswerType["Remote"] = 1] = "Remote";
9870
+ })(OfferAnswerType || (OfferAnswerType = {}));
9847
9871
  class SendOnlyTransceiver extends Transceiver {
9848
9872
  constructor(rtcRtpTransceiver, mid, csi, signaler, mediaType) {
9849
9873
  super(rtcRtpTransceiver, mid);
@@ -9935,7 +9959,7 @@ class SendOnlyTransceiver extends Transceiver {
9935
9959
  this.direction = enabled ? 'sendrecv' : 'inactive';
9936
9960
  this._rtcRtpTransceiver.direction = this.direction;
9937
9961
  if (this._rtcRtpTransceiver.direction !== this._rtcRtpTransceiver.currentDirection) {
9938
- this.negotiationNeeded.emit();
9962
+ this.negotiationNeeded.emit(OfferAnswerType.Remote);
9939
9963
  }
9940
9964
  }
9941
9965
  getStats() {
@@ -9991,9 +10015,11 @@ class SendOnlyTransceiver extends Transceiver {
9991
10015
  }
9992
10016
  setCodecParameters(parameters) {
9993
10017
  this.streamSignaler.setCodecParameters(parameters);
10018
+ this.negotiationNeeded.emit(OfferAnswerType.LocalOnly);
9994
10019
  }
9995
10020
  deleteCodecParameters(parameters) {
9996
10021
  this.streamSignaler.deleteCodecParameters(parameters);
10022
+ this.negotiationNeeded.emit(OfferAnswerType.LocalOnly);
9997
10023
  }
9998
10024
  }
9999
10025
 
@@ -10020,6 +10046,16 @@ class SendSlot {
10020
10046
  set active(active) {
10021
10047
  this.sendTransceiver.setActive(active);
10022
10048
  }
10049
+ setCodecParameters(parameters) {
10050
+ return __awaiter(this, void 0, void 0, function* () {
10051
+ this.sendTransceiver.setCodecParameters(parameters);
10052
+ });
10053
+ }
10054
+ deleteCodecParameters(parameters) {
10055
+ return __awaiter(this, void 0, void 0, function* () {
10056
+ this.sendTransceiver.deleteCodecParameters(parameters);
10057
+ });
10058
+ }
10023
10059
  }
10024
10060
 
10025
10061
  function generateSsrc() {
@@ -13895,15 +13931,20 @@ class MultistreamConnection extends EventEmitter$2 {
13895
13931
  this.sendSourceAdvertisement(mediaType);
13896
13932
  this.sendMediaRequestStatus(mediaType);
13897
13933
  });
13898
- transceiver.negotiationNeeded.on(() => {
13899
- this.emit(MultistreamConnectionEventNames.NegotiationNeeded);
13934
+ transceiver.negotiationNeeded.on((offerAnswerType) => {
13935
+ if (offerAnswerType === OfferAnswerType.Remote) {
13936
+ this.emit(MultistreamConnectionEventNames.NegotiationNeeded);
13937
+ }
13938
+ else if (this.pc.getRemoteDescription()) {
13939
+ this.queueLocalOfferAnswer();
13940
+ }
13900
13941
  });
13901
13942
  this.sendTransceivers.set(mediaType, transceiver);
13902
13943
  this.createJmpSession(mediaType);
13903
13944
  }
13904
- createSendSlot(mediaType) {
13945
+ createSendSlot(mediaType, active = true) {
13905
13946
  const transceiver = this.getSendTransceiverOrThrow(mediaType);
13906
- transceiver.setActive(true);
13947
+ transceiver.setActive(active);
13907
13948
  return new SendSlot(transceiver);
13908
13949
  }
13909
13950
  createJmpSession(mediaType) {
@@ -14333,24 +14374,6 @@ class MultistreamConnection extends EventEmitter$2 {
14333
14374
  }
14334
14375
  return transceiver;
14335
14376
  }
14336
- setCodecParameters(mediaType, parameters) {
14337
- return __awaiter(this, void 0, void 0, function* () {
14338
- const transceiver = this.sendTransceivers.get(mediaType);
14339
- transceiver === null || transceiver === void 0 ? void 0 : transceiver.setCodecParameters(parameters);
14340
- if (this.pc.getRemoteDescription()) {
14341
- yield this.queueLocalOfferAnswer();
14342
- }
14343
- });
14344
- }
14345
- deleteCodecParameters(mediaType, parameters) {
14346
- return __awaiter(this, void 0, void 0, function* () {
14347
- const transceiver = this.sendTransceivers.get(mediaType);
14348
- transceiver === null || transceiver === void 0 ? void 0 : transceiver.deleteCodecParameters(parameters);
14349
- if (this.pc.getRemoteDescription()) {
14350
- yield this.queueLocalOfferAnswer();
14351
- }
14352
- });
14353
- }
14354
14377
  requestMedia(mediaType, streamRequests) {
14355
14378
  var _a;
14356
14379
  const task = () => {