@tencentcloud/trtc-cloud-wx 0.0.17 → 0.0.18

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 +789 -303
package/trtc-cloud-wx.js CHANGED
@@ -413,6 +413,57 @@ function _nonIterableSpread() {
413
413
  function _nonIterableRest() {
414
414
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
415
415
  }
416
+ function _createForOfIteratorHelper(o, allowArrayLike) {
417
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
418
+ if (!it) {
419
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
420
+ if (it) o = it;
421
+ var i = 0;
422
+ var F = function () {};
423
+ return {
424
+ s: F,
425
+ n: function () {
426
+ if (i >= o.length) return {
427
+ done: true
428
+ };
429
+ return {
430
+ done: false,
431
+ value: o[i++]
432
+ };
433
+ },
434
+ e: function (e) {
435
+ throw e;
436
+ },
437
+ f: F
438
+ };
439
+ }
440
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
441
+ }
442
+ var normalCompletion = true,
443
+ didErr = false,
444
+ err;
445
+ return {
446
+ s: function () {
447
+ it = it.call(o);
448
+ },
449
+ n: function () {
450
+ var step = it.next();
451
+ normalCompletion = step.done;
452
+ return step;
453
+ },
454
+ e: function (e) {
455
+ didErr = true;
456
+ err = e;
457
+ },
458
+ f: function () {
459
+ try {
460
+ if (!normalCompletion && it.return != null) it.return();
461
+ } finally {
462
+ if (didErr) throw err;
463
+ }
464
+ }
465
+ };
466
+ }
416
467
  function _toPrimitive(input, hint) {
417
468
  if (typeof input !== "object" || input === null) return input;
418
469
  var prim = input[Symbol.toPrimitive];
@@ -444,6 +495,13 @@ PERFORMANCE OF THIS SOFTWARE.
444
495
  ***************************************************************************** */
445
496
  /* global Reflect, Promise, SuppressedError, Symbol */
446
497
 
498
+ function __decorate(decorators, target, key, desc) {
499
+ var c = arguments.length,
500
+ r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc,
501
+ d;
502
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
503
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
504
+ }
447
505
  function __awaiter(thisArg, _arguments, P, generator) {
448
506
  function adopt(value) {
449
507
  return value instanceof P ? value : new P(function (resolve) {
@@ -562,6 +620,284 @@ exports.TRTCBeautyStyle = void 0;
562
620
  TRTCBeautyStyle[TRTCBeautyStyle["TRTCBeautyStyleNature"] = 1] = "TRTCBeautyStyleNature";
563
621
  })(exports.TRTCBeautyStyle || (exports.TRTCBeautyStyle = {}));
564
622
 
623
+ var Task = /*#__PURE__*/function () {
624
+ function Task(optinos) {
625
+ _classCallCheck(this, Task);
626
+ var _optinos$priority = optinos.priority,
627
+ priority = _optinos$priority === void 0 ? 0 : _optinos$priority,
628
+ action = optinos.action,
629
+ args = optinos.args,
630
+ resolve = optinos.resolve,
631
+ reject = optinos.reject,
632
+ ctx = optinos.ctx,
633
+ name = optinos.name;
634
+ this.ctx = ctx;
635
+ this.priority = priority;
636
+ this.action = action;
637
+ this.args = args;
638
+ this.resolve = resolve;
639
+ this.reject = reject;
640
+ this.name = name;
641
+ this.single = this.whetherSingle(name);
642
+ this.sequenceNumber = Task.nextSequenceNumber++;
643
+ }
644
+ _createClass(Task, [{
645
+ key: "whetherSingle",
646
+ value: function whetherSingle(funName) {
647
+ switch (funName) {
648
+ case 'enterRoom':
649
+ return true;
650
+ default:
651
+ return false;
652
+ }
653
+ }
654
+ }]);
655
+ return Task;
656
+ }();
657
+ 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
+ var TaskQueueState;
675
+ (function (TaskQueueState) {
676
+ TaskQueueState["IDLE"] = "idle";
677
+ TaskQueueState["PENDING"] = "pending";
678
+ TaskQueueState["PROCESS"] = "process";
679
+ })(TaskQueueState || (TaskQueueState = {}));
680
+ var TaskQueueEvent;
681
+ (function (TaskQueueEvent) {
682
+ TaskQueueEvent["SET"] = "SET";
683
+ TaskQueueEvent["SETPROCESS"] = "SETPROCESS";
684
+ TaskQueueEvent["SETDONE"] = "SETDONE";
685
+ })(TaskQueueEvent || (TaskQueueEvent = {}));
686
+ var TaskMachine = /*#__PURE__*/function () {
687
+ function TaskMachine() {
688
+ _classCallCheck(this, TaskMachine);
689
+ this.isProcessing = false; // 添加一个标志以跟踪任务是否正在处理
690
+ this.pusherDomReady = false;
691
+ this.state = TaskQueueState.IDLE;
692
+ this.context = {
693
+ taskQueue: [],
694
+ debounceTimeout: null
695
+ };
696
+ }
697
+ _createClass(TaskMachine, [{
698
+ key: "setPusherDomReady",
699
+ value: function setPusherDomReady(isReady) {
700
+ this.pusherDomReady = isReady;
701
+ return this.pusherDomReady;
702
+ }
703
+ }, {
704
+ key: "send",
705
+ value: function send(event) {
706
+ switch (this.state) {
707
+ case TaskQueueState.IDLE:
708
+ if (event === TaskQueueEvent.SET) {
709
+ this.state = TaskQueueState.PENDING;
710
+ this.processTasks();
711
+ }
712
+ break;
713
+ case TaskQueueState.PENDING:
714
+ if (event === TaskQueueEvent.SETPROCESS) {
715
+ this.processTasks();
716
+ }
717
+ if (event === TaskQueueEvent.SETDONE) {
718
+ this.state = TaskQueueState.IDLE;
719
+ }
720
+ break;
721
+ case TaskQueueState.PROCESS:
722
+ if (event === TaskQueueEvent.SETDONE) {
723
+ this.state = TaskQueueState.IDLE;
724
+ }
725
+ break;
726
+ }
727
+ }
728
+ }, {
729
+ key: "addTask",
730
+ value: function addTask(task) {
731
+ this.addTaskToQueue(task);
732
+ if (this.state === TaskQueueState.IDLE) {
733
+ this.send(TaskQueueEvent.SET);
734
+ } else if (this.state === TaskQueueState.PENDING) {
735
+ this.send(TaskQueueEvent.SETPROCESS);
736
+ }
737
+ }
738
+ }, {
739
+ key: "addTaskToQueue",
740
+ value: function addTaskToQueue(task) {
741
+ this.context.taskQueue.push(task);
742
+ this.context.taskQueue.sort(function (a, b) {
743
+ if (a.priority !== b.priority) {
744
+ return a.priority - b.priority;
745
+ }
746
+ return a.sequenceNumber - b.sequenceNumber;
747
+ });
748
+ }
749
+ }, {
750
+ key: "processTasks",
751
+ value: function processTasks() {
752
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
753
+ var _this = this;
754
+ var currentTasks, singleTasks, exceptSingleTask, _iterator, _step, _task3, args, task, sequenceTask, r, _iterator2, _step2, _task, _iterator3, _step3, _task2;
755
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
756
+ while (1) switch (_context.prev = _context.next) {
757
+ case 0:
758
+ if (!(this.isProcessing || !this.pusherDomReady || this.context.taskQueue.length === 0)) {
759
+ _context.next = 2;
760
+ break;
761
+ }
762
+ return _context.abrupt("return");
763
+ case 2:
764
+ this.isProcessing = true;
765
+ this.state = TaskQueueState.PROCESS;
766
+ currentTasks = _toConsumableArray(this.context.taskQueue);
767
+ this.context.taskQueue = [];
768
+ singleTasks = currentTasks.filter(function (task) {
769
+ return task.single;
770
+ });
771
+ exceptSingleTask = currentTasks.filter(function (task) {
772
+ return !task.single;
773
+ });
774
+ _iterator = _createForOfIteratorHelper(singleTasks);
775
+ _context.prev = 9;
776
+ _iterator.s();
777
+ case 11:
778
+ if ((_step = _iterator.n()).done) {
779
+ _context.next = 24;
780
+ break;
781
+ }
782
+ _task3 = _step.value;
783
+ _context.prev = 13;
784
+ _context.next = 16;
785
+ return _task3.action.call(_task3.ctx, _task3.args, _task3.name);
786
+ case 16:
787
+ _task3.result = _context.sent;
788
+ _context.next = 22;
789
+ break;
790
+ case 19:
791
+ _context.prev = 19;
792
+ _context.t0 = _context["catch"](13);
793
+ _task3.err = _context.t0;
794
+ case 22:
795
+ _context.next = 11;
796
+ break;
797
+ case 24:
798
+ _context.next = 29;
799
+ break;
800
+ case 26:
801
+ _context.prev = 26;
802
+ _context.t1 = _context["catch"](9);
803
+ _iterator.e(_context.t1);
804
+ case 29:
805
+ _context.prev = 29;
806
+ _iterator.f();
807
+ return _context.finish(29);
808
+ case 32:
809
+ args = exceptSingleTask.reduce(function (acc, cur) {
810
+ return Object.assign(Object.assign({}, acc), typeof cur.args === 'function' ? cur.args() : cur.args);
811
+ }, {});
812
+ task = exceptSingleTask[0];
813
+ sequenceTask = currentTasks.sort(function (a, b) {
814
+ return a.sequenceNumber - b.sequenceNumber;
815
+ });
816
+ _context.prev = 35;
817
+ r = null;
818
+ if (!task) {
819
+ _context.next = 41;
820
+ break;
821
+ }
822
+ _context.next = 40;
823
+ return task.action.call(task.ctx, args);
824
+ case 40:
825
+ r = _context.sent;
826
+ case 41:
827
+ _iterator2 = _createForOfIteratorHelper(sequenceTask);
828
+ try {
829
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
830
+ _task = _step2.value;
831
+ if (_task.err) {
832
+ _task.reject(_task.err);
833
+ } else {
834
+ _task.resolve(_task.result || r);
835
+ }
836
+ }
837
+ } catch (err) {
838
+ _iterator2.e(err);
839
+ } finally {
840
+ _iterator2.f();
841
+ }
842
+ _context.next = 49;
843
+ break;
844
+ case 45:
845
+ _context.prev = 45;
846
+ _context.t2 = _context["catch"](35);
847
+ _iterator3 = _createForOfIteratorHelper(sequenceTask);
848
+ try {
849
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
850
+ _task2 = _step3.value;
851
+ _task2.reject(_context.t2);
852
+ }
853
+ } catch (err) {
854
+ _iterator3.e(err);
855
+ } finally {
856
+ _iterator3.f();
857
+ }
858
+ case 49:
859
+ this.isProcessing = false;
860
+ this.send(TaskQueueEvent.SETDONE);
861
+ if (this.context.taskQueue.length > 0) {
862
+ Promise.resolve().then(function () {
863
+ _this.processTasks();
864
+ })["catch"](console.error);
865
+ }
866
+ case 52:
867
+ case "end":
868
+ return _context.stop();
869
+ }
870
+ }, _callee, this, [[9, 26, 29, 32], [13, 19], [35, 45]]);
871
+ }));
872
+ }
873
+ }]);
874
+ return TaskMachine;
875
+ }();
876
+ var taskMachine = new TaskMachine();
877
+ var setHandle = function setHandle(target, key, descriptor) {
878
+ var originalMethod = descriptor.value;
879
+ descriptor.value = function () {
880
+ var _this2 = this;
881
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
882
+ args[_key] = arguments[_key];
883
+ }
884
+ 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
+ }));
896
+ });
897
+ };
898
+ return descriptor;
899
+ };
900
+
565
901
  var _TRTCVideoResolutionM, _TRTCBeautyStyleMap, _TRTCVideoFillModeMap;
