@tencentcloud/trtc-cloud-wx 0.0.18 → 0.0.20-beta

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 +808 -350
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,13 +1354,13 @@ 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.18";
1357
+ var version = "0.0.20-beta";
1154
1358
  var description = "";
1155
1359
  var main = "dist/trtc-cloud-wx.js";
1156
1360
  var module$1 = "dist/trtc-cloud-wx.js";
1157
1361
  var type = "module";
1158
1362
  var scripts = {
1159
- build: "npm run clear && rollup -c",
1363
+ build: "npm run clear && rollup -c && node ./build/copy_to_roomkit.js",
1160
1364
  dev: "node ./build/chokidar.js",
1161
1365
  clear: "node ./build/clear.js",
1162
1366
  copy: "node ./build/copy.js",
@@ -1236,7 +1440,6 @@ var TRTCCloud = /*#__PURE__*/function () {
1236
1440
  this.userId = '';
1237
1441
  this.isEnterRoom = false;
1238
1442
  this.isVideoMuted = false;
1239
- this.isMicMuted = false;
1240
1443
  this.isOpenCamera = false;
1241
1444
  this.audioVolumeEvaluation = 0;
1242
1445
  this.allTimer = {};
@@ -1279,7 +1482,6 @@ var TRTCCloud = /*#__PURE__*/function () {
1279
1482
  this.userId = '';
1280
1483
  this.isEnterRoom = false;
1281
1484
  this.isVideoMuted = false;
1282
- this.isMicMuted = false;
1283
1485
  this.isOpenCamera = false;
1284
1486
  Object.keys(this.allTimer).forEach(function (key) {
1285
1487
  clearInterval(_this.allTimer[key]);
@@ -1296,9 +1498,22 @@ var TRTCCloud = /*#__PURE__*/function () {
1296
1498
  _this2.trtc.createPusher({});
1297
1499
  taskMachine.send(TaskQueueEvent.SETPROCESS);
1298
1500
  } else {
1501
+ if (_this2.isEnterRoom) {
1502
+ _this2.exitRoom();
1503
+ }
1299
1504
  taskMachine.send(TaskQueueEvent.SETDONE);
1300
1505
  }
1301
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
+ });
1302
1517
  }
1303
1518
  }, {
1304
1519
  key: "bindTRTCEvent",
@@ -1520,18 +1735,20 @@ var TRTCCloud = /*#__PURE__*/function () {
1520
1735
  this.userId = userId;
1521
1736
  this.isEnterRoom = true;
1522
1737
  _context2.next = 8;
1523
- return this.setPusherAttributes({
1524
- sdkAppID: sdkAppId,
1525
- userID: userId,
1526
- userSig: userSig,
1527
- roomID: roomId,
1528
- strRoomID: strRoomId,
1529
- role: role,
1530
- privateMapKey: privateMapKey,
1531
- scene: translateTRTCAppScene(scene),
1532
- enableMic: false,
1533
- enableCamera: false,
1534
- 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
+ }
1535
1752
  }, 'enterRoom');
1536
1753
  case 8:
1537
1754
  this.trtc.getPusherInstance().start({
@@ -1550,9 +1767,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1550
1767
  break;
1551
1768
  }
1552
1769
  _context.next = 7;
1553
- return this.setPusherAttributes({
1554
- videoPreview: false,
1555
- enableCamera: true
1770
+ return this.setAttributes({
1771
+ params: {
1772
+ videoPreview: false,
1773
+ enableCamera: true
1774
+ }
1556
1775
  }, 'other');
1557
1776
  case 7:
1558
1777
  this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
@@ -1625,9 +1844,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1625
1844
  return _context3.abrupt("return");
1626
1845
  case 7:
1627
1846
  _context3.next = 9;
1628
- return this.setPusherAttributes({
1629
- enableCamera: false,
1630
- enableMic: false
1847
+ return this.setAttributes({
1848
+ params: {
1849
+ enableCamera: false,
1850
+ enableMic: false
1851
+ }
1631
1852
  }, 'switchRole');
1632
1853
  case 9:
1633
1854
  logger.info('switchRole success');
@@ -1670,12 +1891,14 @@ var TRTCCloud = /*#__PURE__*/function () {
1670
1891
  return _context4.abrupt("return");
1671
1892
  case 3:
1672
1893
  _context4.next = 5;
1673
- return this.setPusherAttributes(function () {
1674
- return {
1675
- videoPreview: _this8.isEnterRoom ? _this8.isVideoMuted : true,
1676
- enableCamera: _this8.isEnterRoom ? !_this8.isVideoMuted : false,
1677
- frontCamera: frontCamera ? 'front' : 'back'
1678
- };
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
+ }
1679
1902
  }, 'startLocalPreview');
1680
1903
  case 5:
1681
1904
  pusher = _context4.sent;
@@ -1705,9 +1928,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1705
1928
  case 0:
1706
1929
  logger.info('stopLocalPreview');
1707
1930
  _context5.next = 3;
1708
- return this.setPusherAttributes({
1709
- videoPreview: false,
1710
- enableCamera: false
1931
+ return this.setAttributes({
1932
+ params: {
1933
+ videoPreview: false,
1934
+ enableCamera: false
1935
+ }
1711
1936
  }, 'stopLocalPreview');
1712
1937
  case 3:
1713
1938
  logger.info('stopLocalPreview success');
@@ -1747,31 +1972,46 @@ var TRTCCloud = /*#__PURE__*/function () {
1747
1972
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1748
1973
  while (1) switch (_context6.prev = _context6.next) {
1749
1974
  case 0:
1750
- logger.info('muteLocalVideo with options: ', mute, streamType);
1975
+ logger.info('muteLocalVideo called with options: ', mute, streamType);
1751
1976
  if (this.isOpenCamera) {
1752
- _context6.next = 3;
1977
+ _context6.next = 4;
1753
1978
  break;
1754
1979
  }
1980
+ logger.info('muteLocalVideo early exit: isOpenCamera is false');
1755
1981
  return _context6.abrupt("return");
1756
- case 3:
1982
+ case 4:
1757
1983
  _context6.t0 = streamType;
1758
- _context6.next = _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig ? 6 : _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeSub ? 6 : 11;
1984
+ _context6.next = _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig ? 7 : _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeSub ? 7 : 20;
1759
1985
  break;
1760
- case 6:
1986
+ case 7:
1761
1987
  this.isVideoMuted = mute;
1762
- _context6.next = 9;
1763
- return this.setPusherAttributes({
1764
- videoPreview: mute,
1765
- enableCamera: !mute
1988
+ logger.info('muteLocalVideo: isVideoMuted set to ', mute);
1989
+ _context6.prev = 9;
1990
+ _context6.next = 12;
1991
+ return this.setAttributes({
1992
+ params: {
1993
+ videoPreview: mute,
1994
+ enableCamera: !mute
1995
+ }
1766
1996
  }, 'muteLocalVideo');
1767
- case 9:
1997
+ case 12:
1998
+ logger.info('muteLocalVideo: setAttributes success');
1999
+ _context6.next = 18;
2000
+ break;
2001
+ case 15:
2002
+ _context6.prev = 15;
2003
+ _context6.t1 = _context6["catch"](9);
2004
+ logger.error('muteLocalVideo: setAttributes failed with error ', _context6.t1);
2005
+ case 18:
1768
2006
  logger.info('muteLocalVideo success');
1769
- return _context6.abrupt("break", 11);
1770
- case 11:
2007
+ return _context6.abrupt("break", 21);
2008
+ case 20:
2009
+ logger.info('muteLocalVideo: streamType not supported ', streamType);
2010
+ case 21:
1771
2011
  case "end":
1772
2012
  return _context6.stop();
1773
2013
  }
1774
- }, _callee6, this);
2014
+ }, _callee6, this, [[9, 15]]);
1775
2015
  }));
1776
2016
  }
1777
2017
  /**
@@ -1784,23 +2024,32 @@ var TRTCCloud = /*#__PURE__*/function () {
1784
2024
  }, {
1785
2025
  key: "startRemoteView",
1786
2026
  value: function startRemoteView(userId, view, streamType) {
1787
- var _this9 = this;
1788
- logger.info('startRemoteView with options: ', userId, view, streamType);
1789
- var streamId = translateTRTCStreamId(userId, streamType);
1790
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1791
- muteVideo: false,
1792
- stopVideo: false
1793
- });
1794
- this.renderMap.set(streamId, view);
1795
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1796
- streamId: streamId,
1797
- view: this.renderMap.get(streamId),
1798
- playerAttributes: playerAttributes,
1799
- callback: function callback() {
1800
- logger.info('startRemoteView success');
1801
- _this9.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1802
- }
1803
- });
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
+ }));
1804
2053
  }
