@tencentcloud/trtc-cloud-wx 0.0.19 → 0.0.20-beta.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/trtc-cloud-wx.js +770 -336
package/trtc-cloud-wx.js CHANGED
@@ -620,9 +620,102 @@ exports.TRTCBeautyStyle = void 0;
620
620
  TRTCBeautyStyle[TRTCBeautyStyle["TRTCBeautyStyleNature"] = 1] = "TRTCBeautyStyleNature";
621
621
  })(exports.TRTCBeautyStyle || (exports.TRTCBeautyStyle = {}));
622
622
 
623
+ var Handletype;
624
+ (function (Handletype) {
625
+ Handletype["setPusher"] = "setPusher";
626
+ Handletype["setPlayer"] = "setPlayer";
627
+ })(Handletype || (Handletype = {}));
628
+ // 数字越高,set优先级越高
629
+ var TaskMap = {
630
+ enterRoom: {
631
+ priority: 0,
632
+ type: Handletype.setPusher
633
+ },
634
+ switchRole: {
635
+ priority: 1,
636
+ type: Handletype.setPusher
637
+ },
638
+ startLocalPreview: {
639
+ priority: 0,
640
+ type: Handletype.setPusher
641
+ },
642
+ stopLocalPreview: {
643
+ priority: 0,
644
+ type: Handletype.setPusher
645
+ },
646
+ muteLocalVideo: {
647
+ priority: 1,
648
+ type: Handletype.setPusher
649
+ },
650
+ setVideoEncoderParam: {
651
+ priority: 0,
652
+ type: Handletype.setPusher
653
+ },
654
+ setLocalRenderParams: {
655
+ priority: 0,
656
+ type: Handletype.setPusher
657
+ },
658
+ startLocalAudio: {
659
+ priority: 0,
660
+ type: Handletype.setPusher
661
+ },
662
+ stopLocalAudio: {
663
+ priority: 0,
664
+ type: Handletype.setPusher
665
+ },
666
+ muteLocalAudio: {
667
+ priority: 1,
668
+ type: Handletype.setPusher
669
+ },
670
+ switchCamera: {
671
+ priority: 0,
672
+ type: Handletype.setPusher
673
+ },
674
+ setBeautyStyle: {
675
+ priority: 0,
676
+ type: Handletype.setPusher
677
+ },
678
+ exitRoom: {
679
+ priority: 9,
680
+ type: Handletype.setPusher
681
+ },
682
+ startRemoteView: {
683
+ priority: 0,
684
+ type: Handletype.setPlayer
685
+ },
686
+ updateRemoteView: {
687
+ priority: 0,
688
+ type: Handletype.setPlayer
689
+ },
690
+ stopAllRemoteView: {
691
+ priority: 1,
692
+ type: Handletype.setPlayer
693
+ },
694
+ muteRemoteVideoStream: {
695
+ priority: 1,
696
+ type: Handletype.setPlayer
697
+ },
698
+ muteAllRemoteVideoStreams: {
699
+ priority: 1,
700
+ type: Handletype.setPlayer
701
+ },
702
+ setRemoteRenderParams: {
703
+ priority: 0,
704
+ type: Handletype.setPlayer
705
+ },
706
+ muteRemoteAudio: {
707
+ priority: 1,
708
+ type: Handletype.setPlayer
709
+ },
710
+ muteAllRemoteAudio: {
711
+ priority: 1,
712
+ type: Handletype.setPlayer
713
+ }
714
+ };
623
715
  var Task = /*#__PURE__*/function () {
624
716
  function Task(optinos) {
625
717
  _classCallCheck(this, Task);
718
+ var _a;
626
719
  var _optinos$priority = optinos.priority,
627
720
  priority = _optinos$priority === void 0 ? 0 : _optinos$priority,
628
721
  action = optinos.action,
@@ -639,6 +732,7 @@ var Task = /*#__PURE__*/function () {
639
732
  this.reject = reject;
640
733
  this.name = name;
641
734
  this.single = this.whetherSingle(name);
735
+ this.type = ((_a = TaskMap[name]) === null || _a === void 0 ? void 0 : _a.type) || Handletype.setPusher;
642
736
  this.sequenceNumber = Task.nextSequenceNumber++;
643
737
  }
644
738
  _createClass(Task, [{
@@ -655,22 +749,6 @@ var Task = /*#__PURE__*/function () {
655
749
  return Task;
656
750
  }();
657
751
  Task.nextSequenceNumber = 0;
658
- // 数字越高,set优先级越高
659
- var TaskPriorityMap = {
660
- enterRoom: 0,
661
- switchRole: 1,
662
- startLocalPreview: 0,
663
- stopLocalPreview: 0,
664
- muteLocalVideo: 1,
665
- setVideoEncoderParam: 0,
666
- setLocalRenderParams: 0,
667
- startLocalAudio: 0,
668
- stopLocalAudio: 0,
669
- muteLocalAudio: 1,
670
- switchCamera: 0,
671
- setBeautyStyle: 0,
672
- exitRoom: 9
673
- };
674
752
  var TaskQueueState;
675
753
  (function (TaskQueueState) {
676
754
  TaskQueueState["IDLE"] = "idle";
@@ -686,13 +764,11 @@ var TaskQueueEvent;
686
764
  var TaskMachine = /*#__PURE__*/function () {
687
765
  function TaskMachine() {
688
766
  _classCallCheck(this, TaskMachine);
689
- this.isProcessing = false; // 添加一个标志以跟踪任务是否正在处理
767
+ this.isProcessing = false; // 表示 pusherTaskQueue 是否正在处理
690
768
  this.pusherDomReady = false;
769
+ this.pusherTaskQueue = []; // 存储所有 pusher 任务
770
+ this.playerTasks = {}; // 存储每个 player 的任务队列
691
771
  this.state = TaskQueueState.IDLE;
692
- this.context = {
693
- taskQueue: [],
694
- debounceTimeout: null
695
- };
696
772
  }
697
773
  _createClass(TaskMachine, [{
698
774
  key: "setPusherDomReady",
@@ -700,19 +776,42 @@ var TaskMachine = /*#__PURE__*/function () {
700
776
  this.pusherDomReady = isReady;
701
777
  return this.pusherDomReady;
702
778
  }
779
+ }, {
780
+ key: "setPlayerDomReady",
781
+ value: function setPlayerDomReady(view, isReady) {
782
+ if (!this.playerTasks[view]) {
783
+ this.playerTasks[view] = {
784
+ taskQueue: [],
785
+ isProcessing: false,
786
+ domReady: false
787
+ };
788
+ }
789
+ this.playerTasks[view].domReady = isReady;
790
+ if (isReady) {
791
+ this.processPlayerTasks(view);
792
+ }
793
+ }
703
794
  }, {
704
795
  key: "send",
705
- value: function send(event) {
796
+ value: function send(event, view) {
706
797
  switch (this.state) {
707
798
  case TaskQueueState.IDLE:
708
799
  if (event === TaskQueueEvent.SET) {
709
800
  this.state = TaskQueueState.PENDING;
710
- this.processTasks();
801
+ if (view) {
802
+ this.processPlayerTasks(view);
803
+ } else {
804
+ this.processPusherTasks();
805
+ }
711
806
  }
712
807
  break;
713
808
  case TaskQueueState.PENDING:
714
809
  if (event === TaskQueueEvent.SETPROCESS) {
715
- this.processTasks();
810
+ if (view) {
811
+ this.processPlayerTasks(view);
812
+ } else {
813
+ this.processPusherTasks();
814
+ }
716
815
  }
717
816
  if (event === TaskQueueEvent.SETDONE) {
718
817
  this.state = TaskQueueState.IDLE;
@@ -728,43 +827,81 @@ var TaskMachine = /*#__PURE__*/function () {
728
827
  }, {
729
828
  key: "addTask",
730
829
  value: function addTask(task) {
731
- this.addTaskToQueue(task);
732
- if (this.state === TaskQueueState.IDLE) {
830
+ if (task.type === Handletype.setPusher) {
831
+ this.addPusherTask(task);
832
+ } else {
833
+ this.addPlayerTask(task.args.view, task);
834
+ }
835
+ }
836
+ }, {
837
+ key: "addPusherTask",
838
+ value: function addPusherTask(task) {
839
+ this.addTaskToQueue(task, this.pusherTaskQueue);
840
+ if (this.state === TaskQueueState.PROCESS && !this.isProcessing) {
841
+ this.processPusherTasks();
842
+ } else if (this.state === TaskQueueState.IDLE) {
733
843
  this.send(TaskQueueEvent.SET);
734
844
  } else if (this.state === TaskQueueState.PENDING) {
735
845
  this.send(TaskQueueEvent.SETPROCESS);
736
846
  }
737
847
  }
848
+ }, {
849
+ key: "addPlayerTask",
850
+ value: function addPlayerTask(view, task) {
851
+ if (!this.playerTasks[view]) {
852
+ this.playerTasks[view] = {
853
+ taskQueue: [],
854
+ isProcessing: false,
855
+ domReady: false
856
+ };
857
+ }
858
+ this.addTaskToQueue(task, this.playerTasks[view].taskQueue);
859
+ if (this.state === TaskQueueState.PROCESS && !this.playerTasks[view].isProcessing) {
860
+ this.processPlayerTasks(view);
861
+ } else if (this.state === TaskQueueState.IDLE) {
862
+ this.send(TaskQueueEvent.SET, view);
863
+ } else if (this.state === TaskQueueState.PENDING) {
864
+ this.send(TaskQueueEvent.SETPROCESS, view);
865
+ }
866
+ }
738
867
  }, {
739
868
  key: "addTaskToQueue",
740
- value: function addTaskToQueue(task) {
741
- this.context.taskQueue.push(task);
742
- this.context.taskQueue.sort(function (a, b) {
869
+ value: function addTaskToQueue(task, queue) {
870
+ queue.push(task);
871
+ queue.sort(function (a, b) {
743
872
  if (a.priority !== b.priority) {
744
873
  return a.priority - b.priority;
745
874
  }
746
875
  return a.sequenceNumber - b.sequenceNumber;
747
876
  });
748
877
  }
878
+ /**
879
+ * 处理任务队列
880
+ * @param taskQueue
881
+ * @param isProcessing
882
+ * @param domReady
883
+ * @param setProcessing
884
+ * @returns
885
+ */
749
886
  }, {
750
887
  key: "processTasks",
751
- value: function processTasks() {
888
+ value: function processTasks(taskQueue, isProcessing, domReady, setProcessing, view) {
752
889
  return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
753
890
  var _this = this;
754
- var currentTasks, singleTasks, exceptSingleTask, _iterator, _step, _task3, args, task, sequenceTask, r, _iterator2, _step2, _task, _iterator3, _step3, _task2;
891
+ var currentTasks, singleTasks, exceptSingleTask, _iterator, _step, _task3, params, task, sequenceTask, r, _iterator2, _step2, _task, _iterator3, _step3, _task2;
755
892
  return _regeneratorRuntime().wrap(function _callee$(_context) {
756
893
  while (1) switch (_context.prev = _context.next) {
757
894
  case 0:
758
- if (!(this.isProcessing || !this.pusherDomReady || this.context.taskQueue.length === 0)) {
895
+ if (!(isProcessing || !domReady || taskQueue.length === 0)) {
759
896
  _context.next = 2;
760
897
  break;
761
898
  }
762
899
  return _context.abrupt("return");
763
900
  case 2:
764
- this.isProcessing = true;
901
+ setProcessing(true);
765
902
  this.state = TaskQueueState.PROCESS;
766
- currentTasks = _toConsumableArray(this.context.taskQueue);
767
- this.context.taskQueue = [];
903
+ currentTasks = _toConsumableArray(taskQueue);
904
+ taskQueue.length = 0;
768
905
  singleTasks = currentTasks.filter(function (task) {
769
906
  return task.single;
770
907
  });
@@ -782,7 +919,7 @@ var TaskMachine = /*#__PURE__*/function () {
782
919
  _task3 = _step.value;
783
920
  _context.prev = 13;
784
921
  _context.next = 16;
785
- return _task3.action.call(_task3.ctx, _task3.args, _task3.name);
922
+ return _task3.action.call(_task3.ctx, _task3.args, _task3.name, TaskMap[_task3.name].type);
786
923
  case 16:
787
924
  _task3.result = _context.sent;
788
925
  _context.next = 22;
@@ -806,8 +943,9 @@ var TaskMachine = /*#__PURE__*/function () {
806
943
  _iterator.f();
807
944
  return _context.finish(29);
808
945
  case 32:
809
- args = exceptSingleTask.reduce(function (acc, cur) {
810
- return Object.assign(Object.assign({}, acc), typeof cur.args === 'function' ? cur.args() : cur.args);
946
+ params = exceptSingleTask.reduce(function (acc, cur) {
947
+ var params = cur.args.params;
948
+ return Object.assign(Object.assign({}, acc), typeof params === 'function' ? params() : params);
811
949
  }, {});
812
950
  task = exceptSingleTask[0];
813
951
  sequenceTask = currentTasks.sort(function (a, b) {
@@ -816,14 +954,31 @@ var TaskMachine = /*#__PURE__*/function () {
816
954
  _context.prev = 35;
817
955
  r = null;
818
956
  if (!task) {
819
- _context.next = 41;
957
+ _context.next = 47;
820
958
  break;
821
959
  }
822
- _context.next = 40;
823
- return task.action.call(task.ctx, args);
824
- case 40:
825
- r = _context.sent;
960
+ if (!view) {
961
+ _context.next = 44;
962
+ break;
963
+ }
964
+ _context.next = 41;
965
+ return task.action.call(task.ctx, {
966
+ params: params,
967
+ streamId: task.args.streamId,
968
+ view: view
969
+ }, task.name, Handletype.setPlayer);
826
970
  case 41:
971
+ r = _context.sent;
972
+ _context.next = 47;
973
+ break;
974
+ case 44:
975
+ _context.next = 46;
976
+ return task.action.call(task.ctx, {
977
+ params: params
978
+ }, task.name, Handletype.setPusher);
979
+ case 46:
980
+ r = _context.sent;
981
+ case 47:
827
982
  _iterator2 = _createForOfIteratorHelper(sequenceTask);
828
983
  try {
829
984
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
@@ -839,10 +994,10 @@ var TaskMachine = /*#__PURE__*/function () {
839
994
  } finally {
840
995
  _iterator2.f();
841
996
  }
842
- _context.next = 49;
997
+ _context.next = 55;
843
998
  break;
844
- case 45:
845
- _context.prev = 45;
999
+ case 51:
1000
+ _context.prev = 51;
846
1001
  _context.t2 = _context["catch"](35);
847
1002
  _iterator3 = _createForOfIteratorHelper(sequenceTask);
848
1003
  try {
@@ -855,19 +1010,63 @@ var TaskMachine = /*#__PURE__*/function () {
855
1010
  } finally {
856
1011
  _iterator3.f();
857
1012
  }
858
- case 49:
859
- this.isProcessing = false;
860
- this.send(TaskQueueEvent.SETDONE);
861
- if (this.context.taskQueue.length > 0) {
1013
+ case 55:
1014
+ setProcessing(false);
1015
+ this.send(TaskQueueEvent.SETDONE, view);
1016
+ if (taskQueue.length > 0) {
862
1017
  Promise.resolve().then(function () {
863
- _this.processTasks();
1018
+ _this.processTasks(taskQueue, isProcessing, domReady, setProcessing, view);
864
1019
  })["catch"](console.error);
865
1020
  }
866
- case 52:
1021
+ case 58:
867
1022
  case "end":
868
1023
  return _context.stop();
869
1024
  }
870
- }, _callee, this, [[9, 26, 29, 32], [13, 19], [35, 45]]);
1025
+ }, _callee, this, [[9, 26, 29, 32], [13, 19], [35, 51]]);
1026
+ }));
1027
+ }
1028
+ }, {
1029
+ key: "processPusherTasks",
1030
+ value: function processPusherTasks() {
1031
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1032
+ var _this2 = this;
1033
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1034
+ while (1) switch (_context2.prev = _context2.next) {
1035
+ case 0:
1036
+ _context2.next = 2;
1037
+ return this.processTasks(this.pusherTaskQueue, this.isProcessing, this.pusherDomReady, function (value) {
1038
+ _this2.isProcessing = value;
1039
+ });
1040
+ case 2:
1041
+ case "end":
1042
+ return _context2.stop();
1043
+ }
1044
+ }, _callee2, this);
1045
+ }));
1046
+ }
1047
+ }, {
1048
+ key: "processPlayerTasks",
1049
+ value: function processPlayerTasks(view) {
1050
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1051
+ var _this3 = this;
1052
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1053
+ while (1) switch (_context3.prev = _context3.next) {
1054
+ case 0:
1055
+ if (this.playerTasks[view]) {
1056
+ _context3.next = 2;
1057
+ break;
1058
+ }
1059
+ return _context3.abrupt("return");
1060
+ case 2:
1061
+ _context3.next = 4;
1062
+ return this.processTasks(this.playerTasks[view].taskQueue, this.playerTasks[view].isProcessing, this.playerTasks[view].domReady, function (value) {
1063
+ _this3.playerTasks[view].isProcessing = value;
1064
+ }, view);
1065
+ case 4:
1066
+ case "end":
1067
+ return _context3.stop();
1068
+ }
1069
+ }, _callee3, this);
871
1070
  }));
872
1071
  }
873
1072
  }]);
@@ -877,22 +1076,27 @@ var taskMachine = new TaskMachine();
877
1076
  var setHandle = function setHandle(target, key, descriptor) {
878
1077
  var originalMethod = descriptor.value;
879
1078
  descriptor.value = function () {
880
- var _this2 = this;
1079
+ var _this4 = this;
881
1080
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
882
1081
  args[_key] = arguments[_key];
883
1082
  }
1083
+ var params = args[0],
1084
+ funName = args[1];
884
1085
  return new Promise(function (resolve, reject) {
885
- var params = args[0],
886
- funName = args[1];
887
- taskMachine.addTask(new Task({
888
- ctx: _this2,
889
- priority: TaskPriorityMap[funName] || 0,
890
- action: originalMethod,
891
- args: params,
892
- name: funName,
893
- resolve: resolve,
894
- reject: reject
895
- }));
1086
+ var _a;
1087
+ try {
1088
+ taskMachine.addTask(new Task({
1089
+ ctx: _this4,
1090
+ priority: ((_a = TaskMap[funName]) === null || _a === void 0 ? void 0 : _a.priority) || 0,
1091
+ action: originalMethod,
1092
+ args: params,
1093
+ name: funName,
1094
+ resolve: resolve,
1095
+ reject: reject
1096
+ }));
1097
+ } catch (error) {
1098
+ reject(error);
1099
+ }
896
1100
  });
897
1101
  };
898
1102
  return descriptor;
@@ -1150,7 +1354,7 @@ var Logger = /*#__PURE__*/function () {
1150
1354
  var logger = new Logger();
1151
1355
 
1152
1356
  var name = "@tencentcloud/trtc-cloud-wx";
1153
- var version = "0.0.19";
1357
+ var version = "0.0.20-beta.1";
1154
1358
  var description = "";
1155
1359
  var main = "dist/trtc-cloud-wx.js";
1156
1360
  var module$1 = "dist/trtc-cloud-wx.js";
@@ -1300,6 +1504,16 @@ var TRTCCloud = /*#__PURE__*/function () {
1300
1504
  taskMachine.send(TaskQueueEvent.SETDONE);
1301
1505
  }
1302
1506
  });
1507
+ this.InterfaceEventEmitter.on('playerDomReady', function (_ref) {
1508
+ var isReady = _ref.isReady,
1509
+ view = _ref.view;
1510
+ taskMachine.setPlayerDomReady(view, isReady);
1511
+ if (isReady) {
1512
+ taskMachine.send(TaskQueueEvent.SETPROCESS, view);
1513
+ } else {
1514
+ taskMachine.send(TaskQueueEvent.SETDONE, view);
1515
+ }
1516
+ });
1303
1517
  }
1304
1518
  }, {
1305
1519
  key: "bindTRTCEvent",
@@ -1521,18 +1735,20 @@ var TRTCCloud = /*#__PURE__*/function () {
1521
1735
  this.userId = userId;
1522
1736
  this.isEnterRoom = true;
1523
1737
  _context2.next = 8;
1524
- return this.setPusherAttributes({
1525
- sdkAppID: sdkAppId,
1526
- userID: userId,
1527
- userSig: userSig,
1528
- roomID: roomId,
1529
- strRoomID: strRoomId,
1530
- role: role,
1531
- privateMapKey: privateMapKey,
1532
- scene: translateTRTCAppScene(scene),
1533
- enableMic: false,
1534
- enableCamera: false,
1535
- videoPreview: false
1738
+ return this.setAttributes({
1739
+ params: {
1740
+ sdkAppID: sdkAppId,
1741
+ userID: userId,
1742
+ userSig: userSig,
1743
+ roomID: roomId,
1744
+ strRoomID: strRoomId,
1745
+ role: role,
1746
+ privateMapKey: privateMapKey,
1747
+ scene: translateTRTCAppScene(scene),
1748
+ enableMic: false,
1749
+ enableCamera: false,
1750
+ videoPreview: false
1751
+ }
1536
1752
  }, 'enterRoom');
1537
1753
  case 8:
1538
1754
  this.trtc.getPusherInstance().start({
@@ -1551,9 +1767,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1551
1767
  break;
1552
1768
  }
1553
1769
  _context.next = 7;
1554
- return this.setPusherAttributes({
1555
- videoPreview: false,
1556
- enableCamera: true
1770
+ return this.setAttributes({
1771
+ params: {
1772
+ videoPreview: false,
1773
+ enableCamera: true
1774
+ }
1557
1775
  }, 'other');
1558
1776
  case 7:
1559
1777
  this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
@@ -1626,9 +1844,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1626
1844
  return _context3.abrupt("return");
1627
1845
  case 7:
1628
1846
  _context3.next = 9;
1629
- return this.setPusherAttributes({
1630
- enableCamera: false,
1631
- enableMic: false
1847
+ return this.setAttributes({
1848
+ params: {
1849
+ enableCamera: false,
1850
+ enableMic: false
1851
+ }
1632
1852
  }, 'switchRole');
1633
1853
  case 9:
1634
1854
  logger.info('switchRole success');
@@ -1671,12 +1891,14 @@ var TRTCCloud = /*#__PURE__*/function () {
1671
1891
  return _context4.abrupt("return");
1672
1892
  case 3:
1673
1893
  _context4.next = 5;
1674
- return this.setPusherAttributes(function () {
1675
- return {
1676
- videoPreview: _this8.isEnterRoom ? _this8.isVideoMuted : true,
1677
- enableCamera: _this8.isEnterRoom ? !_this8.isVideoMuted : false,
1678
- frontCamera: frontCamera ? 'front' : 'back'
1679
- };
1894
+ return this.setAttributes({
1895
+ params: function params() {
1896
+ return {
1897
+ videoPreview: _this8.isEnterRoom ? _this8.isVideoMuted : true,
1898
+ enableCamera: _this8.isEnterRoom ? !_this8.isVideoMuted : false,
1899
+ frontCamera: frontCamera ? 'front' : 'back'
1900
+ };
1901
+ }
1680
1902
  }, 'startLocalPreview');
1681
1903
  case 5:
1682
1904
  pusher = _context4.sent;
@@ -1706,9 +1928,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1706
1928
  case 0:
1707
1929
  logger.info('stopLocalPreview');
1708
1930
  _context5.next = 3;
1709
- return this.setPusherAttributes({
1710
- videoPreview: false,
1711
- enableCamera: false
1931
+ return this.setAttributes({
1932
+ params: {
1933
+ videoPreview: false,
1934
+ enableCamera: false
1935
+ }
1712
1936
  }, 'stopLocalPreview');
1713
1937
  case 3:
1714
1938
  logger.info('stopLocalPreview success');
@@ -1764,18 +1988,20 @@ var TRTCCloud = /*#__PURE__*/function () {
1764
1988
  logger.info('muteLocalVideo: isVideoMuted set to ', mute);
1765
1989
  _context6.prev = 9;
1766
1990
  _context6.next = 12;
1767
- return this.setPusherAttributes({
1768
- videoPreview: mute,
1769
- enableCamera: !mute
1991
+ return this.setAttributes({
1992
+ params: {
1993
+ videoPreview: mute,
1994
+ enableCamera: !mute
1995
+ }
1770
1996
  }, 'muteLocalVideo');
1771
1997
  case 12:
1772
- logger.info('muteLocalVideo: setPusherAttributes success');
1998
+ logger.info('muteLocalVideo: setAttributes success');
1773
1999
  _context6.next = 18;
1774
2000
  break;
1775
2001
  case 15:
1776
2002
  _context6.prev = 15;
1777
2003
  _context6.t1 = _context6["catch"](9);
1778
- logger.error('muteLocalVideo: setPusherAttributes failed with error ', _context6.t1);
2004
+ logger.error('muteLocalVideo: setAttributes failed with error ', _context6.t1);
1779
2005
  case 18:
1780
2006
  logger.info('muteLocalVideo success');
1781
2007
  return _context6.abrupt("break", 21);
@@ -1798,23 +2024,32 @@ var TRTCCloud = /*#__PURE__*/function () {
1798
2024
  }, {
1799
2025
  key: "startRemoteView",
1800
2026
  value: function startRemoteView(userId, view, streamType) {
1801
- var _this9 = this;
1802
- logger.info('startRemoteView with options: ', userId, view, streamType);
1803
- var streamId = translateTRTCStreamId(userId, streamType);
1804
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1805
- muteVideo: false,
1806
- stopVideo: false
1807
- });
1808
- this.renderMap.set(streamId, view);
1809
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1810
- streamId: streamId,
1811
- view: this.renderMap.get(streamId),
1812
- playerAttributes: playerAttributes,
1813
- callback: function callback() {
1814
- logger.info('startRemoteView success');
1815
- _this9.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1816
- }
1817
- });
2027
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
2028
+ var streamId;
2029
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
2030
+ while (1) switch (_context7.prev = _context7.next) {
2031
+ case 0:
2032
+ logger.info('startRemoteView with options: ', userId, view, streamType);
2033
+ streamId = translateTRTCStreamId(userId, streamType);
2034
+ this.renderMap.set(streamId, view);
2035
+ _context7.next = 5;
2036
+ return this.setAttributes({
2037
+ params: {
2038
+ muteVideo: false,
2039
+ stopVideo: false
2040
+ },
2041
+ streamId: streamId,
2042
+ view: view
2043
+ }, 'startRemoteView');
2044
+ case 5:
2045
+ logger.info('startRemoteView success');
2046
+ this.emit('onFirstVideoFrame', userId, streamType, 0, 0);
2047
+ case 7:
2048
+ case "end":
2049
+ return _context7.stop();
2050
+ }
2051
+ }, _callee7, this);
2052
+ }));
1818
2053
  }
1819
2054
  /**
1820
2055
  * 停止显示远端视频画面,同时不再拉取该远端用户的视频数据流
@@ -1824,20 +2059,30 @@ var TRTCCloud = /*#__PURE__*/function () {
1824
2059
  }, {
1825
2060
  key: "stopRemoteView",
1826
2061
  value: function stopRemoteView(userId, streamType) {
1827
- logger.info('stopRemoteView with options: ', userId, streamType);
1828
- var streamId = translateTRTCStreamId(userId, streamType);
1829
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1830
- muteVideo: true,
1831
- stopVideo: true
1832
- });
1833
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1834
- streamId: streamId,
1835
- view: this.renderMap.get(streamId),
1836
- playerAttributes: playerAttributes,
1837
- callback: function callback() {
1838
- logger.info('stopRemoteView success');
1839
- }
1840
- });
2062
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
2063
+ var streamId;
2064
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
2065
+ while (1) switch (_context8.prev = _context8.next) {
2066
+ case 0:
2067
+ logger.info('stopRemoteView with options: ', userId, streamType);
2068
+ streamId = translateTRTCStreamId(userId, streamType);
2069
+ _context8.next = 4;
2070
+ return this.setAttributes({
2071
+ params: {
2072
+ muteVideo: true,
2073
+ stopVideo: true
2074
+ },
2075
+ streamId: streamId,
2076
+ view: this.renderMap.get(streamId)
2077
+ }, 'stopRemoteView');
2078
+ case 4:
2079
+ logger.info('stopRemoteView success');
2080
+ case 5:
2081
+ case "end":
2082
+ return _context8.stop();
2083
+ }
2084
+ }, _callee8, this);
2085
+ }));
1841
2086
  }
1842
2087
  /**
1843
2088
  * 修改远端视频渲染的 HTML 元素,小程序不支持
@@ -1851,75 +2096,141 @@ var TRTCCloud = /*#__PURE__*/function () {
1851
2096
  }, {
1852
2097
  key: "updateRemoteView",
1853
2098
  value: function updateRemoteView(userId, view, streamType) {
1854
- logger.info('updateRemoteView with options: ', userId, view, streamType);
1855
- if (view !== null) {
1856
- this.startRemoteView(userId, view, streamType);
1857
- return;
1858
- }
1859
- this.stopRemoteView(userId, streamType);
2099
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
2100
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
2101
+ while (1) switch (_context9.prev = _context9.next) {
2102
+ case 0:
2103
+ logger.info('updateRemoteView with options: ', userId, view, streamType);
2104
+ if (!(view !== null)) {
2105
+ _context9.next = 5;
2106
+ break;
2107
+ }
2108
+ _context9.next = 4;
2109
+ return this.startRemoteView(userId, view, streamType);
2110
+ case 4:
2111
+ return _context9.abrupt("return");
2112
+ case 5:
2113
+ _context9.next = 7;
2114
+ return this.stopRemoteView(userId, streamType);
2115
+ case 7:
2116
+ case "end":
2117
+ return _context9.stop();
2118
+ }
2119
+ }, _callee9, this);
2120
+ }));
1860
2121
  }
1861
2122
  // 停止显示所有远端视频画面,同时不再拉取该远端用户的视频数据流
1862
2123
  }, {
1863
2124
  key: "stopAllRemoteView",
1864
2125
  value: function stopAllRemoteView() {
1865
- var _this10 = this;
1866
- logger.info('stopAllRemoteView');
1867
- var playerList = this.trtc.getPlayerList();
1868
- playerList.forEach(function (player) {
1869
- var streamId = player.streamID;
1870
- var playerAttributes = _this10.setTRTCPlayerAttributes(streamId, {
1871
- muteVideo: true,
1872
- stopVideo: true
1873
- });
1874
- _this10.InterfaceEventEmitter.emit('playerAttributesChange', {
1875
- streamId: streamId,
1876
- view: _this10.renderMap.get(streamId),
1877
- playerAttributes: playerAttributes,
1878
- callback: function callback() {
1879
- logger.info('stopAllRemoteView success');
2126
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2127
+ var _this9 = this;
2128
+ var playerList;
2129
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
2130
+ while (1) switch (_context11.prev = _context11.next) {
2131
+ case 0:
2132
+ logger.info('stopAllRemoteView');
2133
+ playerList = this.trtc.getPlayerList();
2134
+ playerList.forEach(function (player) {
2135
+ return __awaiter(_this9, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
2136
+ var streamId;
2137
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
2138
+ while (1) switch (_context10.prev = _context10.next) {
2139
+ case 0:
2140
+ streamId = player.streamID;
2141
+ _context10.next = 3;
2142
+ return this.setAttributes({
2143
+ params: {
2144
+ muteVideo: true,
2145
+ stopVideo: true
2146
+ },
2147
+ streamId: streamId,
2148
+ view: this.renderMap.get(streamId)
2149
+ }, 'stopAllRemoteView');
2150
+ case 3:
2151
+ case "end":
2152
+ return _context10.stop();
2153
+ }
2154
+ }, _callee10, this);
2155
+ }));
2156
+ });
2157
+ logger.info('stopAllRemoteView success');
2158
+ case 4:
2159
+ case "end":
2160
+ return _context11.stop();
1880
2161
  }
1881
- });
1882
- });
2162
+ }, _callee11, this);
2163
+ }));
1883
2164
  }