566
902
  var translateTRTCAppScene = function translateTRTCAppScene(scene) {
567
903
  switch (scene) {
@@ -814,7 +1150,7 @@ var Logger = /*#__PURE__*/function () {
814
1150
  var logger = new Logger();
815
1151
 
816
1152
  var name = "@tencentcloud/trtc-cloud-wx";
817
- var version = "0.0.16";
1153
+ var version = "0.0.18";
818
1154
  var description = "";
819
1155
  var main = "dist/trtc-cloud-wx.js";
820
1156
  var module$1 = "dist/trtc-cloud-wx.js";
@@ -827,7 +1163,7 @@ var scripts = {
827
1163
  doc: "npx typedoc --tsconfig typedoc.json",
828
1164
  "doc:watch": "typedoc --watch",
829
1165
  "doc:build": "jsdoc -c jsdoc.json",
830
- publish: "npm run build && bash ./sdk_publish.bash"
1166
+ publish: "bash ./sdk_publish.bash"
831
1167
  };
832
1168
  var keywords = [
833
1169
  ];
@@ -899,7 +1235,8 @@ var TRTCCloud = /*#__PURE__*/function () {
899
1235
  this.role = exports.TRTCRoleType.TRTCRoleAnchor;
900
1236
  this.userId = '';
901
1237
  this.isEnterRoom = false;
902
- this.isMuted = false;
1238
+ this.isVideoMuted = false;
1239
+ this.isMicMuted = false;
903
1240
  this.isOpenCamera = false;
904
1241
  this.audioVolumeEvaluation = 0;
905
1242
  this.allTimer = {};
@@ -919,6 +1256,7 @@ var TRTCCloud = /*#__PURE__*/function () {
919
1256
  }, {
920
1257
  key: "destroy",
921
1258
  value: function destroy() {
1259
+ this.offTRTCEvent();
922
1260
  this.EventEmitter.removeAllListeners();
923
1261
  this.InterfaceEventEmitter.removeAllListeners();
924
1262
  this.trtc.exitRoom();
@@ -929,8 +1267,8 @@ var TRTCCloud = /*#__PURE__*/function () {
929
1267
  this.trtc = new TRTC(this);
930
1268
  this.trtc.setLogLevel(3);
931
1269
  this.TRTC_EVENT = this.trtc.EVENT;
932
- this.trtc.createPusher({});
933
1270
  this.bindTRTCEvent();
1271
+ this.bindComponentEvent();
934
1272
  this.handleNetworkQuality = this.getHandleNetworkQuality(2000);
935
1273
  }
936
1274
  }, {
@@ -940,17 +1278,32 @@ var TRTCCloud = /*#__PURE__*/function () {
940
1278
  this.role = exports.TRTCRoleType.TRTCRoleAnchor;
941
1279
  this.userId = '';
942
1280
  this.isEnterRoom = false;
943
- this.isMuted = false;
1281
+ this.isVideoMuted = false;
1282
+ this.isMicMuted = false;
944
1283
  this.isOpenCamera = false;
945
1284
  Object.keys(this.allTimer).forEach(function (key) {
946
1285
  clearInterval(_this.allTimer[key]);
947
1286
  _this.allTimer[key] = null;
948
1287
  });
949
1288
  }
1289
+ }, {
1290
+ key: "bindComponentEvent",
1291
+ value: function bindComponentEvent() {
1292
+ var _this2 = this;
1293
+ this.InterfaceEventEmitter.on('pusherDomReady', function (isReady) {
1294
+ taskMachine.setPusherDomReady(isReady);
1295
+ if (isReady) {
1296
+ _this2.trtc.createPusher({});
1297
+ taskMachine.send(TaskQueueEvent.SETPROCESS);
1298
+ } else {
1299
+ taskMachine.send(TaskQueueEvent.SETDONE);
1300
+ }
1301
+ });
1302
+ }
950
1303
  }, {
951
1304
  key: "bindTRTCEvent",
952
1305
  value: function bindTRTCEvent() {
953
- var _this2 = this;
1306
+ var _this3 = this;
954
1307
  this.trtc.on(this.TRTC_EVENT.LOCAL_LEAVE, function (event) {
955
1308
  // todo 第二个参数为进房耗时 此处调用start的时候处理
956
1309
  // this.emit('onEnterRoom', 0)
@@ -959,42 +1312,42 @@ var TRTCCloud = /*#__PURE__*/function () {
959
1312
  var _event$data = event.data,
960
1313
  code = _event$data.code,
961
1314
  message = _event$data.message;
962
- _this2.emit('onError', code, message);
1315
+ _this3.emit('onError', code, message);
963
1316
  });
964
1317
  this.trtc.on(this.TRTC_EVENT.REMOTE_USER_JOIN, function (event) {
965
1318
  var userID = event.data.userID;
966
- _this2.emit('onRemoteUserEnterRoom', userID);
1319
+ _this3.emit('onRemoteUserEnterRoom', userID);
967
1320
  });
968
1321
  // 远端用户退出
969
1322
  this.trtc.on(this.TRTC_EVENT.REMOTE_USER_LEAVE, function (event) {
970
1323
  var _event$data2 = event.data,
971
1324
  userID = _event$data2.userID;
972
1325
  _event$data2.playerList;
973
- _this2.InterfaceEventEmitter.emit('onRemoteUserLeaveRoom', userID, 0);
974
- _this2.emit('onUserVideoAvailable', userID, 0);
975
- _this2.emit('onUserSubStreamAvailable', userID, 0);
976
- _this2.emit('onRemoteUserLeaveRoom', userID, 0);
1326
+ _this3.InterfaceEventEmitter.emit('onRemoteUserLeaveRoom', userID, 0);
1327
+ _this3.emit('onUserVideoAvailable', userID, 0);
1328
+ _this3.emit('onUserSubStreamAvailable', userID, 0);
1329
+ _this3.emit('onRemoteUserLeaveRoom', userID, 0);
977
1330
  });
978
1331
  // 远端用户推送视频
979
1332
  this.trtc.on(this.TRTC_EVENT.REMOTE_VIDEO_ADD, function (event) {
980
1333
  var player = event.data.player;
981
- _this2.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 1);
1334
+ _this3.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 1);
982
1335
  });
983
1336
  // 远端用户取消推送视频
984
1337
  this.trtc.on(this.TRTC_EVENT.REMOTE_VIDEO_REMOVE, function (event) {
985
1338
  var player = event.data.player;
986
- _this2.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 0);
1339
+ _this3.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 0);
987
1340
  });
988
1341
  // 远端用户推送音频
989
1342
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_ADD, function (event) {
990
1343
  var player = event.data.player;
991
- _this2.emit('onUserAudioAvailable', player.userID, 1);
992
- _this2.muteRemoteAudio(player.userID, false);
1344
+ _this3.emit('onUserAudioAvailable', player.userID, 1);
1345
+ _this3.muteRemoteAudio(player.userID, false);
993
1346
  });
994
1347
  // 远端用户取消推送音频
995
1348
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_REMOVE, function (event) {
996
1349
  var player = event.data.player;
997
- _this2.emit('onUserAudioAvailable', player.userID, 0);
1350
+ _this3.emit('onUserAudioAvailable', player.userID, 0);
998
1351
  });
999
1352
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_VOLUME_UPDATE, function (event) {
1000
1353
  var playerList = event.data.playerList;
@@ -1004,7 +1357,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1004
1357
  volume: player.volume
1005
1358
  };
1006
1359
  });
