@techsee/techsee-media-service 8.0.2 → 10.0.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 (34) hide show
  1. package/lib/MultiParty/MultiPartyService.d.ts +3 -5
  2. package/lib/MultiParty/MultiPartyService.d.ts.map +1 -1
  3. package/lib/MultiParty/MultiPartyService.js +4 -7
  4. package/lib/MultiParty/MultiPartyService.js.map +1 -1
  5. package/lib/MultiParty/MultiPartyServiceFactory.d.ts.map +1 -1
  6. package/lib/MultiParty/MultiPartyServiceFactory.js +2 -2
  7. package/lib/MultiParty/MultiPartyServiceFactory.js.map +1 -1
  8. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts +23 -1
  9. package/lib/MultiParty/MultipartyServiceEventTypes.d.ts.map +1 -1
  10. package/lib/MultiParty/{OpentokMultiPartyService.d.ts → opentok/OpentokMultiPartyService.d.ts} +9 -13
  11. package/lib/MultiParty/opentok/OpentokMultiPartyService.d.ts.map +1 -0
  12. package/lib/MultiParty/{OpentokMultiPartyService.js → opentok/OpentokMultiPartyService.js} +115 -396
  13. package/lib/MultiParty/opentok/OpentokMultiPartyService.js.map +1 -0
  14. package/lib/MultiParty/opentok/OpentokPublisher.d.ts +25 -0
  15. package/lib/MultiParty/opentok/OpentokPublisher.d.ts.map +1 -0
  16. package/lib/MultiParty/opentok/OpentokPublisher.js +409 -0
  17. package/lib/MultiParty/opentok/OpentokPublisher.js.map +1 -0
  18. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts +1 -0
  19. package/lib/MultiParty/opentok/OpentokSubscriber.d.ts.map +1 -0
  20. package/lib/MultiParty/opentok/OpentokSubscriber.js +34 -0
  21. package/lib/MultiParty/opentok/OpentokSubscriber.js.map +1 -0
  22. package/lib/MultiParty/opentok/OpentokUtils.d.ts +2 -0
  23. package/lib/MultiParty/opentok/OpentokUtils.d.ts.map +1 -0
  24. package/lib/MultiParty/opentok/OpentokUtils.js +17 -0
  25. package/lib/MultiParty/opentok/OpentokUtils.js.map +1 -0
  26. package/lib/MultiParty/opentok/trace.d.ts +2 -0
  27. package/lib/MultiParty/opentok/trace.d.ts.map +1 -0
  28. package/lib/MultiParty/opentok/trace.js +31 -0
  29. package/lib/MultiParty/opentok/trace.js.map +1 -0
  30. package/lib/oldCode/utils/ImageFixer.js +2 -0
  31. package/lib/oldCode/utils/ImageFixer.js.map +1 -1
  32. package/package.json +4 -4
  33. package/lib/MultiParty/OpentokMultiPartyService.d.ts.map +0 -1
  34. package/lib/MultiParty/OpentokMultiPartyService.js.map +0 -1
@@ -204,41 +204,45 @@ Object.defineProperty(exports, "__esModule", {
204
204
  });
205
205
  exports.OpentokMultiPartyService = void 0;
206
206
 
207
- var MediaConstants_1 = require("../MediaConstants");
207
+ var __1 = require("..");
208
208
 
209
- var MediaUtils_1 = require("../MediaUtils");
209
+ var MediaUtils_1 = require("../../MediaUtils");
210
210
 
211
- var MediaCapabilitiesService_1 = require("./MediaCapabilitiesService");
211
+ var MediaCapabilitiesService_1 = require("../MediaCapabilitiesService");
212
212
 
213
- var MediaCapabilitiesUtils_1 = require("./MediaCapabilitiesUtils");
213
+ var MediaCapabilitiesUtils_1 = require("../MediaCapabilitiesUtils");
214
214
 
215
- var MultiPartyService_1 = require("./MultiPartyService");
215
+ var MultiPartyService_1 = require("../MultiPartyService");
216
216
 