1884
2165
  // 暂停接收指定的远端视频流
1885
2166
  // 该接口仅停止接收远程用户的视频流,但并不释放显示资源,所以视频画面会冻屏在 mute 前的最后一帧。
1886
2167
  }, {
1887
2168
  key: "muteRemoteVideoStream",
1888
2169
  value: function muteRemoteVideoStream(userId, mute, streamType) {
1889
- logger.info('muteRemoteVideoStream');
1890
- var streamId = translateTRTCStreamId(userId, streamType);
1891
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1892
- muteVideo: mute
1893
- });
1894
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1895
- streamId: streamId,
1896
- view: this.renderMap.get(streamId),
1897
- playerAttributes: playerAttributes,
1898
- callback: function callback() {
1899
- logger.info('muteRemoteVideoStream success');
1900
- }
1901
- });
2170
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2171
+ var streamId;
2172
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
2173
+ while (1) switch (_context12.prev = _context12.next) {
2174
+ case 0:
2175
+ logger.info('muteRemoteVideoStream');
2176
+ streamId = translateTRTCStreamId(userId, streamType);
2177
+ _context12.next = 4;
2178
+ return this.setAttributes({
2179
+ params: {
2180
+ muteVideo: mute
2181
+ },
2182
+ streamId: streamId,
2183
+ view: this.renderMap.get(streamId)
2184
+ }, 'muteRemoteVideoStream');
2185
+ case 4:
2186
+ logger.info('muteRemoteVideoStream success');
2187
+ case 5:
2188
+ case "end":
2189
+ return _context12.stop();
2190
+ }
2191
+ }, _callee12, this);
2192
+ }));
1902
2193
  }