1007
- _this2.handleAudioVolumeUpdate(userVolumes);
1360
+ _this3.handleAudioVolumeUpdate(userVolumes);
1008
1361
  });
1009
1362
  this.trtc.on(this.TRTC_EVENT.LOCAL_AUDIO_VOLUME_UPDATE, function (event) {
1010
1363
  var pusher = event.data.pusher;
@@ -1012,25 +1365,39 @@ var TRTCCloud = /*#__PURE__*/function () {
1012
1365
  userId: pusher.userID,
1013
1366
  volume: pusher.volume
1014
1367
  }];
1015
- _this2.handleAudioVolumeUpdate(userVolumes);
1368
+ _this3.handleAudioVolumeUpdate(userVolumes);
1016
1369
  });
1017
1370
  this.trtc.on(this.TRTC_EVENT.LOCAL_NET_STATE_UPDATE, function (event) {
1018
1371
  var pusher = event.data.pusher;
1019
- _this2.handleNetworkQuality({
1372
+ _this3.handleNetworkQuality({
1020
1373
  pusher: pusher
1021
1374
  });
1022
1375
  });
1023
1376
  this.trtc.on(this.TRTC_EVENT.REMOTE_NET_STATE_UPDATE, function (event) {
1024
1377
  var playerList = event.data.playerList;
1025
- _this2.handleNetworkQuality({
1378
+ _this3.handleNetworkQuality({
1026
1379
  playerList: playerList
1027
1380
  });
1028
1381
  });
1029
1382
  }
1383
+ }, {
1384
+ key: "offTRTCEvent",
1385
+ value: function offTRTCEvent() {
1386
+ this.trtc.off(this.TRTC_EVENT.LOCAL_LEAVE);
1387
+ this.trtc.off(this.TRTC_EVENT.ERROR);
1388
+ this.trtc.off(this.TRTC_EVENT.REMOTE_USER_JOIN);
1389
+ this.trtc.off(this.TRTC_EVENT.REMOTE_USER_LEAVE);
1390
+ this.trtc.off(this.TRTC_EVENT.REMOTE_VIDEO_ADD);
1391
+ this.trtc.off(this.TRTC_EVENT.REMOTE_VIDEO_REMOVE);
1392
+ this.trtc.off(this.TRTC_EVENT.REMOTE_AUDIO_ADD);
1393
+ this.trtc.off(this.TRTC_EVENT.REMOTE_AUDIO_REMOVE);
1394
+ this.trtc.off(this.TRTC_EVENT.REMOTE_AUDIO_VOLUME_UPDATE);
1395
+ this.trtc.off(this.TRTC_EVENT.REMOTE_NET_STATE_UPDATE);
1396
+ }
1030
1397
  }, {
1031
1398
  key: "getHandleAudioVolumeUpdate",
1032
1399
  value: function getHandleAudioVolumeUpdate(interval) {
1033
- var _this3 = this;
1400
+ var _this4 = this;
1034
1401
  var _a;
1035
1402
  if ((_a = this.allTimer) === null || _a === void 0 ? void 0 : _a.AudioVolume) {
1036
1403
  clearInterval(this.allTimer.AudioVolume);
@@ -1047,12 +1414,12 @@ var TRTCCloud = /*#__PURE__*/function () {
1047
1414
  this.InterfaceEventEmitter.on('onRemoteUserLeaveRoom', filterUselessItem, this.getHandleAudioVolumeUpdate);
1048
1415
  return function (userVolumes) {
1049
1416
  tempUserVolumes = uniqueFunc([].concat(_toConsumableArray(userVolumes), _toConsumableArray(tempUserVolumes)), 'userId');
1050
- if (_this3.allTimer.AudioVolume) return;
1417
+ if (_this4.allTimer.AudioVolume) return;
1051
1418
  var timer = setInterval(function () {
1052
- _this3.emit('onUserVoiceVolume', tempUserVolumes, tempUserVolumes.length, 0 // todo 此参数无用,暂时废弃
1419
+ _this4.emit('onUserVoiceVolume', tempUserVolumes, tempUserVolumes.length, 0 // todo 此参数无用,暂时废弃
1053
1420
  );
1054
1421
  }, interval);
1055
- _this3.allTimer.AudioVolume = timer;
1422
+ _this4.allTimer.AudioVolume = timer;
1056
1423
  };
1057
1424
  }
1058
1425
  }, {
@@ -1061,7 +1428,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1061
1428
  }, {
1062
1429
  key: "getHandleNetworkQuality",
1063
1430
  value: function getHandleNetworkQuality(interval) {
1064
- var _this4 = this;
1431
+ var _this5 = this;
1065
1432
  var _a;
1066
1433
  if ((_a = this.allTimer) === null || _a === void 0 ? void 0 : _a.networkQuality) {
1067
1434
  clearInterval(this.allTimer.networkQuality);
@@ -1092,11 +1459,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1092
1459
  };
1093
1460
  });
1094
1461
  }
1095
- if (_this4.allTimer.networkQuality) return;
1462
+ if (_this5.allTimer.networkQuality) return;
1096
1463
  var timer = setInterval(function () {
1097
- _this4.emit('onNetworkQuality', resultQuality.localQuality, resultQuality.remoteQuality);
1464
+ _this5.emit('onNetworkQuality', resultQuality.localQuality, resultQuality.remoteQuality);
1098
1465
  }, interval);
1099
- _this4.allTimer.networkQuality = timer;
1466
+ _this5.allTimer.networkQuality = timer;
1100
1467
  };
1101
1468
  }
1102
1469
  }, {
@@ -1136,67 +1503,78 @@ var TRTCCloud = /*#__PURE__*/function () {
1136
1503
  }, {
1137
1504
  key: "enterRoom",
1138
1505
  value: function enterRoom(params, scene) {
1139
- var _this5 = this;
1140
- var startTime = new Date().getTime();
1141
- var sdkAppId = params.sdkAppId,
1142
- userId = params.userId,
1143
- userSig = params.userSig,
1144
- roomId = params.roomId,
1145
- strRoomId = params.strRoomId,
1146
- role = params.role,
1147
- privateMapKey = params.privateMapKey;
1148
- logger.setInfo({
1149
- sdkAppId: sdkAppId,
1150
- userId: userId,
1151
- roomId: strRoomId
1152
- });
1153
- logger.info('enterRoom with options: ', JSON.stringify(params), scene);
1154
- this.userId = userId;
1155
- this.trtc.createPusher(this.trtc.getPusherAttributes());
1156
- var pusher = this.trtc.enterRoom({
1157
- sdkAppID: sdkAppId,
1158
- userID: userId,
1159
- userSig: userSig,
1160
- roomID: roomId,
1161
- strRoomID: strRoomId,
1162
- role: role,
1163
- privateMapKey: privateMapKey,
1164
- scene: translateTRTCAppScene(scene),
1165
- enableMic: false,
1166
- enableCamera: false,
1167
- videoPreview: false
1168
- });
1169
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1170
- pusher: pusher,
1171
- callback: function callback() {
1172
- _this5.trtc.getPusherInstance().start({
1173
- success: function success() {
1174
- logger.info('enterRoom success');
1175
- _this5.scene = scene;
1176
- _this5.isEnterRoom = true;
1177
- var endTime = new Date().getTime();
1178
- _this5.emit('onEnterRoom', endTime - startTime);
1179
- if (_this5.trtc.getPusherAttributes().videoPreview === true) {
1180
- // 如果进房前有打开摄像头,需要开启视频上行,并抛出 onSendFirstLocalVideoFrame 事件
1181
- var _pusher = _this5.trtc.setPusherAttributes({
1182
- videoPreview: false,
1183
- enableCamera: true
1184
- });
1185
- _this5.InterfaceEventEmitter.emit('pusherAttributesChange', {
1186
- pusher: _pusher,
1187
- callback: function callback() {
1188
- _this5.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1189
- }
1190
- });
1191
- }
1192
- },
1193
- fail: function fail() {
1194
- logger.info('enterRoom fail');
1195
- _this5.emit('onEnterRoom', -1);
1196
- }
1197
- });
1198
- }
1199
- });
1506
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1507
+ var _this6 = this;
1508
+ var startTime, sdkAppId, userId, userSig, roomId, strRoomId, role, privateMapKey;
1509
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1510
+ while (1) switch (_context2.prev = _context2.next) {
1511
+ case 0:
1512
+ startTime = new Date().getTime();
1513
+ sdkAppId = params.sdkAppId, userId = params.userId, userSig = params.userSig, roomId = params.roomId, strRoomId = params.strRoomId, role = params.role, privateMapKey = params.privateMapKey;
1514
+ logger.setInfo({
1515
+ sdkAppId: sdkAppId,
1516
+ userId: userId,
1517
+ roomId: strRoomId
1518
+ });
1519
+ logger.info('enterRoom with options: ', JSON.stringify(params), scene);
1520
+ this.userId = userId;
1521
+ this.isEnterRoom = true;
1522
+ _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
1535
+ }, 'enterRoom');
1536
+ case 8:
1537
+ this.trtc.getPusherInstance().start({
1538
+ success: function success() {
1539
+ return __awaiter(_this6, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1540
+ var endTime;
1541
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1542
+ while (1) switch (_context.prev = _context.next) {
1543
+ case 0:
1544
+ logger.info('enterRoom success');
1545
+ this.scene = scene;
1546
+ endTime = new Date().getTime();
1547
+ this.emit('onEnterRoom', endTime - startTime);
1548
+ if (!(this.trtc.getPusherAttributes().videoPreview === true)) {
1549
+ _context.next = 8;
1550
+ break;
1551
+ }
1552
+ _context.next = 7;
1553
+ return this.setPusherAttributes({
1554
+ videoPreview: false,
1555
+ enableCamera: true
1556
+ }, 'other');
1557
+ case 7:
1558
+ this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1559
+ case 8:
1560
+ case "end":
1561
+ return _context.stop();
1562
+ }
1563
+ }, _callee, this);
1564
+ }));
1565
+ },
1566
+ fail: function fail() {
1567
+ _this6.isEnterRoom = false;
1568
+ logger.info('enterRoom fail');
1569
+ _this6.emit('onEnterRoom', -1);
1570
+ }
1571
+ });
1572
+ case 9:
1573
+ case "end":
1574
+ return _context2.stop();
1575
+ }
1576
+ }, _callee2, this);
1577
+ }));
1200
1578
  }