1805
2054
  /**
1806
2055
  * 停止显示远端视频画面,同时不再拉取该远端用户的视频数据流
@@ -1810,20 +2059,30 @@ var TRTCCloud = /*#__PURE__*/function () {
1810
2059
  }, {
1811
2060
  key: "stopRemoteView",
1812
2061
  value: function stopRemoteView(userId, streamType) {
1813
- logger.info('stopRemoteView with options: ', userId, streamType);
1814
- var streamId = translateTRTCStreamId(userId, streamType);
1815
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1816
- muteVideo: true,
1817
- stopVideo: true
1818
- });
1819
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1820
- streamId: streamId,
1821
- view: this.renderMap.get(streamId),
1822
- playerAttributes: playerAttributes,
1823
- callback: function callback() {
1824
- logger.info('stopRemoteView success');
1825
- }
1826
- });
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
+ }));
1827
2086
  }
1828
2087
  /**
1829
2088
  * 修改远端视频渲染的 HTML 元素,小程序不支持
@@ -1837,75 +2096,141 @@ var TRTCCloud = /*#__PURE__*/function () {
1837
2096
  }, {
1838
2097
  key: "updateRemoteView",
1839
2098
  value: function updateRemoteView(userId, view, streamType) {
1840
- logger.info('updateRemoteView with options: ', userId, view, streamType);
1841
- if (view !== null) {
1842
- this.startRemoteView(userId, view, streamType);
1843
- return;
1844
- }
1845
- 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
+ }));
1846
2121
  }