1903
2194
  }, {
1904
2195
  key: "muteAllRemoteVideoStreams",
1905
2196
  value: function muteAllRemoteVideoStreams(mute) {
1906
- var _this11 = this;
1907
- logger.info('muteAllRemoteVideoStreams with options: ', mute);
1908
- var playerList = this.trtc.getPlayerList();
1909
- playerList.forEach(function (player) {
1910
- var streamId = player.streamID;
1911
- var playerAttributes = _this11.setTRTCPlayerAttributes(streamId, {
1912
- muteVideo: mute
1913
- });
1914
- _this11.InterfaceEventEmitter.emit('playerAttributesChange', {
1915
- streamId: streamId,
1916
- view: _this11.renderMap.get(streamId),
1917
- playerAttributes: playerAttributes,
1918
- callback: function callback() {
1919
- logger.info('muteAllRemoteVideoStreams success');
2197
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee14() {
2198
+ var _this10 = this;
2199
+ var playerList;
2200
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
2201
+ while (1) switch (_context14.prev = _context14.next) {
2202
+ case 0:
2203
+ logger.info('muteAllRemoteVideoStreams with options: ', mute);
2204
+ playerList = this.trtc.getPlayerList();
2205
+ playerList.forEach(function (player) {
2206
+ return __awaiter(_this10, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
2207
+ var streamId;
2208
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
2209
+ while (1) switch (_context13.prev = _context13.next) {
2210
+ case 0:
2211
+ streamId = player.streamID;
2212
+ _context13.next = 3;
2213
+ return this.setAttributes({
2214
+ params: {
2215
+ muteVideo: mute
2216
+ },
2217
+ streamId: streamId,
2218
+ view: this.renderMap.get(streamId)
2219
+ }, 'muteAllRemoteVideoStreams');
2220
+ case 3:
2221
+ case "end":
2222
+ return _context13.stop();
2223
+ }
2224
+ }, _callee13, this);
2225
+ }));
2226
+ });
2227
+ logger.info('muteAllRemoteVideoStreams success');
2228
+ case 4:
2229
+ case "end":
2230
+ return _context14.stop();
1920
2231
  }
1921
- });
1922
- });
2232
+ }, _callee14, this);
2233
+ }));
1923
2234
  }