1201
1579
  /**
1202
1580
  * @category 房间
@@ -1204,7 +1582,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1204
1582
  }, {
1205
1583
  key: "exitRoom",
1206
1584
  value: function exitRoom() {
1207
- var _this6 = this;
1585
+ var _this7 = this;
1208
1586
  logger.info('exitRoom');
1209
1587
  var _this$trtc$exitRoom = this.trtc.exitRoom(),
1210
1588
  pusher = _this$trtc$exitRoom.pusher;
@@ -1212,8 +1590,8 @@ var TRTCCloud = /*#__PURE__*/function () {
1212
1590
  pusher: pusher,
1213
1591
  callback: function callback() {
1214
1592
  logger.info('exitRoom success');
1215
- _this6.reset();
1216
- _this6.emit('onExitRoom', 0);
1593
+ _this7.reset();
1594
+ _this7.emit('onExitRoom', 0);
1217
1595
  }
1218
1596
  });
1219
1597
  }
@@ -1230,26 +1608,36 @@ var TRTCCloud = /*#__PURE__*/function () {
1230
1608
  }, {
1231
1609
  key: "switchRole",
1232
1610
  value: function switchRole(role) {
1233
- var _this7 = this;
1234
- logger.info('switchRole with options: ', role);
1235
- var tempRole = this.role;
1236
- this.role = role;
1237
- if (tempRole === role || role === exports.TRTCRoleType.TRTCRoleAnchor) {
1238
- logger.info('switchRole success');
1239
- this.emit('onSwitchRole', 0, '');
1240
- return;
1241
- }
1242
- var pusher = this.trtc.setPusherAttributes({
1243
- enableCamera: false,
1244
- enableMic: false
1245
- });
1246
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1247
- pusher: pusher,
1248
- callback: function callback() {
1249
- logger.info('switchRole success');
1250
- _this7.emit('onSwitchRole', 0, '');
1251
- }
1252
- });
1611
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1612
+ var tempRole;
1613
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1614
+ while (1) switch (_context3.prev = _context3.next) {
1615
+ case 0:
1616
+ logger.info('switchRole with options: ', role);
1617
+ tempRole = this.role;
1618
+ this.role = role;
1619
+ if (!(tempRole === role || role === exports.TRTCRoleType.TRTCRoleAnchor)) {
1620
+ _context3.next = 7;
1621
+ break;
1622
+ }
1623
+ logger.info('switchRole success');
1624
+ this.emit('onSwitchRole', 0, '');
1625
+ return _context3.abrupt("return");
1626
+ case 7:
1627
+ _context3.next = 9;
1628
+ return this.setPusherAttributes({
1629
+ enableCamera: false,
1630
+ enableMic: false
1631
+ }, 'switchRole');
1632
+ case 9:
1633
+ logger.info('switchRole success');
1634
+ this.emit('onSwitchRole', 0, '');
1635
+ case 11:
1636
+ case "end":
1637
+ return _context3.stop();
1638
+ }
1639
+ }, _callee3, this);
1640
+ }));
1253
1641
  }
