@techsee/techsee-media-service 16.0.0 → 17.1.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.
Files changed (49) hide show
  1. package/lib/MediaConstants.d.ts +5 -0
  2. package/lib/MediaConstants.d.ts.map +1 -1
  3. package/lib/MediaConstants.js +9 -1
  4. package/lib/MediaConstants.js.map +1 -1
  5. package/lib/MultiParty/MultiPartyService.d.ts +7 -3
  6. package/lib/MultiParty/MultiPartyService.d.ts.map +1 -1
  7. package/lib/MultiParty/MultiPartyServiceFactory.d.ts +2 -2
  8. package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -1
  9. package/lib/MultiParty/MultiPartyServiceFactory.js +2 -2
  10. package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -1
  11. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +3 -1
  12. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -1
  13. package/lib/MultiParty/index.d.ts +0 -1
  14. package/lib/MultiParty/index.d.ts.map +1 -1
  15. package/lib/MultiParty/index.js +1 -10
  16. package/lib/MultiParty/index.js.map +1 -1
  17. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts +13 -6
  18. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -1
  19. package/lib/MultiParty/opentok/OpentokMultiPartyService.js +192 -71
  20. package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -1
  21. package/lib/MultiParty/opentok/OpentokPublisher.d.ts +12 -16
  22. package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -1
  23. package/lib/MultiParty/opentok/OpentokPublisher.js +17 -108
  24. package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -1
  25. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts +2 -1
  26. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.d.ts.map +1 -1
  27. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js +8 -5
  28. package/lib/MultiParty/opentok/OpentokPublisherEventMapper.js.map +1 -1
  29. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts +5 -0
  30. package/lib/MultiParty/opentok/OpentokScreenPublisher.d.ts.map +1 -0
  31. package/lib/MultiParty/opentok/OpentokScreenPublisher.js +80 -0
  32. package/lib/MultiParty/opentok/OpentokScreenPublisher.js.map +1 -0
  33. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts +13 -0
  34. package/lib/MultiParty/opentok/OpentokVideoPublisher.d.ts.map +1 -0
  35. package/lib/MultiParty/opentok/OpentokVideoPublisher.js +314 -0
  36. package/lib/MultiParty/opentok/OpentokVideoPublisher.js.map +1 -0
  37. package/lib/MultiParty/types.d.ts +5 -1
  38. package/lib/MultiParty/types.d.ts.map +1 -1
  39. package/lib/MultiParty/utils.d.ts +7 -1
  40. package/lib/MultiParty/utils.d.ts.map +1 -1
  41. package/lib/MultiParty/utils.js +7 -1
  42. package/lib/MultiParty/utils.js.map +1 -1
  43. package/lib/qos/raw-qos.js +1 -1
  44. package/lib/webrtc-ie-shim.js +1 -1
  45. package/package.json +1 -1
  46. package/lib/MultiParty/VideoLayoutType.d.ts +0 -4
  47. package/lib/MultiParty/VideoLayoutType.d.ts.map +0 -1
  48. package/lib/MultiParty/VideoLayoutType.js +0 -13
  49. package/lib/MultiParty/VideoLayoutType.js.map +0 -1
@@ -214,7 +214,9 @@ var MultiPartyService_1 = require("../MultiPartyService");
214
214
 
215
215
  var MultipartyServiceEventTypes_1 = require("../MultipartyServiceEventTypes");
216
216
 
217
- var OpentokPublisher_1 = require("./OpentokPublisher");
217
+ var OpentokVideoPublisher_1 = require("./OpentokVideoPublisher");
218
+
219
+ var OpentokScreenPublisher_1 = require("./OpentokScreenPublisher");
218
220
 
219
221
  var OpentokSubscriber_1 = require("./OpentokSubscriber");
220
222
 
@@ -222,6 +224,8 @@ var utils_1 = require("../utils");
222
224
 
223
225
  var trace_1 = require("./trace");
224
226
 
227
+ var MediaConstants_1 = require("../../MediaConstants");
228
+
225
229
  var trace = MediaTracer_1.getMediaTracer('Multiparty');
226
230
 
227
231
  var OpentokMultiPartyService =