1924
2235
  }, {
1925
2236
  key: "setTRTCPlayerAttributes",
@@ -1932,55 +2243,59 @@ var TRTCCloud = /*#__PURE__*/function () {
1932
2243
  }, {
1933
2244
  key: "setVideoEncoderParam",
1934
2245
  value: function setVideoEncoderParam(params) {
1935
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
2246
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee15() {
1936
2247
  var videoResolution, videoFps, minVideoBitrate, _translateTRTCVideoRe, videoWidth, videoHeight;
1937
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1938
- while (1) switch (_context7.prev = _context7.next) {
2248
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2249
+ while (1) switch (_context15.prev = _context15.next) {
1939
2250
  case 0:
1940
2251
  logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1941
2252
  videoResolution = params.videoResolution, params.resMode, videoFps = params.videoFps, params.videoBitrate, minVideoBitrate = params.minVideoBitrate;
1942
- _translateTRTCVideoRe = translateTRTCVideoResolution(videoResolution), videoWidth = _translateTRTCVideoRe.videoWidth, videoHeight = _translateTRTCVideoRe.videoHeight; // const videoOrientation = translateTRTCVideoResolutionMode(resMode);
1943
- _context7.next = 5;
1944
- return this.setPusherAttributes({
1945
- videoWidth: videoWidth,
1946
- videoHeight: videoHeight,
1947
- // videoOrientation,
1948
- fps: videoFps,
1949
- minBitrate: minVideoBitrate
2253
+ _translateTRTCVideoRe = translateTRTCVideoResolution(videoResolution), videoWidth = _translateTRTCVideoRe.videoWidth, videoHeight = _translateTRTCVideoRe.videoHeight;
2254
+ _context15.next = 5;
2255
+ return this.setAttributes({
2256
+ params: {
2257
+ videoWidth: videoWidth,
2258
+ videoHeight: videoHeight,
2259
+ // videoOrientation,
2260
+ fps: videoFps,
2261
+ minBitrate: minVideoBitrate
2262
+ }
1950
2263
  }, 'setVideoEncoderParam');
1951
2264
  case 5:
1952
2265
  logger.info('setVideoEncoderParam success');
1953
2266
  case 6:
1954
2267
  case "end":
1955
- return _context7.stop();
2268
+ return _context15.stop();
1956
2269
  }
1957
- }, _callee7, this);
2270
+ }, _callee15, this);
1958
2271
  }));