1254
1642
  }, {
1255
1643
  key: "connectOtherRoom",
@@ -1267,42 +1655,42 @@ var TRTCCloud = /*#__PURE__*/function () {
1267
1655
  }, {
1268
1656
  key: "startLocalPreview",
1269
1657
  value: function startLocalPreview() {
1270
- var _this8 = this;
1271
1658
  var frontCamera = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1272
- logger.info('startLocalPreview with options: ', frontCamera);
1273
- return new Promise(function (resolve, reject) {
1274
- if (_this8.role !== exports.TRTCRoleType.TRTCRoleAnchor) {
1275
- resolve(null);
1276
- return;
1277
- }
1278
- var pusher = _this8.trtc.setPusherAttributes({
1279
- videoPreview: _this8.isEnterRoom ? _this8.isMuted : true,
1280
- enableCamera: _this8.isEnterRoom ? !_this8.isMuted : false,
1281
- frontCamera: frontCamera ? 'front' : 'back'
1282
- });
1283
- _this8.InterfaceEventEmitter.emit('pusherAttributesChange', {
1284
- pusher: pusher,
1285
- callback: function callback() {
1286
- return __awaiter(_this8, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1287
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1288
- while (1) switch (_context.prev = _context.next) {
1289
- case 0:
1290
- logger.info('startLocalPreview success');
1291
- this.emit('onFirstVideoFrame', '', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig, pusher.videoWidth, pusher.videoHeight);
1292
- if (this.isEnterRoom) {
1293
- this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1294
- }
1295
- resolve(null);
1296
- this.isOpenCamera = true;
1297
- case 5:
1298
- case "end":
1299
- return _context.stop();
1300
- }
1301
- }, _callee, this);
1302
- }));
1659
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1660
+ var _this8 = this;
1661
+ var pusher;
1662
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1663
+ while (1) switch (_context4.prev = _context4.next) {
1664
+ case 0:
1665
+ logger.info('startLocalPreview with options: ', frontCamera);
1666
+ if (!(this.role !== exports.TRTCRoleType.TRTCRoleAnchor)) {
1667
+ _context4.next = 3;
1668
+ break;
1669
+ }
1670
+ return _context4.abrupt("return");
1671
+ case 3:
1672
+ _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
+ };
1679
+ }, 'startLocalPreview');
1680
+ case 5:
1681
+ pusher = _context4.sent;
1682
+ logger.info('startLocalPreview success');
1683
+ this.emit('onFirstVideoFrame', '', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig, pusher.videoWidth, pusher.videoHeight);
1684
+ if (this.isEnterRoom) {
1685
+ this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1686
+ }
1687
+ this.isOpenCamera = true;
1688
+ case 10:
1689
+ case "end":
1690
+ return _context4.stop();
1303
1691
  }
1304
- });
1305
- });
1692
+ }, _callee4, this);
1693
+ }));
1306
1694
  }