1847
2122
  // 停止显示所有远端视频画面,同时不再拉取该远端用户的视频数据流
1848
2123
  }, {
1849
2124
  key: "stopAllRemoteView",
1850
2125
  value: function stopAllRemoteView() {
1851
- var _this10 = this;
1852
- logger.info('stopAllRemoteView');
1853
- var playerList = this.trtc.getPlayerList();
1854
- playerList.forEach(function (player) {
1855
- var streamId = player.streamID;
1856
- var playerAttributes = _this10.setTRTCPlayerAttributes(streamId, {
1857
- muteVideo: true,
1858
- stopVideo: true
1859
- });
1860
- _this10.InterfaceEventEmitter.emit('playerAttributesChange', {
1861
- streamId: streamId,
1862
- view: _this10.renderMap.get(streamId),
1863
- playerAttributes: playerAttributes,
1864
- callback: function callback() {
1865
- 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();
1866
2161
  }
1867
- });
1868
- });
2162
+ }, _callee11, this);
2163
+ }));
1869
2164
  }
1870
2165
  // 暂停接收指定的远端视频流
1871
2166
  // 该接口仅停止接收远程用户的视频流,但并不释放显示资源,所以视频画面会冻屏在 mute 前的最后一帧。
1872
2167
  }, {
1873
2168
  key: "muteRemoteVideoStream",
1874
2169
  value: function muteRemoteVideoStream(userId, mute, streamType) {
1875
- logger.info('muteRemoteVideoStream');
1876
- var streamId = translateTRTCStreamId(userId, streamType);
1877
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1878
- muteVideo: mute
1879
- });
1880
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1881
- streamId: streamId,
1882
- view: this.renderMap.get(streamId),
1883
- playerAttributes: playerAttributes,
1884
- callback: function callback() {
1885
- logger.info('muteRemoteVideoStream success');
1886
- }
1887
- });
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
+ }));
1888
2193
  }