1959
2272
  }
1960
2273
  }, {
1961
2274
  key: "setLocalRenderParams",
1962
2275
  value: function setLocalRenderParams(params) {
1963
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
2276
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee16() {
1964
2277
  var rotation, mirrorType, videoOrientation, localMirror;
1965
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1966
- while (1) switch (_context8.prev = _context8.next) {
2278
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2279
+ while (1) switch (_context16.prev = _context16.next) {
1967
2280
  case 0:
1968
2281
  logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1969
2282
  rotation = params.rotation, params.fillMode, mirrorType = params.mirrorType;
1970
2283
  videoOrientation = translateTRTCVideoRotation(rotation);
1971
2284
  localMirror = translateTRTCVideoMirrorType(mirrorType);
1972
- _context8.next = 6;
1973
- return this.setPusherAttributes({
1974
- videoOrientation: videoOrientation,
1975
- localMirror: localMirror
2285
+ _context16.next = 6;
2286
+ return this.setAttributes({
2287
+ params: {
2288
+ videoOrientation: videoOrientation,
2289
+ localMirror: localMirror
2290
+ }
1976
2291
  }, 'setLocalRenderParams');
1977
2292
  case 6:
1978
2293
  logger.info('setLocalRenderParams success');
1979
2294
  case 7:
1980
2295
  case "end":
1981
- return _context8.stop();
2296
+ return _context16.stop();
1982
2297
  }
1983
- }, _callee8, this);
2298
+ }, _callee16, this);
1984
2299
  }));