1307
1695
  /**
1308
1696
  * 停止本地摄像头采集和预览
@@ -1311,20 +1699,26 @@ var TRTCCloud = /*#__PURE__*/function () {
1311
1699
  }, {
1312
1700
  key: "stopLocalPreview",
1313
1701
  value: function stopLocalPreview() {
1314
- var _this9 = this;
1315
- logger.info('stopLocalPreview');
1316
- var pusher = this.trtc.setPusherAttributes({
1317
- videoPreview: false,
1318
- enableCamera: false
1319
- });
1320
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1321
- pusher: pusher,
1322
- callback: function callback() {
1323
- logger.info('stopLocalPreview success');
1324
- _this9.isOpenCamera = false;
1325
- _this9.emit('onUserVideoAvailable', _this9.userId, 0);
1326
- }
1327
- });
1702
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
1703
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1704
+ while (1) switch (_context5.prev = _context5.next) {
1705
+ case 0:
1706
+ logger.info('stopLocalPreview');
1707
+ _context5.next = 3;
1708
+ return this.setPusherAttributes({
1709
+ videoPreview: false,
1710
+ enableCamera: false
1711
+ }, 'stopLocalPreview');
1712
+ case 3:
1713
+ logger.info('stopLocalPreview success');
1714
+ this.isOpenCamera = false;
1715
+ this.emit('onUserVideoAvailable', this.userId, 0);
1716
+ case 6:
1717
+ case "end":
1718
+ return _context5.stop();
1719
+ }
1720
+ }, _callee5, this);
1721
+ }));
1328
1722
  }
1329
1723
  /**
1330
1724
  * 修改本地摄像头预览的 HTML 元素,小程序不支持
@@ -1349,34 +1743,36 @@ var TRTCCloud = /*#__PURE__*/function () {
1349
1743
  }, {
1350
1744
  key: "muteLocalVideo",
1351
1745
  value: function muteLocalVideo(mute, streamType) {
1352
- var _this10 = this;
1353
- logger.info('muteLocalVideo with options: ', mute, streamType);
1354
- return new Promise(function (resolve, reject) {
1355
- if (!_this10.isOpenCamera) {
1356
- resolve(null);
1357
- return;
1358
- }
1359
- var pusher = {};
1360
- switch (streamType) {
1361
- case exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig:
1362
- case exports.TRTCVideoStreamType.TRTCVideoStreamTypeSub:
1363
- _this10.isMuted = mute;
1364
- pusher = _this10.trtc.setPusherAttributes({
1365
- videoPreview: mute,
1366
- enableCamera: !mute
1367
- });
1368
- _this10.InterfaceEventEmitter.emit('pusherAttributesChange', {
1369
- pusher: pusher,
1370
- callback: function callback() {
1371
- logger.info('muteLocalVideo success');
1372
- resolve(null);
1746
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
1747
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1748
+ while (1) switch (_context6.prev = _context6.next) {
1749
+ case 0:
1750
+ logger.info('muteLocalVideo with options: ', mute, streamType);
1751
+ if (this.isOpenCamera) {
1752
+ _context6.next = 3;
1753
+ break;
1373
1754
  }
1374
- });
1375
- break;
1376
- default:
1377
- resolve(null);
1378
- }
1379
- });
1755
+ return _context6.abrupt("return");
1756
+ case 3:
1757
+ _context6.t0 = streamType;
1758
+ _context6.next = _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig ? 6 : _context6.t0 === exports.TRTCVideoStreamType.TRTCVideoStreamTypeSub ? 6 : 11;
1759
+ break;
1760
+ case 6:
1761
+ this.isVideoMuted = mute;
1762
+ _context6.next = 9;
1763
+ return this.setPusherAttributes({
1764
+ videoPreview: mute,
1765
+ enableCamera: !mute
1766
+ }, 'muteLocalVideo');
1767
+ case 9:
1768
+ logger.info('muteLocalVideo success');
1769
+ return _context6.abrupt("break", 11);
1770
+ case 11:
1771
+ case "end":
1772
+ return _context6.stop();
1773
+ }
1774
+ }, _callee6, this);
1775
+ }));
1380
1776
  }