@@ -233,6 +237,7 @@ function (_super) {
233
237
  var _this = _super.call(this) || this;
234
238
 
235
239
  _this.getParticipantId = getParticipantId;
240
+ _this.enableDesktopSharing = false;
236
241
  _this.backgroundImageURI = MultiPartyService_1.DEFAULT_AVATAR_URI;
237
242
  _this.subscriberList = [];
238
243
 
@@ -240,7 +245,7 @@ function (_super) {
240
245
  _this.backgroundImageURI = uri || MultiPartyService_1.DEFAULT_AVATAR_URI;
241
246
  };
242
247
 
243
- _this.connect = function (settings, credentials) {
248
+ _this.connect = function (sessionSettings, credentials) {
244
249
  try {
245
250
  _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
246
251
 
@@ -273,7 +278,9 @@ function (_super) {
273
278
  return;
274
279
  }
275
280
 
276
- _this.initPublisher(settings);
281
+ _this.initVideoPublisher(sessionSettings);
282
+
283
+ _this.isScreenSharingSupported(sessionSettings.isScreenSharingCapabilitiesEnabled);
277
284
  });
278
285
  } catch (err) {
279
286
  trace.error(JSON.stringify(err));
@@ -287,13 +294,14 @@ function (_super) {
287
294
  };
288
295
 
289
296
  _this.disconnect = function () {
290
- var _a;
297
+ var _a, _b;
291
298
 
292
299
  try {
293
300
  trace.info('Disconnecting from session');
294
301
 
295
302
  if (_this.session) {
296
- (_a = _this.publisher) === null || _a === void 0 ? void 0 : _a.destroy();
303
+ (_a = _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
304
+ (_b = _this.screenPublisher) === null || _b === void 0 ? void 0 : _b.destroy();
297
305
 
298
306
  _this.session.disconnect();
299
307
 
@@ -304,28 +312,33 @@ function (_super) {
304
312
  }
305
313
  };
306
314
 
307
- _this.takeSnapshot = function (connectionId) {
308
- var _a, _b;
315
+ _this.takeSnapshot = function (connectionId, videoType) {
316
+ var _a, _b, _c;
317
+
318
+ if (videoType === void 0) {
319
+ videoType = MediaConstants_1.VideoTypesEnum.CAMERA;
320
+ }
309
321
 
310
322
  if (!connectionId) {
311
323
  return null;
312
324
  }
313
325
 
314
326
  if (connectionId === _this.ownConnectionId) {
315
- return ((_a = _this.publisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
327
+ if (videoType === MediaConstants_1.VideoTypesEnum.CAMERA) {
328
+ return ((_a = _this.videoPublisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
329
+ }
330
+
331
+ return ((_b = _this.screenPublisher) === null || _b === void 0 ? void 0 : _b.getImgData()) || null;
316
332
  }
317
333
 
318
- return ((_b = _this.subscribers.find(function (s) {
319
- return s.connectionId === connectionId;
320
- })) === null || _b === void 0 ? void 0 : _b.subscriber.getImgData()) || null;
334
+ return ((_c = _this.subscribers.find(function (s) {
335
+ return s.connectionId === connectionId && s.videoType === videoType;
336
+ })) === null || _c === void 0 ? void 0 : _c.subscriber.getImgData()) || null;
321
337
  };
322
338
 
323
- _this.initPublisher = function (settings) {
339
+ _this.initVideoPublisher = function (settings) {
324
340
  return __awaiter(_this, void 0, void 0, function () {
325
341
  var canStartWithAudio, canStartWithVideo, capabilitiesService, publisherOptions;
326
-
327
- var _this = this;
328
-
329
342
  return __generator(this, function (_a) {
330
343
  switch (_a.label) {
331
344
  case 0:
@@ -359,32 +372,17 @@ function (_super) {
359
372
  }
360
373
 
361
374
  publisherOptions = {
362
- participantId: this.getParticipantId(this.ownConnectionId),
363
- backgroundImageURI: this.backgroundImageURI
375
+ backgroundImageURI: this.backgroundImageURI,
376
+ participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.CAMERA)
364
377
  };
365
378
 
366
379
  try {
367
- this.publisher = new OpentokPublisher_1.OpentokPublisher(__assign(__assign({}, settings), {
368
- cameraEnabled: settings.cameraEnabled && canStartWithVideo,
369
- startWithAudioMuted: settings.startWithAudioMuted && canStartWithAudio
370
- }), publisherOptions, capabilitiesService); // forward publisher events
371
-
372
- this.publisher.on('cameraSourceChanged', function (e) {
373
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.cameraSourceChanged, e);
374
- });
375
- this.publisher.on('streamCreated', function (e) {
376
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, e);
377
- });
378
- this.publisher.on('streamDestroyed', function (e) {
379
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, e);
380
- });
381
- this.publisher.on('mediaDeviceAccessDenied', function (e) {
382
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.mediaDeviceAccessDenied, e);
383
- });
384
- this.publisher.on('videoElementCreated', function () {
385
- return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.videoElementCreated);
386
- });
387
- this.session.publish(this.publisher.get(), trace_1.traceError);
380
+ this.videoPublisher = new OpentokVideoPublisher_1.OpentokVideoPublisher(__assign(__assign({}, settings.videoSettings), {
381
+ cameraEnabled: settings.videoSettings.cameraEnabled && canStartWithVideo,
382
+ startWithAudioMuted: settings.videoSettings.startWithAudioMuted && canStartWithAudio
383
+ }), publisherOptions, capabilitiesService);
384
+ this.forwardPublisherEvents(this.videoPublisher);
385
+ this.session.publish(this.videoPublisher.get(), trace_1.traceError);
388
386
  } catch (error) {
389
387
  trace.error('could not init publisher');
390
388
  }
@@ -397,6 +395,66 @@ function (_super) {
397
395
  });
398
396
  };
399
397
 
398
+ _this.isScreenSharingSupported = function (isScreenSharingCapabilitiesEnabled) {
399
+ return __awaiter(_this, void 0, void 0, function () {
400
+ var _this = this;
401
+
402
+ return __generator(this, function (_a) {
403
+ switch (_a.label) {
404
+ case 0:
405
+ if (!(isScreenSharingCapabilitiesEnabled && !MediaCapabilitiesUtils_1.checkIsMobile())) return [3
406
+ /*break*/
407
+ , 2];
408
+ return [4
409
+ /*yield*/
410
+ , OT.checkScreenSharingCapability(function (res) {
411
+ if (!res.supported || res.extensionRegistered === false) {
412
+ // This browser does not support screen sharing.
413
+ trace.error('no screen sharing support found');
414
+ _this.enableDesktopSharing = false;
415
+ } else {
416
+ _this.enableDesktopSharing = true;
417
+ }
418
+ })];
419
+
420
+ case 1:
421
+ _a.sent();
422
+
423
+ return [3
424
+ /*break*/
425
+ , 3];
426
+
427
+ case 2:
428
+ this.enableDesktopSharing = false;
429
+ _a.label = 3;
430
+
431
+ case 3:
432
+ return [2
433
+ /*return*/
434
+ , Promise.resolve(this.enableDesktopSharing)];
435
+ }
436
+ });
437
+ });
438
+ };
439
+
440
+ _this.forwardPublisherEvents = function (publisher) {
441
+ publisher.on('cameraSourceChanged', function (e) {
442
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.cameraSourceChanged, e);
443
+ });
444
+ publisher.on('streamCreated', function (e) {
445
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamCreated, e);
446
+ });
447
+ publisher.on('streamDestroyed', function (e) {
448
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, e);
449
+ });
450
+ publisher.on('mediaDeviceAccessDenied', function (e) {
451
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.mediaDeviceAccessDenied, e);
452
+ });
453
+ publisher.on('videoElementCreated', function () {
454
+ return _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.videoElementCreated);
455
+ });
456
+ };
457
+
400
458
  _this.publishAudio = function (shouldMute) {
401
459
  return __awaiter(_this, void 0, void 0, function () {
402
460
  var canPublishAudio;
@@ -420,7 +478,7 @@ function (_super) {
420
478
  ];
421
479
  }
422
480
 
423
- (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.publishAudio(shouldMute);
481
+ (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishAudio(shouldMute);
424
482
  return [2
425
483
  /*return*/
426
484
  ];
@@ -452,7 +510,7 @@ function (_super) {
452
510
  ];
453
511
  }
454
512
 
455
- (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.publishVideo(shouldPublishVideo);
513
+ (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.publishVideo(shouldPublishVideo);
456
514
  return [2
457
515
  /*return*/
458
516
  ];
@@ -461,59 +519,107 @@ function (_super) {
461
519
  });
462
520
  };
463
521
 
464
- _this.switchCamera = function () {
522
+ _this.publishScreen = function () {
465
523
  return __awaiter(_this, void 0, void 0, function () {
524
+ var publisherOptions, capabilitiesService;
525
+
466
526
  var _a;
467
527
 
468
528
  return __generator(this, function (_b) {
469
- return [2
470
- /*return*/
471
- , (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.switchCamera()];
529
+ switch (_b.label) {
530
+ case 0:
531
+ if (!this.enableDesktopSharing) return [3
532
+ /*break*/
533
+ , 2];
534
+ publisherOptions = {
535
+ backgroundImageURI: this.backgroundImageURI
536
+ };
537
+ return [4
538
+ /*yield*/
539
+ , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
540
+
541
+ case 1:
542
+ capabilitiesService = _b.sent();
543
+
544
+ try {
545
+ this.screenPublisher = new OpentokScreenPublisher_1.OpentokScreenPublisher(__assign(__assign({}, publisherOptions), {
546
+ participantId: this.getParticipantId(this.ownConnectionId, MediaConstants_1.VideoTypesEnum.SCREEN)
547
+ }), capabilitiesService);
548
+ this.forwardPublisherEvents(this.screenPublisher);
549
+ this.screenPublisher && ((_a = this.session) === null || _a === void 0 ? void 0 : _a.publish(this.screenPublisher.get(), trace_1.traceError));
550
+ } catch (e) {
551
+ trace.error('Failed to publish screen', e);
552
+ }
553
+
554
+ _b.label = 2;
555
+
556
+ case 2:
557
+ return [2
558
+ /*return*/
559
+ ];
560
+ }
472
561
  });
473
562
  });
474
563
  };
475
564
 
476
- _this.reinitializeStreams = function (settings) {
565
+ _this.switchCamera = function () {
477
566
  return __awaiter(_this, void 0, void 0, function () {
478
- var _a, _b;
479
-
480
- return __generator(this, function (_c) {
481
- if (!this.session) {
482
- return [2
483
- /*return*/
484
- ];
485
- }
567
+ var _a;
486
568
 
487
- this.subscriberList.map(function (s) {
488
- return s.subscriber;
489
- }).forEach((_a = this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
490
- this.subscriberList = [];
491
- (_b = this.publisher) === null || _b === void 0 ? void 0 : _b.destroy();
569
+ return __generator(this, function (_b) {
492
570
  return [2
493
571
  /*return*/
494
- , this.initPublisher(settings)];
572
+ , (_a = this.videoPublisher) === null || _a === void 0 ? void 0 : _a.switchCamera()];
495
573
  });
496
574
  });
497
575
  };
498
576
 
577
+ _this.reinitializeStreams = function (settings) {
578
+ var _a, _b, _c;
579
+
580
+ var promises = [];
581
+
582
+ if (!_this.session) {
583
+ return Promise.resolve([]);
584
+ }
585
+
586
+ var shouldPublishScreen = !!_this.screenPublisher;
587
+
588
+ _this.subscriberList.map(function (s) {
589
+ return s.subscriber;
590
+ }).forEach((_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
591
+
592
+ _this.subscriberList = [];
593
+ (_b = _this.videoPublisher) === null || _b === void 0 ? void 0 : _b.destroy();
594
+ (_c = _this.screenPublisher) === null || _c === void 0 ? void 0 : _c.destroy();
595
+ promises.push(_this.initVideoPublisher(settings));
596
+
597
+ if (shouldPublishScreen) {
598
+ promises.push(_this.publishScreen());
599
+ }
600
+
601
+ return Promise.all(promises);
602
+ };
603
+
499
604
  _this.streamCreatedHandler = function (event) {
500
605
  return __awaiter(_this, void 0, void 0, function () {
501
- var stream, connection, hasAudio, hasVideo, videoDimensions, connectionId, data, participantId, clientRole, subscriber;
606
+ var stream, connection, hasAudio, hasVideo, videoDimensions, videoType, connectionId, data, participantId, clientRole, subscriber;
502
607
  return __generator(this, function (_a) {
503
608
  trace.info('streamCreatedHandler', event.stream);
504
609
  stream = event.stream;
505
- connection = stream.connection, hasAudio = stream.hasAudio, hasVideo = stream.hasVideo, videoDimensions = stream.videoDimensions;
610
+ connection = stream.connection, hasAudio = stream.hasAudio, hasVideo = stream.hasVideo, videoDimensions = stream.videoDimensions, videoType = stream.videoType;
506
611
  connectionId = connection.connectionId, data = connection.data;
507
- participantId = this.getParticipantId(connectionId);
612
+ participantId = this.getParticipantId(connectionId, videoType);
508
613
  clientRole = utils_1.decodeClientRole(data);
509
614
 
510
615
  if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
511
616
  if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
512
- subscriber = OpentokSubscriber_1.createSubscriber(this.session, stream, this.getParticipantId(connectionId), this.backgroundImageURI);
617
+ subscriber = OpentokSubscriber_1.createSubscriber(this.session, stream, this.getParticipantId(connectionId, videoType), this.backgroundImageURI);
513
618
  this.subscriberList.push({
514
619
  subscriber: subscriber,
515
620
  connectionId: connectionId,
516
- clientRole: clientRole
621
+ clientRole: clientRole,
622
+ videoType: videoType
517
623
  });
518
624
  } else {
519
625
  trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiPartyService_1.maxParticipantsNumber);
@@ -528,7 +634,8 @@ function (_super) {
528
634
  hasAudio: hasAudio,
529
635
  isOwnConnection: false,
530
636
  mirror: false,
531
- videoDimensions: videoDimensions
637
+ videoDimensions: videoDimensions,
638
+ videoType: videoType
532
639
  });
533
640
  return [2
534
641
  /*return*/
@@ -539,17 +646,23 @@ function (_super) {
539
646
 
540
647
  _this.streamDestroyedHandler = function (event) {
541
648
  trace.info('streamDestroyedHandler', event);
542
- var connection = event.stream.connection;
649
+ var _a = event.stream,
650
+ connection = _a.connection,
651
+ videoType = _a.videoType;
543
652
  var connectionId = connection.connectionId;
544
653
  _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
545
- return subscriber.connectionId !== connectionId;
654
+ return !utils_1.isSameStream(__assign({}, subscriber), {
655
+ connectionId: connectionId,
656
+ videoType: videoType
657
+ });
546
658
  });
547
659
 
548
660
  _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamDestroyed, {
549
- participantId: _this.getParticipantId(connectionId),
661
+ participantId: _this.getParticipantId(connectionId, videoType),
550
662
  connectionId: connectionId,
551
663
  isOwnConnection: false,
552
- clientRole: utils_1.decodeClientRole(connection.data)
664
+ clientRole: utils_1.decodeClientRole(connection.data),
665
+ videoType: videoType
553
666
  });
554
667
  };
555
668
 
@@ -595,13 +708,14 @@ function (_super) {
595
708
  hasVideo = _a.hasVideo,
596
709
  hasAudio = _a.hasAudio,
597
710
  connection = _a.connection,
598
- videoDimensions = _a.videoDimensions;
711
+ videoDimensions = _a.videoDimensions,
712
+ videoType = _a.videoType;
599
713
  var connectionId = connection.connectionId;
600
714
 
601
715
  _this.emit(MultipartyServiceEventTypes_1.MultiPartyServiceEventTypes.streamPropertyChanged, {
602
716
  hasVideo: hasVideo,
603
717
  hasAudio: hasAudio,
604
- participantId: _this.getParticipantId(connectionId),
718
+ participantId: _this.getParticipantId(connectionId, videoType),
605
719
  connectionId: connectionId,
606
720
  isOwnConnection: _this.checkOwnConnection(connectionId),
607
721
  clientRole: utils_1.decodeClientRole(connection.data),
@@ -636,6 +750,13 @@ function (_super) {
636
750
  enumerable: false,
637
751
  configurable: true
638
752
  });
753
+
754
+ OpentokMultiPartyService.prototype.stopScreenPublisher = function () {
755
+ var _a;
756
+
757
+ return (_a = this.screenPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
758
+ };
759
+
639
760
  return OpentokMultiPartyService;
640
761
  }(MultiPartyService_1.MultiPartyService);
641
762