@techsee/techsee-media-service 7.0.2 → 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
 
@@ -477,7 +482,7 @@ function (_super) {
477
482
 
478
483
  _this.switchCamera = function () {
479
484
  return __awaiter(_this, void 0, void 0, function () {
480
- var mediaCapabilitiesService, deviceId, cameraType_1, err_1;
485
+ var mediaCapabilitiesService, deviceId, cameraSource_1, err_1;
481
486
 
482
487
  var _this = this;
483
488
 
@@ -503,12 +508,12 @@ function (_super) {
503
508
 
504
509
  switch (this.settings.selectedCamera) {
505
510
  case MediaConstants_1.MultiPartyCameraTypes.BACK:
506
- cameraType_1 = MediaConstants_1.MultiPartyCameraTypes.FRONT;
511
+ cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.FRONT;
507
512
  deviceId = mediaCapabilitiesService.frontCameraDeviceId;
508
513
  break;
509
514
 
510
515
  case MediaConstants_1.MultiPartyCameraTypes.FRONT:
511
- cameraType_1 = MediaConstants_1.MultiPartyCameraTypes.BACK;
516
+ cameraSource_1 = MediaConstants_1.MultiPartyCameraTypes.BACK;
512
517
  deviceId = mediaCapabilitiesService.backCameraDeviceId;
513
518
  break;
514
519
 
@@ -519,13 +524,15 @@ function (_super) {
519
524
  return [4
520
525
  /*yield*/
521
526
  , (_a = this.currentPublisher) === null || _a === void 0 ? void 0 : _a.setVideoSource(deviceId).then(function () {
522
- _this.settings.selectedCamera = cameraType_1;
527
+ _this.settings.selectedCamera = cameraSource_1;
528
+ var e = {
529
+ cameraSource: cameraSource_1,
530
+ mirror: true
531
+ };
523
532
 
524
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.cameraSourceChanged, {
525
- cameraSource: cameraType_1
526
- });
533
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.cameraSourceChanged, e);
527
534
 
528
- trace.info("Success to switch camera to cameraType: " + cameraType_1);
535
+ trace.info("Success to switch camera to cameraSource: " + cameraSource_1);
529
536
  })];
530
537
 
531
538
  case 2:
@@ -594,63 +601,61 @@ function (_super) {
594
601
  this.currentPublisher.on('videoElementCreated', function (event) {
595
602
  trace.info('videoElementCreated', event);
596
603
 
597
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.videoElementCreated, event);
604
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.videoElementCreated);
598
605
  });
599
606
  this.currentPublisher.on('streamDestroyed', function (event) {
600
- var _a;
601
-
602
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
+ };
603
616
 
604
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamDestroyed, {
605
- event: event,
606
- participantId: _this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId)
607
- });
617
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
608
618
  });
609
- this.currentPublisher.on('accessDenied', function (event) {
610
- var _a;
611
-
612
- trace.info('Publisher denied media permissions', event);
613
- var connection = (_a = _this.session) === null || _a === void 0 ? void 0 : _a.connection;
614
- var connectionId = connection === null || connection === void 0 ? void 0 : connection.connectionId;
615
-
616
- var participantId = _this.getParticipantId(connectionId);
619
+ this.currentPublisher.on('accessDenied', function () {
620
+ trace.info('Publisher denied media permissions');
621
+ var e = {
622
+ isOwnConnection: true
623
+ };
617
624
 
618
- var isOwnConnection = _this.ownConnectionId === connectionId;
619
-
620
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, {
621
- connectionId: connectionId,
622
- isOwnConnection: isOwnConnection,
623
- participantId: participantId
624
- });
625
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.mediaDeviceAccessDenied, e);
625
626
  });
626
627
  this.currentPublisher.on('streamCreated', function (event) {
627
628
  return __awaiter(_this, void 0, void 0, function () {
628
- var participantId;
629
-
630
- var _a, _b, _c, _d, _e, _f, _g;
629
+ var _a, hasAudio, hasVideo, connectionId, participantId, clientRole, e;
631
630
 
632
- return __generator(this, function (_h) {
633
- switch (_h.label) {
631
+ return __generator(this, function (_b) {
632
+ switch (_b.label) {
634
633
  case 0:
635
634
  return [4
636
635
  /*yield*/
637
636
  , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
638
637
 
639
638
  case 1:
640
- _h.sent();
639
+ _b.sent();
641
640
 
642
- participantId = this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId);
643
- this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamCreated, {
644
- 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 = {
645
646
  participantId: participantId,
646
- startWithAudioMuted: this.settings.startWithAudioMuted,
647
- hasAudio: (_b = event === null || event === void 0 ? void 0 : event.stream) === null || _b === void 0 ? void 0 : _b.hasAudio,
648
- hasVideo: (_c = event === null || event === void 0 ? void 0 : event.stream) === null || _c === void 0 ? void 0 : _c.hasVideo,
649
- 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)
650
- });
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);
651
656
  trace.info('publisher stream created', {
652
657
  event: event,
653
- hasAudio: (_g = (_f = this.currentPublisher) === null || _f === void 0 ? void 0 : _f.stream) === null || _g === void 0 ? void 0 : _g.hasAudio,
658
+ hasAudio: hasAudio,
654
659
  participantId: participantId
655
660
  });
656
661
  return [2
@@ -682,68 +687,51 @@ function (_super) {
682
687
 
683
688
  _this.reinitializeStreams = function (settings) {
684
689
  return __awaiter(_this, void 0, void 0, function () {
685
- var _this = this;
686
-
687
- return __generator(this, function (_a) {
688
- switch (_a.label) {
689
- case 0:
690
- if (!this.session) {
691
- return [2
692
- /*return*/
693
- ];
694
- }
695
-
696
- if (this.currentPublisher) {
697
- this.currentPublisher.destroy();
698
- this.currentPublisher = undefined;
699
- }
700
-
701
- return [4
702
- /*yield*/
703
- , this.createPublisher(settings)];
690
+ var _a;
704
691
 
705
- case 1:
706
- _a.sent();
692
+ return __generator(this, function (_b) {
693
+ if (!this.session) {
694
+ return [2
695
+ /*return*/
696
+ ];
697
+ }
707
698
 
708
- this.subscriberList = this.subscriberList.map(function (s) {
709
- 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 = [];
710
703
 
711
- var connectionId = s.connectionId,
712
- subscriber = s.subscriber;
713
- var stream = subscriber.stream;
714
- (_a = _this.session) === null || _a === void 0 ? void 0 : _a.unsubscribe(subscriber);
715
- return __assign(__assign({}, s), {
716
- subscriber: _this.createSubscriber(stream, connectionId)
717
- });
718
- });
719
- return [2
720
- /*return*/
721
- ];
704
+ if (this.currentPublisher) {
705
+ this.currentPublisher.destroy();
706
+ this.currentPublisher = undefined;
722
707
  }
708
+
709
+ return [2
710
+ /*return*/
711
+ , this.createPublisher(settings)];
723
712
  });
724
713
  });
725
714
  };
726
715
 
727
716
  _this.streamCreatedHandler = function (event) {
728
717
  return __awaiter(_this, void 0, void 0, function () {
729
- var stream, connection, connectionId, participantId, subscriber;
730
-
731
- var _a, _b;
732
-
733
- return __generator(this, function (_c) {
734
- switch (_c.label) {
718
+ var stream, connection, connectionId, hasAudio, hasVideo, participantId, clientRole, subscriber, e;
719
+ return __generator(this, function (_a) {
720
+ switch (_a.label) {
735
721
  case 0:
736
722
  trace.info('streamCreatedHandler', event.stream);
737
723
  stream = event.stream;
738
724
  connection = stream.connection;
739
725
  connectionId = connection.connectionId;
726
+ hasAudio = stream.hasAudio, hasVideo = stream.hasVideo;
740
727
  participantId = this.getParticipantId(connectionId);
728
+ clientRole = this.getClientRole(connection);
741
729
  return [4
742
730
  /*yield*/
743
731
  , MediaCapabilitiesService_1.MediaCapabilitiesService.setDevicesList()];
744
732
 
745
733
  case 1:
746
- _c.sent();
734
+ _a.sent();
747
735
 
748
736
  if (this.ownConnectionId && stream && connectionId !== this.ownConnectionId) {
749
737
  if (this.subscriberList.length < MultiPartyService_1.maxParticipantsNumber - 1) {
@@ -751,21 +739,24 @@ function (_super) {
751
739
  this.subscriberList.push({
752
740
  subscriber: subscriber,
753
741
  connectionId: connectionId,
754
- clientRole: this.getClientRole(connection)
742
+ clientRole: clientRole
755
743
  });
756
744
  } else {
757
745
  trace.info("a new subscriber cannot be added, as the number of participants reached its limit: " + MultiPartyService_1.maxParticipantsNumber);
758
746
  }
759
747
  }
760
748
 
761
- this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamCreated, {
762
- event: event,
749
+ e = {
763
750
  participantId: participantId,
764
- startWithAudioMuted: this.settings.startWithAudioMuted,
765
- isOwnConnection: this.ownConnectionId === connectionId,
766
- hasVideo: (_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.hasVideo,
767
- hasAudio: (_b = event === null || event === void 0 ? void 0 : event.stream) === null || _b === void 0 ? void 0 : _b.hasAudio
768
- });
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);
769
760
  return [2
770
761
  /*return*/
771
762
  ];
@@ -774,80 +765,81 @@ function (_super) {
774
765
  });
775
766
  };
776
767
 
777
- _this.streamPropertyChangedHandler = function (event) {
778
- var _a;
779
-
780
- trace.info('streamPropertyChangedHandler', event);
781
- var stream = event.stream;
782
-
783
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.videoAudioStatus, {
784
- hasVideo: stream === null || stream === void 0 ? void 0 : stream.hasVideo,
785
- hasAudio: stream === null || stream === void 0 ? void 0 : stream.hasAudio,
786
- participantId: _this.getParticipantId(stream === null || stream === void 0 ? void 0 : stream.connection.connectionId),
787
- isOwnConnection: _this.ownConnectionId === ((_a = stream === null || stream === void 0 ? void 0 : stream.connection) === null || _a === void 0 ? void 0 : _a.connectionId),
788
- stream: stream
789
- });
790
- };
791
-
792
768
  _this.streamDestroyedHandler = function (event) {
793
- var _a;
794
-
795
769
  trace.info('streamDestroyedHandler', event);
796
- var stream = event.stream;
797
- 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
+ };
798
778
  _this.subscriberList = _this.subscriberList.filter(function (subscriber) {
799
- return subscriber.connectionId !== destroyedConnectionId;
779
+ return subscriber.connectionId !== connectionId;
800
780
  });
801
781
 
802
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.streamDestroyed, {
803
- event: event,
804
- participantId: _this.getParticipantId((_a = event === null || event === void 0 ? void 0 : event.stream) === null || _a === void 0 ? void 0 : _a.connection.connectionId)
805
- });
782
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.streamDestroyed, e);
806
783
  };
807
784
 
808
785
  _this.connectionCreatedHandler = function (event) {
809
786
  trace.info('connectionCreatedHandler', event);
810
787
  var connection = event.connection;
788
+ var connectionId = connection.connectionId;
811
789
 
812
790
  if (!_this.ownConnectionId || !connection) {
813
791
  return;
814
792
  }
815
793
 
816
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.participantsNumberChanged, _this.subscriberList.length);
817
-
818
- 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
+ };
819
800
 
820
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectionCreated, {
821
- clientRole: clientRole,
822
- event: event,
823
- participantId: _this.getParticipantId(connection.connectionId),
824
- isOwnConnection: _this.ownConnectionId === connection.connectionId
825
- });
801
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionCreated, e);
826
802
  };
827
803
 
828
804
  _this.connectionDestroyedHandler = function (event) {
829
805
  var connection = event.connection;
830
-
831
- var clientRole = _this.getClientRole(connection);
832
-
806
+ var connectionId = connection.connectionId;
833
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
+ };
834
814
 
835
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.connectionDestroyed, {
836
- clientRole: clientRole,
837
- event: event,
838
- participantId: _this.getParticipantId(event === null || event === void 0 ? void 0 : event.connection.connectionId),
839
- isOwnConnection: _this.ownConnectionId === connection.connectionId
840
- });
815
+ _this.emit(MultipartyServiceEventTypes_1.MULTI_PARTY_EVENTS.connectionDestroyed, e);
841
816
 
842
- if (!_this.ownConnectionId || !connection || connection.connectionId !== _this.ownConnectionId) {
817
+ if (connectionId !== _this.ownConnectionId || !_this.ownConnectionId) {
843
818
  return;
844
819
  }
845
820
 
846
- _this.emit(MultiPartyService_1.MULTI_PARTY_EVENTS.participantsNumberChanged, _this.subscriberList.length);
847
-
848
821
  _this.session = undefined;
849
822
  };
850
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
+
851
843
  _this.traceErrorCallback = function (error) {
852
844
  trace.error(JSON.stringify(error));
853
845
  };
@@ -874,15 +866,18 @@ function (_super) {
874
866
  }
875
867
  }, function (err) {
876
868
  _this.traceErrorCallback(err);
877
-
878
- subscriber === null || subscriber === void 0 ? void 0 : subscriber.on('videoElementCreated', function (event) {
879
- trace.info('videoElementCreated', event);
880
- });
881
869
  });
882
870
 
871
+ subscriber.on('videoElementCreated', function (event) {
872
+ trace.info('videoElementCreated', event);
873
+ });
883
874
  return subscriber;
884
875
  };
885
876
 
877
+ _this.checkOwnConnection = function (connectionId) {
878
+ return _this.ownConnectionId !== undefined && _this.ownConnectionId === connectionId;
879
+ };
880
+
886
881
  _this.branding = settings.branding;
887
882
  return _this;
888
883
  }