1381
1777
  /**
1382
1778
  * 开始显示远端视频画面
@@ -1388,7 +1784,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1388
1784
  }, {
1389
1785
  key: "startRemoteView",
1390
1786
  value: function startRemoteView(userId, view, streamType) {
1391
- var _this11 = this;
1787
+ var _this9 = this;
1392
1788
  logger.info('startRemoteView with options: ', userId, view, streamType);
1393
1789
  var streamId = translateTRTCStreamId(userId, streamType);
1394
1790
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
@@ -1402,7 +1798,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1402
1798
  playerAttributes: playerAttributes,
1403
1799
  callback: function callback() {
1404
1800
  logger.info('startRemoteView success');
1405
- _this11.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1801
+ _this9.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1406
1802
  }
1407
1803
  });
1408
1804
  }
@@ -1452,18 +1848,18 @@ var TRTCCloud = /*#__PURE__*/function () {
1452
1848
  }, {
1453
1849
  key: "stopAllRemoteView",
1454
1850
  value: function stopAllRemoteView() {
1455
- var _this12 = this;
1851
+ var _this10 = this;
1456
1852
  logger.info('stopAllRemoteView');
1457
1853
  var playerList = this.trtc.getPlayerList();
1458
1854
  playerList.forEach(function (player) {
1459
1855
  var streamId = player.streamID;
1460
- var playerAttributes = _this12.setTRTCPlayerAttributes(streamId, {
1856
+ var playerAttributes = _this10.setTRTCPlayerAttributes(streamId, {
1461
1857
  muteVideo: true,
1462
1858
  stopVideo: true
1463
1859
  });
1464
- _this12.InterfaceEventEmitter.emit('playerAttributesChange', {
1860
+ _this10.InterfaceEventEmitter.emit('playerAttributesChange', {
1465
1861
  streamId: streamId,
1466
- view: _this12.renderMap.get(streamId),
1862
+ view: _this10.renderMap.get(streamId),
1467
1863
  playerAttributes: playerAttributes,
1468
1864
  callback: function callback() {
1469
1865
  logger.info('stopAllRemoteView success');
@@ -1493,17 +1889,17 @@ var TRTCCloud = /*#__PURE__*/function () {
1493
1889
  }, {
1494
1890
  key: "muteAllRemoteVideoStreams",
1495
1891
  value: function muteAllRemoteVideoStreams(mute) {
1496
- var _this13 = this;
1892
+ var _this11 = this;
1497
1893
  logger.info('muteAllRemoteVideoStreams with options: ', mute);
1498
1894
  var playerList = this.trtc.getPlayerList();
1499
1895
  playerList.forEach(function (player) {
1500
1896
  var streamId = player.streamID;
1501
- var playerAttributes = _this13.setTRTCPlayerAttributes(streamId, {
1897
+ var playerAttributes = _this11.setTRTCPlayerAttributes(streamId, {
1502
1898
  muteVideo: mute
1503
1899
  });
1504
- _this13.InterfaceEventEmitter.emit('playerAttributesChange', {
1900
+ _this11.InterfaceEventEmitter.emit('playerAttributesChange', {
1505
1901
  streamId: streamId,
1506
- view: _this13.renderMap.get(streamId),
1902
+ view: _this11.renderMap.get(streamId),
1507
1903
  playerAttributes: playerAttributes,
1508
1904
  callback: function callback() {
1509
1905
  logger.info('muteAllRemoteVideoStreams success');
@@ -1522,49 +1918,56 @@ var TRTCCloud = /*#__PURE__*/function () {
1522
1918
  }, {
1523
1919
  key: "setVideoEncoderParam",
1524
1920
  value: function setVideoEncoderParam(params) {
1525
- logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1526
- var videoResolution = params.videoResolution;
1527
- params.resMode;
1528
- var videoFps = params.videoFps;
1529
- params.videoBitrate;
1530
- var minVideoBitrate = params.minVideoBitrate;
1531
- var _translateTRTCVideoRe = translateTRTCVideoResolution(videoResolution),
1532
- videoWidth = _translateTRTCVideoRe.videoWidth,
1533
- videoHeight = _translateTRTCVideoRe.videoHeight;
1534
- // const videoOrientation = translateTRTCVideoResolutionMode(resMode);
1535
- var pusher = this.trtc.setPusherAttributes({
1536
- videoWidth: videoWidth,
1537
- videoHeight: videoHeight,
1538
- // videoOrientation,
1539
- fps: videoFps,
1540
- minBitrate: minVideoBitrate
1541
- });
1542
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1543
- pusher: pusher,
1544
- callback: function callback() {
1545
- logger.info('setVideoEncoderParam success');
1546
- }
1547
- });
1921
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1922
+ var videoResolution, videoFps, minVideoBitrate, _translateTRTCVideoRe, videoWidth, videoHeight;
1923
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1924
+ while (1) switch (_context7.prev = _context7.next) {
1925
+ case 0:
1926
+ logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1927
+ 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
1936
+ }, 'setVideoEncoderParam');
1937
+ case 5:
1938
+ logger.info('setVideoEncoderParam success');
1939
+ case 6:
1940
+ case "end":
1941
+ return _context7.stop();
1942
+ }
1943
+ }, _callee7, this);
1944
+ }));
1548
1945
  }
1549
1946
  }, {
1550
1947
  key: "setLocalRenderParams",
1551
1948
  value: function setLocalRenderParams(params) {
1552
- logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1553
- var rotation = params.rotation;
1554
- params.fillMode;
1555
- var mirrorType = params.mirrorType;
1556
- var videoOrientation = translateTRTCVideoRotation(rotation);
1557
- var localMirror = translateTRTCVideoMirrorType(mirrorType);
1558
- var pusher = this.trtc.setPusherAttributes({
1559
- videoOrientation: videoOrientation,
1560
- localMirror: localMirror
1561
- });
1562
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1563
- pusher: pusher,
1564
- callback: function callback() {
1565
- logger.info('setLocalRenderParams success');
1566
- }
1567
- });
1949
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee8() {
1950
+ var rotation, mirrorType, videoOrientation, localMirror;
1951
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
1952
+ while (1) switch (_context8.prev = _context8.next) {
1953
+ case 0:
1954
+ logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1955
+ rotation = params.rotation, params.fillMode, mirrorType = params.mirrorType;
1956
+ videoOrientation = translateTRTCVideoRotation(rotation);
1957
+ localMirror = translateTRTCVideoMirrorType(mirrorType);
1958
+ _context8.next = 6;
1959
+ return this.setPusherAttributes({
1960
+ videoOrientation: videoOrientation,
1961
+ localMirror: localMirror
1962
+ }, 'setLocalRenderParams');
1963
+ case 6:
1964
+ logger.info('setLocalRenderParams success');
1965
+ case 7:
1966
+ case "end":
1967
+ return _context8.stop();
1968
+ }
1969
+ }, _callee8, this);
1970
+ }));
1568
1971
  }
1569
1972
  /**
1570
1973
  * 设置远端图像的渲染模式
@@ -1596,54 +1999,88 @@ var TRTCCloud = /*#__PURE__*/function () {
1596
1999
  }, {
1597
2000
  key: "startLocalAudio",
1598
2001
  value: function startLocalAudio(quality) {
1599
- var _this14 = this;
1600
- logger.info('startLocalAudio with options: ', quality);
1601
- var pusher = this.trtc.setPusherAttributes({
1602
- enableMic: true
1603
- });
1604
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1605
- pusher: pusher,
1606
- callback: function callback() {
1607
- logger.info('startLocalAudio success');
1608
- _this14.emit('onMicDidReady');
1609
- _this14.emit('onUserAudioAvailable', _this14.userId, 1);
1610
- if (_this14.enterRoom) {
1611
- _this14.emit('onSendFirstLocalAudioFrame');
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) {
2006
+ case 0:
2007
+ logger.info('startLocalAudio with options: ', quality);
2008
+ if (!(this.role !== exports.TRTCRoleType.TRTCRoleAnchor)) {
2009
+ _context9.next = 3;
2010
+ break;
2011
+ }
2012
+ throw new Error('Current role is audience, unable to access mic. Call switchRole to become a host.');
2013
+ 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
+ };
2025
+ }, 'startLocalAudio');
2026
+ case 7:
2027
+ logger.info('startLocalAudio success');
2028
+ this.emit('onMicDidReady');
2029
+ this.emit('onUserAudioAvailable', this.userId, 1);
2030
+ if (this.enterRoom) {
2031
+ this.emit('onSendFirstLocalAudioFrame');
2032
+ }
2033
+ case 11:
2034
+ case "end":
2035
+ return _context9.stop();
1612
2036
  }
1613
- }
1614
- });
2037
+ }, _callee9, this);
2038
+ }));
1615
2039
  }
1616
2040
  }, {
1617
2041
  key: "stopLocalAudio",
1618
2042
  value: function stopLocalAudio() {
1619
- var _this15 = this;
1620
- logger.info('stopLocalAudio');
1621
- var pusher = this.trtc.setPusherAttributes({
1622
- enableMic: false
1623
- });
1624
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1625
- pusher: pusher,
1626
- callback: function callback() {
1627
- logger.info('stopLocalAudio success');
1628
- _this15.emit('onUserAudioAvailable', _this15.userId, 0);
1629
- }
1630
- });
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) {
2046
+ case 0:
2047
+ logger.info('stopLocalAudio');
2048
+ _context10.next = 3;
2049
+ return this.setPusherAttributes({
2050
+ enableMic: false
2051
+ }, 'stopLocalAudio');
2052
+ case 3:
2053
+ logger.info('stopLocalAudio success');
2054
+ this.emit('onUserAudioAvailable', this.userId, 0);
2055
+ case 5:
2056
+ case "end":
2057
+ return _context10.stop();
2058
+ }
2059
+ }, _callee10, this);
2060
+ }));
1631
2061
  }