1985
2300
  }
1986
2301
  /**
@@ -1992,41 +2307,51 @@ var TRTCCloud = /*#__PURE__*/function () {
1992
2307
  }, {
1993
2308
  key: "setRemoteRenderParams",
1994
2309
  value: function setRemoteRenderParams(userId, streamType, params) {
1995
- logger.info('setRemoteRenderParams with options: ', userId, streamType, JSON.stringify(params));
1996
- var fillMode = params.fillMode,
1997
- rotation = params.rotation;
1998
- params.mirrorType;
1999
- var streamId = translateTRTCStreamId(userId, streamType); // 音频默认都是主流
2000
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
2001
- objectFit: translateVideoFillMod(fillMode),
2002
- orientation: translateTRTCVideoRotation(rotation)
2003
- });
2004
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
2005
- streamId: streamId,
2006
- view: this.renderMap.get(streamId),
2007
- playerAttributes: playerAttributes,
2008
- callback: function callback() {
2009
- logger.info('setRemoteRenderParams success');
2010
- }
2011
- });
2310
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee17() {
2311
+ var fillMode, rotation, streamId;
2312
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
2313
+ while (1) switch (_context17.prev = _context17.next) {
2314
+ case 0:
2315
+ logger.info('setRemoteRenderParams with options: ', userId, streamType, JSON.stringify(params));
2316
+ fillMode = params.fillMode, rotation = params.rotation, params.mirrorType;
2317
+ streamId = translateTRTCStreamId(userId, streamType); // 音频默认都是主流
2318
+ _context17.next = 5;
2319
+ return this.setAttributes({
2320
+ params: {
2321
+ objectFit: translateVideoFillMod(fillMode),
2322
+ orientation: translateTRTCVideoRotation(rotation)
2323
+ },
2324
+ streamId: streamId,
2325
+ view: this.renderMap.get(streamId)
2326
+ }, 'setRemoteRenderParams');
2327
+ case 5:
2328
+ logger.info('setRemoteRenderParams success');
2329
+ case 6:
2330
+ case "end":
2331
+ return _context17.stop();
2332
+ }
2333
+ }, _callee17, this);
2334
+ }));
2012
2335
  }
2013
2336
  }, {
2014
2337
  key: "startLocalAudio",
2015
2338
  value: function startLocalAudio(quality) {
2016
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
2017
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
2018
- while (1) switch (_context9.prev = _context9.next) {
2339
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee18() {
2340
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
2341
+ while (1) switch (_context18.prev = _context18.next) {
2019
2342
  case 0:
2020
2343
  logger.info('startLocalAudio with options: ', quality);
2021
2344
  if (!(this.role !== exports.TRTCRoleType.TRTCRoleAnchor)) {
2022
- _context9.next = 3;
2345
+ _context18.next = 3;
2023
2346
  break;
2024
2347
  }
2025
2348
  throw new Error('Current role is audience, unable to access mic. Call switchRole to become a host.');
2026
2349
  case 3:
2027
- _context9.next = 5;
2028
- return this.setPusherAttributes({
2029
- enableMic: true
2350
+ _context18.next = 5;
2351
+ return this.setAttributes({
2352
+ params: {
2353
+ enableMic: true
2354
+ }
2030
2355
  }, 'startLocalAudio');
2031
2356
  case 5:
2032
2357
  logger.info('startLocalAudio success');
@@ -2037,112 +2362,146 @@ var TRTCCloud = /*#__PURE__*/function () {
2037
2362
  }
2038
2363
  case 9:
2039
2364
  case "end":
2040
- return _context9.stop();
2365
+ return _context18.stop();
2041
2366
  }
2042
- }, _callee9, this);
2367
+ }, _callee18, this);
2043
2368
  }));
2044
2369
  }
2045
2370
  }, {
2046
2371
  key: "stopLocalAudio",
2047
2372
  value: function stopLocalAudio() {
2048
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
2049
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
2050
- while (1) switch (_context10.prev = _context10.next) {
2373
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee19() {
2374
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
2375
+ while (1) switch (_context19.prev = _context19.next) {
2051
2376
  case 0:
2052
2377
  logger.info('stopLocalAudio');
2053
- _context10.next = 3;
2054
- return this.setPusherAttributes({
2055
- enableMic: false
2378
+ _context19.next = 3;
2379
+ return this.setAttributes({
2380
+ params: {
2381
+ enableMic: false
2382
+ }
2056
2383
  }, 'stopLocalAudio');
2057
2384
  case 3:
2058
2385
  logger.info('stopLocalAudio success');
2059
2386
  this.emit('onUserAudioAvailable', this.userId, 0);
2060
2387
  case 5:
2061
2388
  case "end":
2062
- return _context10.stop();
2389
+ return _context19.stop();
2063
2390
  }
2064
- }, _callee10, this);
2391
+ }, _callee19, this);
2065
2392
  }));
2066
2393
  }
