@techsee/techsee-media-service 7.0.1 → 8.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.
@@ -214,6 +214,8 @@ var MediaCapabilitiesUtils_1 = require("./MediaCapabilitiesUtils");
214
214
 
215
215
  var MultiPartyService_1 = require("./MultiPartyService");
216
216
 
217
+ var MultipartyServiceEventTypes_1 = require("./MultipartyServiceEventTypes");
218
+
217
219
  var trace = MediaUtils_1.getMediaTracer('Multiparty'); // The preferred camera position to use for the video source
218
220
 
219
221
  var OpentokFacingMode;
@@ -259,11 +261,13 @@ function (_super) {
259
261
 
260
262
  _this.traceErrorCallback(error);
261
263
 
262
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectFailed, {
264
+ var e = {
263
265
  meta: {
264
266
  err: JSON.stringify(error)
265
267
  }
266
- });
268
+ };
269
+
270
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, e);
267
271
 
268
272
  return;
269
273
  }
@@ -272,12 +276,13 @@ function (_super) {
272
276
  });
273
277
  } catch (err) {
274
278
  trace.error(JSON.stringify(err));
275
-
276
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectFailed, {
279
+ var e = {
277
280
  meta: {
278
281
  err: JSON.stringify(err)
279
282
  }
280
- });
283
+ };
284
+
285
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectFailed, e);
281
286
  }
282
287
  };
283
288
 