217
- var MultipartyServiceEventTypes_1 = require("./MultipartyServiceEventTypes");
217
+ var MultipartyServiceEventTypes_1 = require("../MultipartyServiceEventTypes");
218
218
 
219
- var trace = MediaUtils_1.getMediaTracer('Multiparty');
220
- var OPENTOK_MIRRORED_CSS_CLASS = 'OT_mirrored'; // The preferred camera position to use for the video source
219
+ var OpentokPublisher_1 = require("./OpentokPublisher");
220
+
221
+ var OpentokSubscriber_1 = require("./OpentokSubscriber");
222
+
223
+ var OpentokUtils_1 = require("./OpentokUtils");
221
224
 
222
- var OpentokFacingMode;
225
+ var trace_1 = require("./trace");
223
226
 
224
- (function (OpentokFacingMode) {
225
- OpentokFacingMode["USER"] = "user";
226
- OpentokFacingMode["ENVIRONMENT"] = "environment";
227
- })(OpentokFacingMode || (OpentokFacingMode = {}));
227
+ var trace = MediaUtils_1.getMediaTracer('Multiparty');
228
228
 
229
229
  var OpentokMultiPartyService =
230
230
  /** @class */
231
231
  function (_super) {
232
232
  __extends(OpentokMultiPartyService, _super);
233
233
 
234
- function OpentokMultiPartyService(settings, getParticipantId) {
235
- var _this = _super.call(this, settings) || this;
234
+ function OpentokMultiPartyService(getParticipantId) {
235
+ var _this = _super.call(this) || this;
236
236
 
237
237
  _this.getParticipantId = getParticipantId;
238
+ _this.backgroundImageURI = __1.DEFAULT_AVATAR_URI;
238
239
  _this.subscriberList = [];
239
- _this.mirror = true;
240
240
 
241
- _this.connect = function (credentials) {
241
+ _this.setBackgroundImageURI = function (uri) {
242
+ _this.backgroundImageURI = uri || __1.DEFAULT_AVATAR_URI;
243
+ };
244
+
245
+ _this.connect = function (settings, credentials) {
242
246
  try {
243
247
  _this.session = OT.initSession(credentials.apiKey, credentials.sessionId);
244
248
 
@@ -260,31 +264,27 @@ function (_super) {
260
264
  if (error) {
261
265
  (_a = _this.session) === null || _a === void 0 ? void 0 : _a.off();
262
266
  _this.session = undefined;
267
+ trace_1.traceError(error);
263
268
 
264
- _this.traceErrorCallback(error);
265
-
266
- var e = {
269
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, {
267
270
  meta: {
268
271
  err: JSON.stringify(error)
269
272
  }
270
- };
271
-
272
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, e);
273
+ });
273
274
 
274
275
  return;
275
276
  }
276
277
 
277
- _this.createPublisher(_this.settings);
278
+ _this.initPublisher(settings);
278
279
  });
279
280
  } catch (err) {
280
281
  trace.error(JSON.stringify(err));
281
- var e = {
282
+
283
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, {
282
284
  meta: {
283
285
  err: JSON.stringify(err)
284
286
  }
285
- };
286
-
287
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, e);
287
+ });
288
288
  }
289
289
  };
290
290
 