1889
2194
  }, {
1890
2195
  key: "muteAllRemoteVideoStreams",
1891
2196
  value: function muteAllRemoteVideoStreams(mute) {
1892
- var _this11 = this;
1893
- logger.info('muteAllRemoteVideoStreams with options: ', mute);
1894
- var playerList = this.trtc.getPlayerList();
1895
- playerList.forEach(function (player) {
1896
- var streamId = player.streamID;
1897
- var playerAttributes = _this11.setTRTCPlayerAttributes(streamId, {
1898
- muteVideo: mute
1899
- });
1900
- _this11.InterfaceEventEmitter.emit('playerAttributesChange', {
1901
- streamId: streamId,
1902
- view: _this11.renderMap.get(streamId),
1903
- playerAttributes: playerAttributes,
1904
- callback: function callback() {
1905
- 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();
1906
2231
  }
1907
- });
1908
- });
2232
+ }, _callee14, this);
2233
+ }));
1909
2234
  }
1910
2235
  }, {
1911
2236
  key: "setTRTCPlayerAttributes",
@@ -1918,55 +2243,59 @@ var TRTCCloud = /*#__PURE__*/function () {
1918
2243
  }, {
1919
2244
  key: "setVideoEncoderParam",
1920
2245
  value: function setVideoEncoderParam(params) {
1921
- 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() {
1922
2247
  var videoResolution, videoFps, minVideoBitrate, _translateTRTCVideoRe, videoWidth, videoHeight;
1923
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1924
- while (1) switch (_context7.prev = _context7.next) {
2248
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
2249
+ while (1) switch (_context15.prev = _context15.next) {
1925
2250
  case 0:
1926
2251
  logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1927
2252
  videoResolution = params.videoResolution, params.resMode, videoFps = params.videoFps, params.videoBitrate, minVideoBitrate = params.minVideoBitrate;
1928
- _translateTRTCVideoRe = translateTRTCVideoResolution(videoResolution), videoWidth = _translateTRTCVideoRe.videoWidth, videoHeight = _translateTRTCVideoRe.videoHeight; // const videoOrientation = translateTRTCVideoResolutionMode(resMode);
1929
- _context7.next = 5;
1930
- return this.setPusherAttributes({
1931
- videoWidth: videoWidth,
1932
- videoHeight: videoHeight,
1933
- // videoOrientation,
1934
- fps: videoFps,
1935
- 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
+ }
1936
2263
  }, 'setVideoEncoderParam');
1937
2264
  case 5:
1938
2265
  logger.info('setVideoEncoderParam success');
1939
2266
  case 6:
1940
2267
  case "end":
1941
- return _context7.stop();
2268
+ return _context15.stop();
1942
2269
  }
1943
- }, _callee7, this);
2270
+ }, _callee15, this);
1944
2271
  }));
1945
2272
  }
1946
2273
  }, {
1947
2274
  key: "setLocalRenderParams",
1948
2275
  value: function setLocalRenderParams(params) {
1949
- 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() {
1950
2277
  var rotation, mirrorType, videoOrientation, localMirror;
1951
- return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1952
- while (1) switch (_context8.prev = _context8.next) {
2278
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
2279
+ while (1) switch (_context16.prev = _context16.next) {
1953
2280
  case 0:
1954
2281
  logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1955
2282
  rotation = params.rotation, params.fillMode, mirrorType = params.mirrorType;
1956
2283
  videoOrientation = translateTRTCVideoRotation(rotation);
1957
2284
  localMirror = translateTRTCVideoMirrorType(mirrorType);
1958
- _context8.next = 6;
1959
- return this.setPusherAttributes({
1960
- videoOrientation: videoOrientation,
1961
- localMirror: localMirror
2285
+ _context16.next = 6;
2286
+ return this.setAttributes({
2287
+ params: {
2288
+ videoOrientation: videoOrientation,
2289
+ localMirror: localMirror
2290
+ }
1962
2291
  }, 'setLocalRenderParams');
1963
2292
  case 6:
1964
2293
  logger.info('setLocalRenderParams success');
1965
2294
  case 7:
1966
2295
  case "end":
1967
- return _context8.stop();
2296
+ return _context16.stop();
1968
2297
  }
1969
- }, _callee8, this);
2298
+ }, _callee16, this);
1970
2299
  }));
1971
2300
  }