@@ -320,6 +325,12 @@ function (_super) {
320
325
  return __generator(this, function (_b) {
321
326
  switch (_b.label) {
322
327
  case 0:
328
+ if (!this.session) {
329
+ return [2
330
+ /*return*/
331
+ ];
332
+ }
333
+
323
334
  return [4
324
335
  /*yield*/
325
336
  , MediaCapabilitiesUtils_1.checkAudioCapabilities()];
@@ -471,7 +482,7 @@ function (_super) {
471
482
 
472
483
  _this.switchCamera = function () {
473
484
  return __awaiter(_this, void 0, void 0, function () {
474
- var mediaCapabilitiesService, deviceId, cameraType_1, err_1;
485
+ var mediaCapabilitiesService, deviceId, cameraSource_1, err_1;
475
486
 
476
487
  var _this = this;
477
488
 
@@ -497,12 +508,12 @@ function (_super) {
497
508
 
498
509
  switch (this.settings.selectedCamera) {
499
510
  case MediaConstants_1.MultiPartyCameraTypes.BACK:
500
- cameraType_1 = MediaConstants_1.MultiPartyCameraTypes.FRONT;
511
+ cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.FRONT;
501
512
  deviceId = mediaCapabilitiesService.frontCameraDeviceId;
502
513
  break;
503
514
 
504
515
  case MediaConstants_1.MultiPartyCameraTypes.FRONT:
505
- cameraType_1 = MediaConstants_1.MultiPartyCameraTypes.BACK;
516
+ cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.BACK;
506
517
  deviceId = mediaCapabilitiesService.backCameraDeviceId;
507
518
  break;
508
519
 
@@ -513,13 +524,15 @@ function (_super) {
513
524
  return [4
514
525
  /*yield*/
515
526
  , (_a = this.currentPublisher) === null || _a === void 0 ? void 0 : _a.setVideoSource(deviceId).then(function () {
516
- _this.settings.selectedCamera = cameraType_1;
527
+ _this.settings.selectedCamera = cameraSource_1;
528
+ var e = {
529
+ cameraSource: cameraSource_1,
530
+ mirror: true
531
+ };
517
532
 
518
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.cameraSourceChanged, {
519
- cameraSource: cameraType_1
520
- });
533
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.cameraSourceChanged, e);
521
534
 
522
- trace.info("Success to switch camera to cameraType: " + cameraType_1);
535
+ trace.info("Success to switch camera to cameraSource: " + cameraSource_1);
523
536
  })];
524
537
 
525
538
  case 2:
@@ -588,63 +601,61 @@ function (_super) {
588
601
  this.currentPublisher.on('videoElementCreated', function (event) {
589
602
  trace.info('videoElementCreated', event);
590
603
 
591
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.videoElementCreated, event);
604
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.videoElementCreated);
592
605
  });
593
606
  this.currentPublisher.on('streamDestroyed', function (event) {
594
- var _a;
595
-
596
607
  trace.info('Publisher stream destroyed', event);
608
+ var connection = event.stream.connection;
609
+ var connectionId = connection.connectionId;
610
+ var e = {
611
+ participantId: _this.getParticipantId(connectionId),
612
+ connectionId: connectionId,
613
+ isOwnConnection: true,
614
+ clientRole: _this.getClientRole(connection)
615
+ };
597
616
 
598
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamDestroyed, {
599
- event: event,
600
- participantId: _this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId)
601
- });
617
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
602
618
  });
603
- this.currentPublisher.on('accessDenied', function (event) {
604
- var _a;
605
-
606
- trace.info('Publisher denied media permissions', event);
607
- var connection = (_a = _this.session) === null || _a === void 0 ? void 0 : _a.connection;
608
- var connectionId = connection === null || connection === void 0 ? void 0 : connection.connectionId;
609
-
610
- var participantId = _this.getParticipantId(connectionId);
611
-
612
- var isOwnConnection = _this.ownConnectionId === connectionId;
619
+ this.currentPublisher.on('accessDenied', function () {
620
+ trace.info('Publisher denied media permissions');
621
+ var e = {
622
+ isOwnConnection: true
623
+ };
613
624
 
614
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, {
615
- connectionId: connectionId,
616
- isOwnConnection: isOwnConnection,
617
- participantId: participantId
618
- });
625
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, e);
619
626
  });
620
627
  this.currentPublisher.on('streamCreated', function (event) {
621
628
  return __awaiter(_this, void 0, void 0, function () {
622
- var participantId;
623
-
624
- var _a, _b, _c, _d, _e, _f, _g;
629
+ var _a, hasAudio, hasVideo, connectionId, participantId, clientRole, e;
625
630
 
626
- return __generator(this, function (_h) {
627
- switch (_h.label) {
631
+ return __generator(this, function (_b) {
632
+ switch (_b.label) {
628
633
  case 0:
629
634
  return [4
630
635
  /*yield*/
631
636
  , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
632
637
 
633
638
  case 1:
634
- _h.sent();
639
+ _b.sent();
635
640
 
636
- participantId = this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId);
637
- this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamCreated, {
638
- event: event,
641
+ _a = event.stream, hasAudio = _a.hasAudio, hasVideo = _a.hasVideo;
642
+ connectionId = event.stream.connection.connectionId;
643
+ participantId = this.getParticipantId(connectionId);
644
+ clientRole = this.getClientRole(event.stream.connection);
645
+ e = {
639
646
  participantId: participantId,
640
- startWithAudioMuted: this.settings.startWithAudioMuted,
641
- hasAudio: (_b = event === null || event === void 0 ? void 0 : event.stream) === null || _b === void 0 ? void 0 : _b.hasAudio,
642
- hasVideo: (_c = event === null || event === void 0 ? void 0 : event.stream) === null || _c === void 0 ? void 0 : _c.hasVideo,
643
- isOwnConnection: this.ownConnectionId === ((_e = (_d = event === null || event === void 0 ? void 0 : event.stream) === null || _d === void 0 ? void 0 : _d.connection) === null || _e === void 0 ? void 0 : _e.connectionId)
644
- });
647
+ clientRole: clientRole,
648
+ connectionId: connectionId,
649
+ hasVideo: hasVideo,
650
+ hasAudio: hasAudio,
651
+ isOwnConnection: true,
652
+ audioEnabled: !this.settings.startWithAudioMuted,
653
+ mirror: true
654
+ };
655
+ this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, e);
645
656
  trace.info('publisher stream created', {
646
657
  event: event,
647
- hasAudio: (_g = (_f = this.currentPublisher) === null || _f === void 0 ? void 0 : _f.stream) === null || _g === void 0 ? void 0 : _g.hasAudio,
658
+ hasAudio: hasAudio,
648
659
  participantId: participantId
649
660
  });
650
661
  return [2
@@ -676,62 +687,51 @@ function (_super) {
676
687
 
677
688
  _this.reinitializeStreams = function (settings) {
678
689
  return __awaiter(_this, void 0, void 0, function () {
679
- var _this = this;
680
-
681
- return __generator(this, function (_a) {
682
- switch (_a.label) {
683
- case 0:
684
- if (this.currentPublisher) {
685
- this.currentPublisher.destroy();
686
- this.currentPublisher = undefined;
687
- }
688
-
689
- return [4
690
- /*yield*/
691
- , this.createPublisher(settings)];
690
+ var _a;
692
691
 
693
- case 1:
694
- _a.sent();
692
+ return __generator(this, function (_b) {
693
+ if (!this.session) {
694
+ return [2
695
+ /*return*/
696
+ ];
697
+ }
695
698
 
696
- this.subscriberList = this.subscriberList.map(function (s) {
697
- var _a;
699
+ this.subscriberList.map(function (s) {
700
+ return s.subscriber;
701
+ }).forEach((_a = this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe);
702
+ this.subscriberList = [];
698
703
 
699
- var connectionId = s.connectionId,
700
- subscriber = s.subscriber;
701
- var stream = subscriber.stream;
702
- (_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe(subscriber);
703
- return __assign(__assign({}, s), {
704
- subscriber: _this.createSubscriber(stream, connectionId)
705
- });
706
- });
707
- return [2
708
- /*return*/
709
- ];
704
+ if (this.currentPublisher) {
705
+ this.currentPublisher.destroy();
706
+ this.currentPublisher = undefined;
710
707
  }
708
+
709
+ return [2
710
+ /*return*/
711
+ , this.createPublisher(settings)];
711
712
  });
712
713
  });
713
714
  };
714
715
 
715
716
  _this.streamCreatedHandler = function (event) {
716
717
  return __awaiter(_this, void 0, void 0, function () {
717
- var stream, connection, connectionId, participantId, subscriber;
718
-
719
- var _a, _b;
720
-
721
- return __generator(this, function (_c) {
722
- switch (_c.label) {
718
+ var stream, connection, connectionId, hasAudio, hasVideo, participantId, clientRole, subscriber, e;
719
+ return __generator(this, function (_a) {
720
+ switch (_a.label) {
723
721
  case 0:
724
722
  trace.info('streamCreatedHandler', event.stream);
725
723
  stream = event.stream;
726
724
  connection = stream.connection;
727
725
  connectionId = connection.connectionId;
726
+ hasAudio = stream.hasAudio, hasVideo = stream.hasVideo;
728
727
  participantId = this.getParticipantId(connectionId);
728
+ clientRole = this.getClientRole(connection);
729
729
  return [4
730
730
  /*yield*/
731
731
  , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
732
732
 
733
733
  case 1:
734
- _c.sent();
734
+ _a.sent();
735
735
 
736
736
  if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
737
737
  if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
@@ -739,21 +739,24 @@ function (_super) {
739
739
  this.subscriberList.push({
740
740
  subscriber: subscriber,
741
741
  connectionId: connectionId,
742
- clientRole: this.getClientRole(connection)
742
+ clientRole: clientRole
743
743
  });
744
744
  } else {
745
745
  trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiPartyService_1.maxParticipantsNumber);
746
746
  }
747
747
  }
748
748
 
749
- this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamCreated, {
750
- event: event,
749
+ e = {
751
750
  participantId: participantId,
752
- startWithAudioMuted: this.settings.startWithAudioMuted,
753
- isOwnConnection: this.ownConnectionId === connectionId,
754
- hasVideo: (_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.hasVideo,
755
- hasAudio: (_b = event === null || event === void 0 ? void 0 : event.stream) === null || _b === void 0 ? void 0 : _b.hasAudio
756
- });
751
+ clientRole: clientRole,
752
+ connectionId: connectionId,
753
+ hasVideo: hasVideo,
754
+ hasAudio: hasAudio,
755
+ isOwnConnection: false,
756
+ audioEnabled: !this.settings.startWithAudioMuted,
757
+ mirror: true
758
+ };
759
+ this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamCreated, e);
757
760
  return [2
758
761
  /*return*/
759
762
  ];
@@ -762,80 +765,81 @@ function (_super) {
762
765
  });
763
766
  };
764
767
 
765
- _this.streamPropertyChangedHandler = function (event) {
766
- var _a;
767
-
768
- trace.info('streamPropertyChangedHandler', event);
769
- var stream = event.stream;
770
-
771
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.videoAudioStatus, {
772
- hasVideo: stream === null || stream === void 0 ? void 0 : stream.hasVideo,
773
- hasAudio: stream === null || stream === void 0 ? void 0 : stream.hasAudio,
774
- participantId: _this.getParticipantId(stream === null || stream === void 0 ? void 0 : stream.connection.connectionId),
775
- isOwnConnection: _this.ownConnectionId === ((_a = stream === null || stream === void 0 ? void 0 : stream.connection) === null || _a === void 0 ? void 0 : _a.connectionId),
776
- stream: stream
777
- });
778
- };
779
-
780
768
  _this.streamDestroyedHandler = function (event) {
781
- var _a;
782
-
783
769
  trace.info('streamDestroyedHandler', event);
784
- var stream = event.stream;
785
- var destroyedConnectionId = stream && stream.connection && stream.connection.connectionId;
770
+ var connection = event.stream.connection;
771
+ var connectionId = connection.connectionId;
772
+ var e = {
773
+ participantId: _this.getParticipantId(connectionId),
774
+ connectionId: connectionId,
775
+ isOwnConnection: false,
776
+ clientRole: _this.getClientRole(connection)
777
+ };
786
778
  _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
787
- return subscriber.connectionId !== destroyedConnectionId;
779
+ return subscriber.connectionId !== connectionId;
788
780
  });
789
781
 
790
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamDestroyed, {
791
- event: event,
792
- participantId: _this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId)
793
- });
782
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
794
783
  };
795
784
 
796
785
  _this.connectionCreatedHandler = function (event) {
797
786
  trace.info('connectionCreatedHandler', event);
798
787
  var connection = event.connection;
788
+ var connectionId = connection.connectionId;
799
789
 
800
790
  if (!_this.ownConnectionId || !connection) {
801
791
  return;
802
792
  }
803
793
 
804
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.participantsNumberChanged, _this.subscriberList.length);
805
-
806
- var clientRole = _this.getClientRole(connection);
794
+ var e = {
795
+ clientRole: _this.getClientRole(connection),
796
+ participantId: _this.getParticipantId(connectionId),
797
+ connectionId: connectionId,
798
+ isOwnConnection: _this.checkOwnConnection(connectionId)
799
+ };
807
800
 
808
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectionCreated, {
809
- clientRole: clientRole,
810
- event: event,
811
- participantId: _this.getParticipantId(connection.connectionId),
812
- isOwnConnection: _this.ownConnectionId === connection.connectionId
813
- });
801
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionCreated, e);
814
802
  };
815
803
 
816
804
  _this.connectionDestroyedHandler = function (event) {
817
805
  var connection = event.connection;
818
-
819
- var clientRole = _this.getClientRole(connection);
820
-
806
+ var connectionId = connection.connectionId;
821
807
  trace.info('connectionDestroyedHandler', event);
808
+ var e = {
809
+ clientRole: _this.getClientRole(connection),
810
+ participantId: _this.getParticipantId(connectionId),
811
+ connectionId: connectionId,
812
+ isOwnConnection: _this.checkOwnConnection(connectionId)
813
+ };
822
814
 
823
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectionDestroyed, {
824
- clientRole: clientRole,
825
- event: event,
826
- participantId: _this.getParticipantId(event === null || event === void 0 ? void 0 : event.connection.connectionId),
827
- isOwnConnection: _this.ownConnectionId === connection.connectionId
828
- });
815
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionDestroyed, e);
829
816
 
830
- if (!_this.ownConnectionId || !connection || connection.connectionId !== _this.ownConnectionId) {
817
+ if (connectionId !== _this.ownConnectionId || !_this.ownConnectionId) {
831
818
  return;
832
819
  }
833
820
 
834
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.participantsNumberChanged, _this.subscriberList.length);
835
-
836
821
  _this.session = undefined;
837
822
  };
838
823
 
824
+ _this.streamPropertyChangedHandler = function (event) {
825
+ trace.info('streamPropertyChangedHandler', event);
826
+ var _a = event.stream,
827
+ hasVideo = _a.hasVideo,
828
+ hasAudio = _a.hasAudio,
829
+ connection = _a.connection;
830
+ var connectionId = connection.connectionId;
831
+ var e = {
832
+ hasVideo: hasVideo,
833
+ hasAudio: hasAudio,
834
+ participantId: _this.getParticipantId(connectionId),
835
+ connectionId: connectionId,
836
+ isOwnConnection: _this.checkOwnConnection(connectionId),
837
+ clientRole: _this.getClientRole(connection)
838
+ };
839
+
840
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamPropertyChanged, e);
841
+ };
842
+
839
843
  _this.traceErrorCallback = function (error) {
840
844
  trace.error(JSON.stringify(error));
841
845
  };
@@ -862,15 +866,18 @@ function (_super) {
862
866
  }
863
867
  }, function (err) {
864
868
  _this.traceErrorCallback(err);
865
-
866
- subscriber === null || subscriber === void 0 ? void 0 : subscriber.on('videoElementCreated', function (event) {
867
- trace.info('videoElementCreated', event);
868
- });
869
869
  });
870
870
 
871
+ subscriber.on('videoElementCreated', function (event) {
872
+ trace.info('videoElementCreated', event);
873
+ });
871
874
  return subscriber;
872
875
  };
873
876
 
877
+ _this.checkOwnConnection = function (connectionId) {
878
+ return _this.ownConnectionId !== undefined && _this.ownConnectionId === connectionId;
879
+ };
880
+
874
881
  _this.branding = settings.branding;
875
882
  return _this;
876
883
  }