@@ -295,7 +295,7 @@ function (_super) {
295
295
  trace.info('Disconnecting from session');
296
296
 
297
297
  if (_this.session) {
298
- (_a = _this.currentPublisher) === null || _a === void 0 ? void 0 : _a.destroy();
298
+ (_a = _this.publisher) === null || _a === void 0 ? void 0 : _a.destroy();
299
299
 
300
300
  _this.session.disconnect();
301
301
 
@@ -314,7 +314,7 @@ function (_super) {
314
314
  }
315
315
 
316
316
  if (connectionId === _this.ownConnectionId) {
317
- return ((_a = _this.currentPublisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
317
+ return ((_a = _this.publisher) === null || _a === void 0 ? void 0 : _a.getImgData()) || null;
318
318
  }
319
319
 
320
320
  return ((_b = _this.subscribers.find(function (s) {
@@ -322,14 +322,14 @@ function (_super) {
322
322
  })) === null || _b === void 0 ? void 0 : _b.subscriber.getImgData()) || null;
323
323
  };
324
324
 
325
- _this.createPublisher = function (settings) {
325
+ _this.initPublisher = function (settings) {
326
326
  return __awaiter(_this, void 0, void 0, function () {
327
- var canStartWithAudio, canStartWithVideo;
327
+ var canStartWithAudio, canStartWithVideo, capabilitiesService, publisherOptions;
328
328
 
329
- var _a;
329
+ var _this = this;
330
330
 
331
- return __generator(this, function (_b) {
332
- switch (_b.label) {
331
+ return __generator(this, function (_a) {
332
+ switch (_a.label) {
333
333
  case 0:
334
334
  if (!this.session) {
335
335
  return [2
@@ -342,43 +342,49 @@ function (_super) {
342
342
  , MediaCapabilitiesUtils_1.checkAudioCapabilities()];
343
343
 
344
344
  case 1:
345
- canStartWithAudio = _b.sent();
345
+ canStartWithAudio = _a.sent();
346
346
  return [4
347
347
  /*yield*/
348
348
  , MediaCapabilitiesUtils_1.checkVideoCapabilities()];
349
349
 
350
350
  case 2:
351
- canStartWithVideo = _b.sent();
352
-
353
- if (!canStartWithAudio && !canStartWithVideo) {
354
- // FIXME: use emitter
355
- trace.error('Did not create publisher due to lack of media capabilities.');
356
- return [2
357
- /*return*/
358
- ];
359
- }
360
-
361
- if (!!this.currentPublisher) return [3
362
- /*break*/
363
- , 4];
351
+ canStartWithVideo = _a.sent();
364
352
  return [4
365
353
  /*yield*/
366
- , this.initPublisher(__assign(__assign({}, settings), {
367
- cameraEnabled: settings.cameraEnabled && canStartWithVideo,
368
- startWithAudioMuted: settings.startWithAudioMuted && canStartWithAudio
369
- }))];
354
+ , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
370
355
 
371
356
  case 3:
372
- _b.sent();
357
+ capabilitiesService = _a.sent();
373
358
 
374
- if (!this.currentPublisher) {
359
+ if (!canStartWithAudio && !canStartWithVideo) {
375
360
  throw new Error('Creating session requires initialized publisher');
376
361
  }
377
362
 
378
- this.currentPublisher && ((_a = this.session) === null || _a === void 0 ? void 0 : _a.publish(this.currentPublisher, this.traceErrorCallback));
379
- _b.label = 4;
380
-
381
- case 4:
363
+ publisherOptions = {
364
+ participantId: this.getParticipantId(this.ownConnectionId),
365
+ backgroundImageURI: this.backgroundImageURI
366
+ };
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.MULTI_PARTY_EVENTS.cameraSourceChanged, e);
374
+ });
375
+ this.publisher.on('streamCreated', function (e) {
376
+ return _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, e);
377
+ });
378
+ this.publisher.on('streamDestroyed', function (e) {
379
+ return _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
380
+ });
381
+ this.publisher.on('mediaDeviceAccessDenied', function (e) {
382
+ return _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, e);
383
+ });
384
+ this.publisher.on('videoElementCreated', function () {
385
+ return _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.videoElementCreated);
386
+ });
387
+ this.session.publish(this.publisher.get(), trace_1.traceError);
382
388
  return [2
383
389
  /*return*/
384
390
  ];
@@ -390,15 +396,18 @@ function (_super) {
390
396
  _this.publishAudio = function (shouldMute) {
391
397
  return __awaiter(_this, void 0, void 0, function () {
392
398
  var canPublishAudio;
393
- return __generator(this, function (_a) {
394
- switch (_a.label) {
399
+
400
+ var _a;
401
+
402
+ return __generator(this, function (_b) {
403
+ switch (_b.label) {
395
404
  case 0:
396
405
  return [4
397
406
  /*yield*/
398
407
  , MediaCapabilitiesUtils_1.checkAudioCapabilities()];
399
408
 
400
409
  case 1:
401
- canPublishAudio = _a.sent(); // why do we care about audio if 'shouldMute' is true?
410
+ canPublishAudio = _b.sent();
402
411
 
403
412
  if (shouldMute && !canPublishAudio) {
404
413
  trace.error('could not publish audio');
@@ -407,28 +416,7 @@ function (_super) {
407
416
  ];
408
417
  }
409
418
 
410
- if (!!this.currentPublisher) return [3
411
- /*break*/
412
- , 3];
413
- return [4
414
- /*yield*/
415
- , this.createPublisher(__assign(__assign({}, this.settings), {
416
- // so if 'shouldMute' is true then we DON't mute?
417
- startWithAudioMuted: !shouldMute
418
- }))];
419
-
420
- case 2:
421
- _a.sent();
422
-
423
- return [3
424
- /*break*/
425
- , 4];
426
-
427
- case 3:
428
- this.currentPublisher.publishAudio(shouldMute);
429
- _a.label = 4;
430
-
431
- case 4:
419
+ (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.publishAudio(shouldMute);
432
420
  return [2
433
421
  /*return*/
434
422
  ];
@@ -440,15 +428,18 @@ function (_super) {
440
428
  _this.publishVideo = function (shouldPublishVideo) {
441
429
  return __awaiter(_this, void 0, void 0, function () {
442
430
  var canPublishVideo;
443
- return __generator(this, function (_a) {
444
- switch (_a.label) {
431
+
432
+ var _a;
433
+
434
+ return __generator(this, function (_b) {
435
+ switch (_b.label) {
445
436
  case 0:
446
437
  return [4
447
438
  /*yield*/
448
439
  , MediaCapabilitiesUtils_1.checkVideoCapabilities()];
449
440
 
450
441
  case 1:
451
- canPublishVideo = _a.sent();
442
+ canPublishVideo = _b.sent();
452
443
 
453
444
  if (shouldPublishVideo && !canPublishVideo) {
454
445
  trace.error('could not publish video');
@@ -457,27 +448,7 @@ function (_super) {
457
448
  ];
458
449
  }
459
450
 
460
- if (!!this.currentPublisher) return [3
461
- /*break*/
462
- , 3];
463
- return [4
464
- /*yield*/
465
- , this.createPublisher(__assign(__assign({}, this.settings), {
466
- cameraEnabled: shouldPublishVideo
467
- }))];
468
-
469
- case 2:
470
- _a.sent();
471
-
472
- return [3
473
- /*break*/
474
- , 4];
475
-
476
- case 3:
477
- this.currentPublisher.publishVideo(shouldPublishVideo);
478
- _a.label = 4;
479
-
480
- case 4:
451
+ (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.publishVideo(shouldPublishVideo);
481
452
  return [2
482
453
  /*return*/
483
454
  ];
@@ -488,227 +459,21 @@ function (_super) {
488
459
 
489
460
  _this.switchCamera = function () {
490
461
  return __awaiter(_this, void 0, void 0, function () {
491
- var mediaCapabilitiesService, deviceId, cameraSource_1, err_1;
492
-
493
- var _this = this;
494
-
495
462
  var _a;
496
463
 
497
464
  return __generator(this, function (_b) {
498
- switch (_b.label) {
499
- case 0:
500
- _b.trys.push([0, 3,, 4]);
501
-
502
- return [4
503
- /*yield*/
504
- , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
505
-
506
- case 1:
507
- mediaCapabilitiesService = _b.sent();
508
-
509
- if (!mediaCapabilitiesService.supportSwitchCamera) {
510
- throw new Error('Not Support switch camera');
511
- }
512
-
513
- deviceId = '';
514
-
515
- switch (this.settings.selectedCamera) {
516
- case MediaConstants_1.MultiPartyCameraTypes.BACK:
517
- cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.FRONT;
518
- deviceId = mediaCapabilitiesService.frontCameraDeviceId;
519
- this.mirror = true;
520
- break;
521
-
522
- case MediaConstants_1.MultiPartyCameraTypes.FRONT:
523
- cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.BACK;
524
- deviceId = mediaCapabilitiesService.backCameraDeviceId;
525
- this.mirror = !MediaCapabilitiesUtils_1.checkIsMobile();
526
- break;
527
-
528
- default:
529
- throw new Error("cameraType not valid: " + this.settings.selectedCamera);
530
- }
531
-
532
- return [4
533
- /*yield*/
534
- , (_a = this.currentPublisher) === null || _a === void 0 ? void 0 : _a.setVideoSource(deviceId).then(function () {
535
- var _a, _b, _c, _d;
536
-
537
- _this.settings.selectedCamera = cameraSource_1;
538
-
539
- if (_this.mirror) {
540
- (_b = (_a = _this.currentPublisher) === null || _a === void 0 ? void 0 : _a.element) === null || _b === void 0 ? void 0 : _b.classList.add(OPENTOK_MIRRORED_CSS_CLASS);
541
- } else {
542
- (_d = (_c = _this.currentPublisher) === null || _c === void 0 ? void 0 : _c.element) === null || _d === void 0 ? void 0 : _d.classList.remove(OPENTOK_MIRRORED_CSS_CLASS);
543
- }
544
-
545
- var e = {
546
- cameraSource: cameraSource_1,
547
- mirror: _this.mirror
548
- };
549
-
550
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.cameraSourceChanged, e);
551
-
552
- trace.info("Success to switch camera to cameraSource: " + cameraSource_1);
553
- })];
554
-
555
- case 2:
556
- return [2
557
- /*return*/
558
- , _b.sent()];
559
-
560
- case 3:
561
- err_1 = _b.sent();
562
- trace.error(JSON.stringify(err_1));
563
- throw err_1;
564
-
565
- case 4:
566
- return [2
567
- /*return*/
568
- ];
569
- }
570
- });
571
- });
572
- };
573
-
574
- _this.initPublisher = function (settings) {
575
- return __awaiter(_this, void 0, void 0, function () {
576
- var selectedCamera, isMobile, mediaCapabilitiesService, frontCameraDeviceId, backCameraDeviceId, videoSourceId, mobileCameraType, err_2;
577
-
578
- var _this = this;
579
-
580
- var _a, _b, _c;
581
-
582
- return __generator(this, function (_d) {
583
- switch (_d.label) {
584
- case 0:
585
- _d.trys.push([0, 2,, 3]);
586
-
587
- selectedCamera = settings.selectedCamera;
588
- isMobile = MediaCapabilitiesUtils_1.checkIsMobile();
589
- return [4
590
- /*yield*/
591
- , MediaCapabilitiesService_1.MediaCapabilitiesService.getInstance()];
592
-
593
- case 1:
594
- mediaCapabilitiesService = _d.sent();
595
- frontCameraDeviceId = mediaCapabilitiesService.frontCameraDeviceId, backCameraDeviceId = mediaCapabilitiesService.backCameraDeviceId;
596
- videoSourceId = (selectedCamera === MediaConstants_1.MultiPartyCameraTypes.FRONT ? frontCameraDeviceId : backCameraDeviceId) || undefined;
597
- mobileCameraType = settings.selectedCamera === MediaConstants_1.MultiPartyCameraTypes.FRONT ? OpentokFacingMode.USER : OpentokFacingMode.ENVIRONMENT;
598
- this.mirror = !isMobile || settings.selectedCamera !== MediaConstants_1.MultiPartyCameraTypes.BACK;
599
- this.currentPublisher = OT.initPublisher(this.getParticipantId(((_b = (_a = this.session) === null || _a === void 0 ? void 0 : _a.connection) === null || _b === void 0 ? void 0 : _b.connectionId) || ''), {
600
- insertMode: 'append',
601
- fitMode: 'cover',
602
- width: '100%',
603
- height: '100%',
604
- style: {
605
- buttonDisplayMode: 'off',
606
- archiveStatusDisplayMode: 'off',
607
- audioLevelDisplayMode: 'off',
608
- backgroundImageURI: ((_c = this.branding) === null || _c === void 0 ? void 0 : _c.backgroundImageURI) || MultiPartyService_1.DEFAULT_AVATAR_URI
609
- },
610
- publishAudio: !settings.startWithAudioMuted,
611
- publishVideo: settings.cameraEnabled,
612
- videoSource: !isMobile ? videoSourceId : undefined,
613
- facingMode: isMobile || !videoSourceId ? mobileCameraType : undefined,
614
- mirror: this.mirror
615
- }, this.traceErrorCallback);
616
-
617
- if (!this.currentPublisher) {
618
- trace.error('failed to init publisher');
619
- } else {
620
- this.currentPublisher.on('videoElementCreated', function (event) {
621
- trace.info('videoElementCreated', event);
622
-
623
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.videoElementCreated);
624
- });
625
- this.currentPublisher.on('streamDestroyed', function (event) {
626
- trace.info('Publisher stream destroyed', event);
627
- var connection = event.stream.connection;
628
- var connectionId = connection.connectionId;
629
- var e = {
630
- participantId: _this.getParticipantId(connectionId),
631
- connectionId: connectionId,
632
- isOwnConnection: true,
633
- clientRole: _this.getClientRole(connection)
634
- };
635
-
636
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
637
- });
638
- this.currentPublisher.on('accessDenied', function () {
639
- trace.info('Publisher denied media permissions');
640
- var e = {
641
- isOwnConnection: true
642
- };
643
-
644
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, e);
645
- });
646
- this.currentPublisher.on('streamCreated', function (event) {
647
- return __awaiter(_this, void 0, void 0, function () {
648
- var _a, hasAudio, hasVideo, connectionId, participantId, clientRole, e;
649
-
650
- return __generator(this, function (_b) {
651
- switch (_b.label) {
652
- case 0:
653
- return [4
654
- /*yield*/
655
- , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
656
-
657
- case 1:
658
- _b.sent();
659
-
660
- _a = event.stream, hasAudio = _a.hasAudio, hasVideo = _a.hasVideo;
661
- connectionId = event.stream.connection.connectionId;
662
- participantId = this.getParticipantId(connectionId);
663
- clientRole = this.getClientRole(event.stream.connection);
664
- e = {
665
- participantId: participantId,
666
- clientRole: clientRole,
667
- connectionId: connectionId,
668
- hasVideo: hasVideo,
669
- hasAudio: hasAudio,
670
- isOwnConnection: true,
671
- audioEnabled: !this.settings.startWithAudioMuted,
672
- mirror: this.mirror
673
- };
674
- this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, e);
675
- trace.info('publisher stream created', {
676
- event: event,
677
- hasAudio: hasAudio,
678
- participantId: participantId
679
- });
680
- return [2
681
- /*return*/
682
- ];
683
- }
684
- });
685
- });
686
- });
687
- }
688
-
689
- return [3
690
- /*break*/
691
- , 3];
692
-
693
- case 2:
694
- err_2 = _d.sent();
695
- trace.error(JSON.stringify(err_2));
696
- throw err_2;
697
-
698
- case 3:
699
- return [2
700
- /*return*/
701
- ];
702
- }
465
+ return [2
466
+ /*return*/
467
+ , (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.switchCamera()];
703
468
  });
704
469
  });
705
470
  };
706
471
 
707
472
  _this.reinitializeStreams = function (settings) {
708
473
  return __awaiter(_this, void 0, void 0, function () {
709
- var _a;
474
+ var _a, _b;
710
475
 
711
- return __generator(this, function (_b) {
476
+ return __generator(this, function (_c) {
712
477
  if (!this.session) {
713
478
  return [2
714
479
  /*return*/
@@ -719,32 +484,26 @@ function (_super) {
719
484
  return s.subscriber;
720
485
  }).forEach((_a = this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
721
486
  this.subscriberList = [];
722
-
723
- if (this.currentPublisher) {
724
- this.currentPublisher.destroy();
725
- this.currentPublisher = undefined;
726
- }
727
-
487
+ (_b = this.publisher) === null || _b === void 0 ? void 0 : _b.destroy();
728
488
  return [2
729
489
  /*return*/
730
- , this.createPublisher(settings)];
490
+ , this.initPublisher(settings)];
731
491
  });
732
492
  });
733
493
  };
734
494
 
735
495
  _this.streamCreatedHandler = function (event) {
736
496
  return __awaiter(_this, void 0, void 0, function () {
737
- var stream, connection, connectionId, hasAudio, hasVideo, participantId, clientRole, subscriber, e;
497
+ var stream, connection, hasAudio, hasVideo, videoDimensions, connectionId, participantId, clientRole, subscriber;
738
498
  return __generator(this, function (_a) {
739
499
  switch (_a.label) {
740
500
  case 0:
741
501
  trace.info('streamCreatedHandler', event.stream);
742
502
  stream = event.stream;
743
- connection = stream.connection;
503
+ connection = stream.connection, hasAudio = stream.hasAudio, hasVideo = stream.hasVideo, videoDimensions = stream.videoDimensions;
744
504
  connectionId = connection.connectionId;
745
- hasAudio = stream.hasAudio, hasVideo = stream.hasVideo;
746
505
  participantId = this.getParticipantId(connectionId);
747
- clientRole = this.getClientRole(connection);
506
+ clientRole = OpentokUtils_1.getClientRole(connection);
748
507
  return [4
749
508
  /*yield*/
750
509
  , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
@@ -754,7 +513,7 @@ function (_super) {
754
513
 
755
514
  if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
756
515
  if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
757
- subscriber = this.createSubscriber(stream, connectionId);
516
+ subscriber = OpentokSubscriber_1.createSubscriber(this.session, stream, this.getParticipantId(connectionId), this.backgroundImageURI);
758
517
  this.subscriberList.push({
759
518
  subscriber: subscriber,
760
519
  connectionId: connectionId,
@@ -765,17 +524,16 @@ function (_super) {
765
524
  }
766
525
  }
767
526
 
768
- e = {
527
+ this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, {
769
528
  participantId: participantId,
770
529
  clientRole: clientRole,
771
530
  connectionId: connectionId,
772
531
  hasVideo: hasVideo,
773
532
  hasAudio: hasAudio,
774
533
  isOwnConnection: false,
775
- audioEnabled: !this.settings.startWithAudioMuted,
776
- mirror: false
777
- };
778
- this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, e);
534
+ mirror: false,
535
+ videoDimensions: videoDimensions
536
+ });
779
537
  return [2
780
538
  /*return*/
781
539
  ];
@@ -788,17 +546,16 @@ function (_super) {
788
546
  trace.info('streamDestroyedHandler', event);
789
547
  var connection = event.stream.connection;
790
548
  var connectionId = connection.connectionId;
791
- var e = {
792
- participantId: _this.getParticipantId(connectionId),
793
- connectionId: connectionId,
794
- isOwnConnection: false,
795
- clientRole: _this.getClientRole(connection)
796
- };
797
549
  _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
798
550
  return subscriber.connectionId !== connectionId;
799
551
  });
800
552
 
801
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
553
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, {
554
+ participantId: _this.getParticipantId(connectionId),
555
+ connectionId: connectionId,
556
+ isOwnConnection: false,
557
+ clientRole: OpentokUtils_1.getClientRole(connection)
558
+ });
802
559
  };
803
560
 
804
561
  _this.connectionCreatedHandler = function (event) {
@@ -810,28 +567,25 @@ function (_super) {
810
567
  return;
811
568
  }
812
569
 
813
- var e = {
814
- clientRole: _this.getClientRole(connection),
570
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionCreated, {
571
+ clientRole: OpentokUtils_1.getClientRole(connection),
815
572
  participantId: _this.getParticipantId(connectionId),
816
573
  connectionId: connectionId,
817
574
  isOwnConnection: _this.checkOwnConnection(connectionId)
818
- };
819
-
820
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionCreated, e);
575
+ });
821
576
  };
822
577
 
823
578
  _this.connectionDestroyedHandler = function (event) {
824
579
  var connection = event.connection;
825
580
  var connectionId = connection.connectionId;
826
581
  trace.info('connectionDestroyedHandler', event);
827
- var e = {
828
- clientRole: _this.getClientRole(connection),
582
+
583
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionDestroyed, {
584
+ clientRole: OpentokUtils_1.getClientRole(connection),
829
585
  participantId: _this.getParticipantId(connectionId),
830
586
  connectionId: connectionId,
831
587
  isOwnConnection: _this.checkOwnConnection(connectionId)
832
- };
833
-
834
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionDestroyed, e);
588
+ });
835
589
 
836
590
  if (connectionId !== _this.ownConnectionId || !_this.ownConnectionId) {
837
591
  return;
@@ -845,59 +599,29 @@ function (_super) {
845
599
  var _a = event.stream,
846
600
  hasVideo = _a.hasVideo,
847
601
  hasAudio = _a.hasAudio,
848
- connection = _a.connection;
602
+ connection = _a.connection,
603
+ videoDimensions = _a.videoDimensions;
849
604
  var connectionId = connection.connectionId;
850
- var e = {
605
+
606
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamPropertyChanged, {
851
607
  hasVideo: hasVideo,
852
608
  hasAudio: hasAudio,
853
609
  participantId: _this.getParticipantId(connectionId),
854
610
  connectionId: connectionId,
855
611
  isOwnConnection: _this.checkOwnConnection(connectionId),
856
- clientRole: _this.getClientRole(connection)
857
- };
858
-
859
- _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamPropertyChanged, e);
860
- };
861
-
862
- _this.traceErrorCallback = function (error) {
863
- trace.error(JSON.stringify(error));
612
+ clientRole: OpentokUtils_1.getClientRole(connection),
613
+ videoDimensions: videoDimensions
614
+ });
864
615
  };
865
616
 
866
617
  _this.sessionDisconnectedHandler = function (event) {
867
- trace.info('sessionDisconnectedHandler', event); // ToDo: Below line makes no sense (according to the OT types). This is not how OT signals work.
868
- // this?.session?.signal({ retryAfterReconnect: true });
869
- };
870
-
871
- _this.createSubscriber = function (stream, connectionId) {
872
- var _a; // ToDo: OT session can be undefined. This needs to be fixed.
873
-
874
-
875
- var subscriber = _this.session.subscribe(stream, _this.getParticipantId(connectionId), {
876
- insertMode: 'append',
877
- fitMode: 'cover',
878
- width: '100%',
879
- height: '100%',
880
- style: {
881
- buttonDisplayMode: 'off',
882
- audioLevelDisplayMode: 'off',
883
- videoDisabledDisplayMode: 'off',
884
- backgroundImageURI: ((_a = _this.branding) === null || _a === void 0 ? void 0 : _a.backgroundImageURI) || MultiPartyService_1.DEFAULT_AVATAR_URI
885
- }
886
- }, function (err) {
887
- _this.traceErrorCallback(err);
888
- });
889
-
890
- subscriber.on('videoElementCreated', function (event) {
891
- trace.info('videoElementCreated', event);
892
- });
893
- return subscriber;
618
+ trace.info('sessionDisconnectedHandler', event);
894
619
  };
895
620
 
896
621
  _this.checkOwnConnection = function (connectionId) {
897
622
  return _this.ownConnectionId !== undefined && _this.ownConnectionId === connectionId;
898
623
  };
899
624
 
900
- _this.branding = settings.branding;
901
625
  return _this;
902
626
  }
903
627
 
@@ -917,11 +641,6 @@ function (_super) {
917
641
  enumerable: false,
918
642
  configurable: true
919
643
  });
920
-
921
- OpentokMultiPartyService.prototype.getClientRole = function (connection) {
922
- return (connection === null || connection === void 0 ? void 0 : connection.data) && JSON.parse(connection.data).clientRole || MediaConstants_1.SessionClientRole.USER;
923
- };
924
-
925
644
  return OpentokMultiPartyService;
926
645
  }(MultiPartyService_1.MultiPartyService);
927
646