1972
2301
  /**
@@ -1978,147 +2307,201 @@ var TRTCCloud = /*#__PURE__*/function () {
1978
2307
  }, {
1979
2308
  key: "setRemoteRenderParams",
1980
2309
  value: function setRemoteRenderParams(userId, streamType, params) {
1981
- logger.info('setRemoteRenderParams with options: ', userId, streamType, JSON.stringify(params));
1982
- var fillMode = params.fillMode,
1983
- rotation = params.rotation;
1984
- params.mirrorType;
1985
- var streamId = translateTRTCStreamId(userId, streamType); // 音频默认都是主流
1986
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1987
- objectFit: translateVideoFillMod(fillMode),
1988
- orientation: translateTRTCVideoRotation(rotation)
1989
- });
1990
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
1991
- streamId: streamId,
1992
- view: this.renderMap.get(streamId),
1993
- playerAttributes: playerAttributes,
1994
- callback: function callback() {
1995
- logger.info('setRemoteRenderParams success');
1996
- }
1997
- });
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
+ }));
1998
2335
  }
1999
2336
  }, {
2000
2337
  key: "startLocalAudio",
2001
2338
  value: function startLocalAudio(quality) {
2002
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
2003
- var _this12 = this;
2004
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
2005
- 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) {
2006
2342
  case 0:
2007
2343
  logger.info('startLocalAudio with options: ', quality);
2008
2344
  if (!(this.role !== exports.TRTCRoleType.TRTCRoleAnchor)) {
2009
- _context9.next = 3;
2345
+ _context18.next = 3;
2010
2346
  break;
2011
2347
  }
2012
2348
  throw new Error('Current role is audience, unable to access mic. Call switchRole to become a host.');
2013
2349
  case 3:
2014
- if (!this.isMicMuted) {
2015
- _context9.next = 5;
2016
- break;
2017
- }
2018
- throw new Error('The microphone has been muted. Please unmute it first.');
2019
- case 5:
2020
- _context9.next = 7;
2021
- return this.setPusherAttributes(function () {
2022
- return {
2023
- enableMic: !_this12.isMicMuted
2024
- };
2350
+ _context18.next = 5;
2351
+ return this.setAttributes({
2352
+ params: {
2353
+ enableMic: true
2354
+ }
2025
2355
  }, 'startLocalAudio');
2026
- case 7:
2356
+ case 5:
2027
2357
  logger.info('startLocalAudio success');
2028
2358
  this.emit('onMicDidReady');
2029
2359
  this.emit('onUserAudioAvailable', this.userId, 1);
2030
2360
  if (this.enterRoom) {
2031
2361
  this.emit('onSendFirstLocalAudioFrame');
2032
2362
  }
2033
- case 11:
2363
+ case 9:
2034
2364
  case "end":
2035
- return _context9.stop();
2365
+ return _context18.stop();
2036
2366
  }
2037
- }, _callee9, this);
2367
+ }, _callee18, this);
2038
2368
  }));
2039
2369
  }
2040
2370
  }, {
2041
2371
  key: "stopLocalAudio",
2042
2372
  value: function stopLocalAudio() {
2043
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
2044
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
2045
- 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) {
2046
2376
  case 0:
2047
2377
  logger.info('stopLocalAudio');
2048
- _context10.next = 3;
2049
- return this.setPusherAttributes({
2050
- enableMic: false
2378
+ _context19.next = 3;
2379
+ return this.setAttributes({
2380
+ params: {
2381
+ enableMic: false
2382
+ }
2051
2383
  }, 'stopLocalAudio');
2052
2384
  case 3:
2053
2385
  logger.info('stopLocalAudio success');
2054
2386
  this.emit('onUserAudioAvailable', this.userId, 0);
2055
2387
  case 5:
2056
2388
  case "end":
2057
- return _context10.stop();
2389
+ return _context19.stop();
2058
2390
  }
2059
- }, _callee10, this);
2391
+ }, _callee19, this);
2060
2392
  }));
2061
2393
  }