1632
2062
  }, {
1633
2063
  key: "muteLocalAudio",
1634
2064
  value: function muteLocalAudio(mute) {
1635
- var _this16 = this;
1636
- logger.info('muteLocalAudio with options: ', mute);
1637
- var pusher = this.trtc.setPusherAttributes({
1638
- enableMic: !mute
1639
- });
1640
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1641
- pusher: pusher,
1642
- callback: function callback() {
1643
- logger.info('muteLocalAudio success');
1644
- _this16.emit('onUserAudioAvailable', _this16.userId, mute === true ? 0 : 1);
1645
- }
1646
- });
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) {
2068
+ case 0:
2069
+ logger.info('muteLocalAudio with options: ', mute);
2070
+ _context11.next = 3;
2071
+ return this.setPusherAttributes({
2072
+ enableMic: !mute
2073
+ }, 'muteLocalAudio');
2074
+ case 3:
2075
+ this.isMicMuted = mute;
2076
+ logger.info('muteLocalAudio success');
2077
+ this.emit('onUserAudioAvailable', this.userId, mute === true ? 0 : 1);
2078
+ case 6:
2079
+ case "end":
2080
+ return _context11.stop();
2081
+ }
2082
+ }, _callee11, this);
2083
+ }));
1647
2084
  }
1648
2085
  }, {
1649
2086
  key: "muteRemoteAudio",
@@ -1665,17 +2102,17 @@ var TRTCCloud = /*#__PURE__*/function () {
1665
2102
  }, {
1666
2103
  key: "muteAllRemoteAudio",
1667
2104
  value: function muteAllRemoteAudio(mute) {
1668
- var _this17 = this;
2105
+ var _this13 = this;
1669
2106
  logger.info('muteAllRemoteAudio with options: ', mute);
1670
2107
  var playerList = this.trtc.getPlayerList();
1671
2108
  playerList.forEach(function (player) {
1672
2109
  var streamId = player.streamID;
1673
- var playerAttributes = _this17.setTRTCPlayerAttributes(streamId, {
2110
+ var playerAttributes = _this13.setTRTCPlayerAttributes(streamId, {
1674
2111
  muteAudio: mute
1675
2112
  });
1676
- _this17.InterfaceEventEmitter.emit('playerAttributesChange', {
2113
+ _this13.InterfaceEventEmitter.emit('playerAttributesChange', {
1677
2114
  streamId: streamId,
1678
- view: _this17.renderMap.get(streamId),
2115
+ view: _this13.renderMap.get(streamId),
1679
2116
  playerAttributes: playerAttributes,
1680
2117
  callback: function callback() {
1681
2118
  logger.info('muteAllRemoteAudio success');
@@ -1695,23 +2132,30 @@ var TRTCCloud = /*#__PURE__*/function () {
1695
2132
  }, {
1696
2133
  key: "switchCamera",
1697
2134
  value: function switchCamera(frontCamera) {
1698
- var _this18 = this;
2135
+ var _this14 = this;
1699
2136
  logger.info('switchCamera with options: ', frontCamera);
1700
2137
  var pusher = this.trtc.getPusherInstance();
1701
2138
  if (frontCamera === (pusher.pusherAttributes.frontCamera === 'front')) return Promise.resolve();
1702
2139
  return new Promise(function (resolve, reject) {
1703
2140
  wx.createLivePusherContext().switchCamera({
1704
2141
  success: function success(event) {
1705
- var pusher = _this18.trtc.setPusherAttributes({
1706
- frontCamera: true
1707
- });
1708
- _this18.InterfaceEventEmitter.emit('pusherAttributesChange', {
1709
- pusher: pusher,
1710
- callback: function callback() {
1711
- logger.info('switchCamera success');
1712
- }
1713
- });
1714
- resolve(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) {
2145
+ case 0:
2146
+ _context12.next = 2;
2147
+ return this.setPusherAttributes({
2148
+ frontCamera: frontCamera
2149
+ }, 'switchCamera');
2150
+ case 2:
2151
+ logger.info('switchCamera success');
2152
+ resolve(event);
2153
+ case 4:
2154
+ case "end":
2155
+ return _context12.stop();
2156
+ }
2157
+ }, _callee12, this);
2158
+ }));
1715
2159
  },
1716
2160
  fail: function fail(error) {
1717
2161
  logger.info('switchCamera fail');
@@ -1723,18 +2167,25 @@ var TRTCCloud = /*#__PURE__*/function () {
1723
2167
  }, {
1724
2168
  key: "setBeautyStyle",
1725
2169
  value: function setBeautyStyle(style, beauty, white, ruddiness) {
1726
- logger.info('setBeautyStyle with options: ', style, beauty, white, ruddiness);
1727
- var pusher = this.trtc.setPusherAttributes({
1728
- beautyStyle: style,
1729
- beautyLevel: beauty,
1730
- whitenessLevel: white
1731
- });
1732
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1733
- pusher: pusher,
1734
- callback: function callback() {
1735
- logger.info('setBeautyStyle success');
1736
- }
1737
- });
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) {
2173
+ case 0:
2174
+ 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
2180
+ }, 'setBeautyStyle');
2181
+ case 3:
2182
+ logger.info('setBeautyStyle success');
2183
+ case 4:
2184
+ case "end":
2185
+ return _context13.stop();
2186
+ }
2187
+ }, _callee13, this);
2188
+ }));
1738
2189
  }
1739
2190
  }, {
1740
2191
  key: "sendSEIMsg",
@@ -1898,6 +2349,40 @@ var TRTCCloud = /*#__PURE__*/function () {
1898
2349
  }
1899
2350
  }
1900
2351
  }
2352
+ }, {
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);
2362
+ });
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;
2373
+ }
2374
+ _this15.InterfaceEventEmitter.emit('pusherAttributesChange', {
2375
+ pusher: pusher,
2376
+ callback: function callback() {
2377
+ resolve(pusher);
2378
+ }
2379
+ });
2380
+ } catch (err) {
2381
+ reject(err);
2382
+ }
2383
+ });
2384
+ return Promise.race([originalPromise, timeoutPromise]);
2385
+ }
1901
2386
  }], [{
1902
2387
  key: "getTRTCShareInstance",
1903
2388
  value: function getTRTCShareInstance() {
@@ -1920,6 +2405,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1920
2405
  }]);
1921
2406
  return TRTCCloud;
1922
2407
  }();
2408
+ __decorate([setHandle], TRTCCloud.prototype, "setPusherAttributes", null);
1923
2409
 
1924
2410
  exports.TRTCCloud = TRTCCloud;
1925
2411
  exports.default = TRTCCloud;