2067
2394
  }, {
2068
2395
  key: "muteLocalAudio",
2069
2396
  value: function muteLocalAudio(mute) {
2070
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2071
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
2072
- while (1) switch (_context11.prev = _context11.next) {
2397
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee20() {
2398
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
2399
+ while (1) switch (_context20.prev = _context20.next) {
2073
2400
  case 0:
2074
2401
  logger.info('muteLocalAudio called with options: ', mute);
2075
- _context11.prev = 1;
2076
- _context11.next = 4;
2077
- return this.setPusherAttributes({
2078
- muted: mute
2402
+ _context20.prev = 1;
2403
+ _context20.next = 4;
2404
+ return this.setAttributes({
2405
+ params: {
2406
+ muted: mute
2407
+ }
2079
2408
  }, 'muteLocalAudio');
2080
2409
  case 4:
2081
- logger.info('setPusherAttributes executed successfully');
2082
- _context11.next = 11;
2410
+ logger.info('setAttributes executed successfully');
2411
+ _context20.next = 11;
2083
2412
  break;
2084
2413
  case 7:
2085
- _context11.prev = 7;
2086
- _context11.t0 = _context11["catch"](1);
2087
- logger.error('Error in setPusherAttributes: ', _context11.t0);
2088
- throw _context11.t0;
2414
+ _context20.prev = 7;
2415
+ _context20.t0 = _context20["catch"](1);
2416
+ logger.error('Error in setAttributes: ', _context20.t0);
2417
+ throw _context20.t0;
2089
2418
  case 11:
2090
- _context11.prev = 11;
2419
+ _context20.prev = 11;
2091
2420
  this.emit('onUserAudioAvailable', this.userId, mute === true ? 0 : 1);
2092
2421
  logger.info('onUserAudioAvailable event emitted successfully');
2093
- _context11.next = 20;
2422
+ _context20.next = 20;
2094
2423
  break;
2095
2424
  case 16:
2096
- _context11.prev = 16;
2097
- _context11.t1 = _context11["catch"](11);
2098
- logger.error('Error in emitting onUserAudioAvailable event: ', _context11.t1);
2099
- throw _context11.t1;
2425
+ _context20.prev = 16;
2426
+ _context20.t1 = _context20["catch"](11);
2427
+ logger.error('Error in emitting onUserAudioAvailable event: ', _context20.t1);
2428
+ throw _context20.t1;
2100
2429
  case 20:
2101
2430
  logger.info('muteLocalAudio execution finished');
2102
2431
  case 21:
2103
2432
  case "end":
2104
- return _context11.stop();
2433
+ return _context20.stop();
2105
2434
  }
2106
- }, _callee11, this, [[1, 7], [11, 16]]);
2435
+ }, _callee20, this, [[1, 7], [11, 16]]);
2107
2436
  }));
2108
2437
  }
2109
2438
  }, {
2110
2439
  key: "muteRemoteAudio",
2111
2440
  value: function muteRemoteAudio(userId, mute) {
2112
- logger.info('muteRemoteAudio with options: ', userId, mute);
2113
- var streamId = translateTRTCStreamId(userId, exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig); // 音频默认都是主流
2114
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
2115
- muteAudio: mute
2116
- });
2117
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
2118
- streamId: streamId,
2119
- view: this.renderMap.get(streamId),
2120
- playerAttributes: playerAttributes,
2121
- callback: function callback() {
2122
- logger.info('muteRemoteAudio success');
2123
- }
2124
- });
2441
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee21() {
2442
+ var streamId;
2443
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2444
+ while (1) switch (_context21.prev = _context21.next) {
2445
+ case 0:
2446
+ logger.info('muteRemoteAudio with options: ', userId, mute);
2447
+ streamId = translateTRTCStreamId(userId, exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig); // 音频默认都是主流
2448
+ _context21.next = 4;
2449
+ return this.setAttributes({
2450
+ params: {
2451
+ muteAudio: mute
2452
+ },
2453
+ streamId: streamId,
2454
+ view: this.renderMap.get(streamId)
2455
+ }, 'muteRemoteAudio');
2456
+ case 4:
2457
+ logger.info('muteRemoteAudio success');
2458
+ case 5:
2459
+ case "end":
2460
+ return _context21.stop();
2461
+ }
2462
+ }, _callee21, this);
2463
+ }));
2125
2464
  }
2126
2465
  }, {
2127
2466
  key: "muteAllRemoteAudio",
2128
2467
  value: function muteAllRemoteAudio(mute) {
2129
- var _this12 = this;
2130
- logger.info('muteAllRemoteAudio with options: ', mute);
2131
- var playerList = this.trtc.getPlayerList();
2132
- playerList.forEach(function (player) {
2133
- var streamId = player.streamID;
2134
- var playerAttributes = _this12.setTRTCPlayerAttributes(streamId, {
2135
- muteAudio: mute
2136
- });
2137
- _this12.InterfaceEventEmitter.emit('playerAttributesChange', {
2138
- streamId: streamId,
2139
- view: _this12.renderMap.get(streamId),
2140
- playerAttributes: playerAttributes,
2141
- callback: function callback() {
2142
- logger.info('muteAllRemoteAudio success');
2468
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee23() {
2469
+ var _this11 = this;
2470
+ var playerList;
2471
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2472
+ while (1) switch (_context23.prev = _context23.next) {
2473
+ case 0:
2474
+ logger.info('muteAllRemoteAudio with options: ', mute);
2475
+ playerList = this.trtc.getPlayerList();
2476
+ playerList.forEach(function (player) {
2477
+ return __awaiter(_this11, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee22() {
2478
+ var streamId;
2479
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2480
+ while (1) switch (_context22.prev = _context22.next) {
2481
+ case 0:
2482
+ streamId = player.streamID;
2483
+ _context22.next = 3;
2484
+ return this.setAttributes({
2485
+ params: {
2486
+ muteAudio: mute
2487
+ },
2488
+ streamId: streamId,
2489
+ view: this.renderMap.get(streamId)
2490
+ }, 'muteRemoteAudio');
2491
+ case 3:
2492
+ case "end":
2493
+ return _context22.stop();
2494
+ }
2495
+ }, _callee22, this);
2496
+ }));
2497
+ });
2498
+ logger.info('muteAllRemoteAudio success');
2499
+ case 4:
2500
+ case "end":
2501
+ return _context23.stop();
2143
2502
  }
2144
- });
2145
- });
2503
+ }, _callee23, this);
2504
+ }));
2146
2505
  }