2062
2394
  }, {
2063
2395
  key: "muteLocalAudio",
2064
2396
  value: function muteLocalAudio(mute) {
2065
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
2066
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
2067
- 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) {
2068
2400
  case 0:
2069
- logger.info('muteLocalAudio with options: ', mute);
2070
- _context11.next = 3;
2071
- return this.setPusherAttributes({
2072
- enableMic: !mute
2401
+ logger.info('muteLocalAudio called with options: ', mute);
2402
+ _context20.prev = 1;
2403
+ _context20.next = 4;
2404
+ return this.setAttributes({
2405
+ params: {
2406
+ muted: mute
2407
+ }
2073
2408
  }, 'muteLocalAudio');
2074
- case 3:
2075
- this.isMicMuted = mute;
2076
- logger.info('muteLocalAudio success');
2409
+ case 4:
2410
+ logger.info('setAttributes executed successfully');
2411
+ _context20.next = 11;
2412
+ break;
2413
+ case 7:
2414
+ _context20.prev = 7;
2415
+ _context20.t0 = _context20["catch"](1);
2416
+ logger.error('Error in setAttributes: ', _context20.t0);
2417
+ throw _context20.t0;
2418
+ case 11:
2419
+ _context20.prev = 11;
2077
2420
  this.emit('onUserAudioAvailable', this.userId, mute === true ? 0 : 1);
2078
- case 6:
2421
+ logger.info('onUserAudioAvailable event emitted successfully');
2422
+ _context20.next = 20;
2423
+ break;
2424
+ case 16:
2425
+ _context20.prev = 16;
2426
+ _context20.t1 = _context20["catch"](11);
2427
+ logger.error('Error in emitting onUserAudioAvailable event: ', _context20.t1);
2428
+ throw _context20.t1;
2429
+ case 20:
2430
+ logger.info('muteLocalAudio execution finished');
2431
+ case 21:
2079
2432
  case "end":
2080
- return _context11.stop();
2433
+ return _context20.stop();
2081
2434
  }
2082
- }, _callee11, this);
2435
+ }, _callee20, this, [[1, 7], [11, 16]]);
2083
2436
  }));
2084
2437
  }
2085
2438
  }, {
2086
2439
  key: "muteRemoteAudio",
2087
2440
  value: function muteRemoteAudio(userId, mute) {
2088
- logger.info('muteRemoteAudio with options: ', userId, mute);
2089
- var streamId = translateTRTCStreamId(userId, exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig); // 音频默认都是主流
2090
- var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
2091
- muteAudio: mute
2092
- });
2093
- this.InterfaceEventEmitter.emit('playerAttributesChange', {
2094
- streamId: streamId,
2095
- view: this.renderMap.get(streamId),
2096
- playerAttributes: playerAttributes,
2097
- callback: function callback() {
2098
- logger.info('muteRemoteAudio success');
2099
- }
2100
- });
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
+ }));
2101
2464
  }
2102
2465
  }, {
2103
2466
  key: "muteAllRemoteAudio",
2104
2467
  value: function muteAllRemoteAudio(mute) {
2105
- var _this13 = this;
2106
- logger.info('muteAllRemoteAudio with options: ', mute);
2107
- var playerList = this.trtc.getPlayerList();
2108
- playerList.forEach(function (player) {
2109
- var streamId = player.streamID;
2110
- var playerAttributes = _this13.setTRTCPlayerAttributes(streamId, {
2111
- muteAudio: mute
2112
- });
2113
- _this13.InterfaceEventEmitter.emit('playerAttributesChange', {
2114
- streamId: streamId,
2115
- view: _this13.renderMap.get(streamId),
2116
- playerAttributes: playerAttributes,
2117
- callback: function callback() {
2118
- 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();
2119
2502
  }
2120
- });
2121
- });
2503
+ }, _callee23, this);
2504
+ }));
2122
2505
  }