2147
2506
  }, {
2148
2507
  key: "enableAudioVolumeEvaluation",
@@ -2156,29 +2515,31 @@ var TRTCCloud = /*#__PURE__*/function () {
2156
2515
  }, {
2157
2516
  key: "switchCamera",
2158
2517
  value: function switchCamera(frontCamera) {
2159
- var _this13 = this;
2518
+ var _this12 = this;
2160
2519
  logger.info('switchCamera with options: ', frontCamera);
2161
2520
  var pusher = this.trtc.getPusherInstance();
2162
2521
  if (frontCamera === (pusher.pusherAttributes.frontCamera === 'front')) return Promise.resolve();
2163
2522
  return new Promise(function (resolve, reject) {
2164
2523
  wx.createLivePusherContext().switchCamera({
2165
2524
  success: function success(event) {
2166
- return __awaiter(_this13, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2167
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
2168
- while (1) switch (_context12.prev = _context12.next) {
2525
+ return __awaiter(_this12, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee24() {
2526
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2527
+ while (1) switch (_context24.prev = _context24.next) {
2169
2528
  case 0:
2170
- _context12.next = 2;
2171
- return this.setPusherAttributes({
2172
- frontCamera: frontCamera
2529
+ _context24.next = 2;
2530
+ return this.setAttributes({
2531
+ params: {
2532
+ frontCamera: frontCamera
2533
+ }
2173
2534
  }, 'switchCamera');
2174
2535
  case 2:
2175
2536
  logger.info('switchCamera success');
2176
2537
  resolve(event);
2177
2538
  case 4:
2178
2539
  case "end":
2179
- return _context12.stop();
2540
+ return _context24.stop();
2180
2541
  }
2181
- }, _callee12, this);
2542
+ }, _callee24, this);
2182
2543
  }));
2183
2544
  },
2184
2545
  fail: function fail(error) {
@@ -2191,24 +2552,26 @@ var TRTCCloud = /*#__PURE__*/function () {
2191
2552
  }, {
2192
2553
  key: "setBeautyStyle",
2193
2554
  value: function setBeautyStyle(style, beauty, white, ruddiness) {
2194
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
2195
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
2196
- while (1) switch (_context13.prev = _context13.next) {
2555
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee25() {
2556
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2557
+ while (1) switch (_context25.prev = _context25.next) {
2197
2558
  case 0:
2198
2559
  logger.info('setBeautyStyle with options: ', style, beauty, white, ruddiness);
2199
- _context13.next = 3;
2200
- return this.setPusherAttributes({
2201
- beautyStyle: style,
2202
- beautyLevel: beauty,
2203
- whitenessLevel: white
2560
+ _context25.next = 3;
2561
+ return this.setAttributes({
2562
+ params: {
2563
+ beautyStyle: style,
2564
+ beautyLevel: beauty,
2565
+ whitenessLevel: white
2566
+ }
2204
2567
  }, 'setBeautyStyle');
2205
2568
  case 3:
2206
2569
  logger.info('setBeautyStyle success');
2207
2570
  case 4:
2208
2571
  case "end":
2209
- return _context13.stop();
2572
+ return _context25.stop();
2210
2573
  }
2211
- }, _callee13, this);
2574
+ }, _callee25, this);
2212
2575
  }));
2213
2576
  }
2214
2577
  }, {
@@ -2374,38 +2737,109 @@ var TRTCCloud = /*#__PURE__*/function () {
2374
2737
  }
2375
2738
  }
2376
2739
  }, {
2377
- key: "setPusherAttributes",
2378
- value: function setPusherAttributes(params, funName) {
2379
- var _this14 = this;
2380
- // 定义一个超时时间(以毫秒为单位)
2381
- var timeoutDuration = 2000;
2382
- var timeoutPromise = new Promise(function (resolve, reject) {
2383
- setTimeout(function () {
2384
- reject(new Error('setPusherAttributes timed out'));
2385
- }, timeoutDuration);
2740
+ key: "pusherAttributesChange",
2741
+ value: function pusherAttributesChange(pusher) {
2742
+ var _this13 = this;
2743
+ return new Promise(function (resolve) {
2744
+ _this13.InterfaceEventEmitter.emit('pusherAttributesChange', {
2745
+ pusher: pusher,
2746
+ callback: function callback() {
2747
+ resolve(pusher);
2748
+ }
2749
+ });
2386
2750
  });
2387
- var originalPromise = new Promise(function (resolve, reject) {
2388
- try {
2389
- var pusher = {};
2390
- switch (funName) {
2391
- case 'enterRoom':
2392
- pusher = _this14.trtc.enterRoom(params);
2393
- break;
2394
- default:
2395
- pusher = _this14.trtc.setPusherAttributes(params);
2396
- break;
2751
+ }
2752
+ }, {
2753
+ key: "playerAttributesChange",
2754
+ value: function playerAttributesChange(params) {
2755
+ var _this14 = this;
2756
+ var streamId = params.streamId,
2757
+ playerAttributes = params.playerAttributes;
2758
+ return new Promise(function (resolve) {
2759
+ _this14.InterfaceEventEmitter.emit('playerAttributesChange', {
2760
+ streamId: streamId,
2761
+ view: _this14.renderMap.get(streamId),
2762
+ playerAttributes: playerAttributes,
2763
+ callback: function callback() {
2764
+ resolve(playerAttributes);
2397
2765
  }
2398
- _this14.InterfaceEventEmitter.emit('pusherAttributesChange', {
2399
- pusher: pusher,
2400
- callback: function callback() {
2401
- resolve(pusher);
2402
- }
2403
- });
2404
- } catch (err) {
2405
- reject(err);
2406
- }
2766
+ });
2407
2767
  });
2408
- return Promise.race([originalPromise, timeoutPromise]);
2768
+ }
2769
+ }, {
2770
+ key: "setAttributes",
2771
+ value: function setAttributes(options, funName, handleType) {
2772
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee28() {
2773
+ var _this15 = this,
2774
+ _handleMap;
2775
+ var timeoutDuration, timeoutPromise, params, streamId, handleMap, originalPromise;
2776
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2777
+ while (1) switch (_context28.prev = _context28.next) {
2778
+ case 0:
2779
+ // 定义一个超时时间(以毫秒为单位)
2780
+ timeoutDuration = 2000;
2781
+ timeoutPromise = new Promise(function (resolve, reject) {
2782
+ setTimeout(function () {
2783
+ reject(new Error('setAttributes timed out'));
2784
+ }, timeoutDuration);
2785
+ });
2786
+ params = options.params, streamId = options.streamId, options.view;
2787
+ handleMap = (_handleMap = {}, _defineProperty(_handleMap, Handletype.setPlayer, function () {
2788
+ return __awaiter(_this15, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
2789
+ var playerAttributes;
2790
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2791
+ while (1) switch (_context26.prev = _context26.next) {
2792
+ case 0:
2793
+ _context26.next = 2;
2794
+ return this.playerAttributesChange({
2795
+ playerAttributes: this.setTRTCPlayerAttributes(streamId, params),
2796
+ streamId: streamId
2797
+ });
2798
+ case 2:
2799
+ playerAttributes = _context26.sent;
2800
+ return _context26.abrupt("return", playerAttributes);
2801
+ case 4:
2802
+ case "end":
2803
+ return _context26.stop();
2804
+ }
2805
+ }, _callee26, this);
2806
+ }));
2807
+ }), _defineProperty(_handleMap, Handletype.setPusher, function () {
2808
+ return __awaiter(_this15, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
2809
+ var _pusher, pusher;
2810
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2811
+ while (1) switch (_context27.prev = _context27.next) {
2812
+ case 0:
2813
+ if (!(funName === 'enterRoom')) {
2814
+ _context27.next = 5;
2815
+ break;
2816
+ }
2817
+ _context27.next = 3;
2818
+ return this.pusherAttributesChange(this.trtc.enterRoom(params));
2819
+ case 3:
2820
+ _pusher = _context27.sent;
2821
+ return _context27.abrupt("return", _pusher);
2822
+ case 5:
2823
+ _context27.next = 7;
2824
+ return this.pusherAttributesChange(this.trtc.setPusherAttributes(params));
2825
+ case 7:
2826
+ pusher = _context27.sent;
2827
+ return _context27.abrupt("return", pusher);
2828
+ case 9:
2829
+ case "end":
2830
+ return _context27.stop();
2831
+ }
2832
+ }, _callee27, this);
2833
+ }));
2834
+ }), _handleMap);
2835
+ originalPromise = handleMap[handleType] ? handleMap[handleType]() : Promise.reject(new Error('setAttributes fail'));
2836
+ return _context28.abrupt("return", Promise.race([originalPromise, timeoutPromise]));
2837
+ case 6:
2838
+ case "end":
2839
+ return _context28.stop();
2840
+ }
2841
+ }, _callee28);
2842
+ }));
2409
2843
  }
2410
2844
  }], [{
2411
2845
  key: "getTRTCShareInstance",
@@ -2429,7 +2863,7 @@ var TRTCCloud = /*#__PURE__*/function () {
2429
2863
  }]);
2430
2864
  return TRTCCloud;
2431
2865
  }();
2432
- __decorate([setHandle], TRTCCloud.prototype, "setPusherAttributes", null);
2866
+ __decorate([setHandle], TRTCCloud.prototype, "setAttributes", null);
2433
2867
 
2434
2868
  exports.TRTCCloud = TRTCCloud;
2435
2869
  exports.default = TRTCCloud;