2123
2506
  }, {
2124
2507
  key: "enableAudioVolumeEvaluation",
@@ -2132,29 +2515,31 @@ var TRTCCloud = /*#__PURE__*/function () {
2132
2515
  }, {
2133
2516
  key: "switchCamera",
2134
2517
  value: function switchCamera(frontCamera) {
2135
- var _this14 = this;
2518
+ var _this12 = this;
2136
2519
  logger.info('switchCamera with options: ', frontCamera);
2137
2520
  var pusher = this.trtc.getPusherInstance();
2138
2521
  if (frontCamera === (pusher.pusherAttributes.frontCamera === 'front')) return Promise.resolve();
2139
2522
  return new Promise(function (resolve, reject) {
2140
2523
  wx.createLivePusherContext().switchCamera({
2141
2524
  success: function success(event) {
2142
- return __awaiter(_this14, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
2143
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
2144
- 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) {
2145
2528
  case 0:
2146
- _context12.next = 2;
2147
- return this.setPusherAttributes({
2148
- frontCamera: frontCamera
2529
+ _context24.next = 2;
2530
+ return this.setAttributes({
2531
+ params: {
2532
+ frontCamera: frontCamera
2533
+ }
2149
2534
  }, 'switchCamera');
2150
2535
  case 2:
2151
2536
  logger.info('switchCamera success');
2152
2537
  resolve(event);
2153
2538
  case 4:
2154
2539
  case "end":
2155
- return _context12.stop();
2540
+ return _context24.stop();
2156
2541
  }
2157
- }, _callee12, this);
2542
+ }, _callee24, this);
2158
2543
  }));
2159
2544
  },
2160
2545
  fail: function fail(error) {
@@ -2167,24 +2552,26 @@ var TRTCCloud = /*#__PURE__*/function () {
2167
2552
  }, {
2168
2553
  key: "setBeautyStyle",
2169
2554
  value: function setBeautyStyle(style, beauty, white, ruddiness) {
2170
- return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
2171
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
2172
- 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) {
2173
2558
  case 0:
2174
2559
  logger.info('setBeautyStyle with options: ', style, beauty, white, ruddiness);
2175
- _context13.next = 3;
2176
- return this.setPusherAttributes({
2177
- beautyStyle: style,
2178
- beautyLevel: beauty,
2179
- whitenessLevel: white
2560
+ _context25.next = 3;
2561
+ return this.setAttributes({
2562
+ params: {
2563
+ beautyStyle: style,
2564
+ beautyLevel: beauty,
2565
+ whitenessLevel: white
2566
+ }
2180
2567
  }, 'setBeautyStyle');
2181
2568
  case 3:
2182
2569
  logger.info('setBeautyStyle success');
2183
2570
  case 4:
2184
2571
  case "end":
2185
- return _context13.stop();
2572
+ return _context25.stop();
2186
2573
  }
2187
- }, _callee13, this);
2574
+ }, _callee25, this);
2188
2575
  }));
2189
2576
  }
2190
2577
  }, {
@@ -2350,38 +2737,109 @@ var TRTCCloud = /*#__PURE__*/function () {
2350
2737
  }
2351
2738
  }
2352
2739
  }, {
2353
- key: "setPusherAttributes",
2354
- value: function setPusherAttributes(params, funName) {
2355
- var _this15 = this;
2356
- // 定义一个超时时间(以毫秒为单位)
2357
- var timeoutDuration = 2000;
2358
- var timeoutPromise = new Promise(function (resolve, reject) {
2359
- setTimeout(function () {
2360
- reject(new Error('setPusherAttributes timed out'));
2361
- }, 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
+ });
2362
2750
  });
2363
- var originalPromise = new Promise(function (resolve, reject) {
2364
- try {
2365
- var pusher = {};
2366
- switch (funName) {
2367
- case 'enterRoom':
2368
- pusher = _this15.trtc.enterRoom(params);
2369
- break;
2370
- default:
2371
- pusher = _this15.trtc.setPusherAttributes(params);
2372
- 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);
2373
2765
  }
2374
- _this15.InterfaceEventEmitter.emit('pusherAttributesChange', {
2375
- pusher: pusher,
2376
- callback: function callback() {
2377
- resolve(pusher);
2378
- }
2379
- });
2380
- } catch (err) {
2381
- reject(err);
2382
- }
2766
+ });
2383
2767
  });
2384
- 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
+ }));
2385
2843
  }
2386
2844
  }], [{
2387
2845
  key: "getTRTCShareInstance",
@@ -2405,7 +2863,7 @@ var TRTCCloud = /*#__PURE__*/function () {
2405
2863
  }]);
2406
2864
  return TRTCCloud;
2407
2865
  }();
2408
- __decorate([setHandle], TRTCCloud.prototype, "setPusherAttributes", null);
2866
+ __decorate([setHandle], TRTCCloud.prototype, "setAttributes", null);
2409
2867
 
2410
2868
  exports.TRTCCloud = TRTCCloud;
2411
2869
  exports.default = TRTCCloud;