@tencentcloud/trtc-cloud-wx 0.0.16 → 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 +790 -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.15";
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";
@@ -826,7 +1162,8 @@ var scripts = {
826
1162
  copy: "node ./build/copy.js",
827
1163
  doc: "npx typedoc --tsconfig typedoc.json",
828
1164
  "doc:watch": "typedoc --watch",
829
- "doc:build": "jsdoc -c jsdoc.json"
1165
+ "doc:build": "jsdoc -c jsdoc.json",
1166
+ publish: "bash ./sdk_publish.bash"
830
1167
  };
831
1168
  var keywords = [
832
1169
  ];
@@ -898,7 +1235,8 @@ var TRTCCloud = /*#__PURE__*/function () {
898
1235
  this.role = exports.TRTCRoleType.TRTCRoleAnchor;
899
1236
  this.userId = '';
900
1237
  this.isEnterRoom = false;
901
- this.isMuted = false;
1238
+ this.isVideoMuted = false;
1239
+ this.isMicMuted = false;
902
1240
  this.isOpenCamera = false;
903
1241
  this.audioVolumeEvaluation = 0;
904
1242
  this.allTimer = {};
@@ -918,6 +1256,7 @@ var TRTCCloud = /*#__PURE__*/function () {
918
1256
  }, {
919
1257
  key: "destroy",
920
1258
  value: function destroy() {
1259
+ this.offTRTCEvent();
921
1260
  this.EventEmitter.removeAllListeners();
922
1261
  this.InterfaceEventEmitter.removeAllListeners();
923
1262
  this.trtc.exitRoom();
@@ -928,8 +1267,8 @@ var TRTCCloud = /*#__PURE__*/function () {
928
1267
  this.trtc = new TRTC(this);
929
1268
  this.trtc.setLogLevel(3);
930
1269
  this.TRTC_EVENT = this.trtc.EVENT;
931
- this.trtc.createPusher({});
932
1270
  this.bindTRTCEvent();
1271
+ this.bindComponentEvent();
933
1272
  this.handleNetworkQuality = this.getHandleNetworkQuality(2000);
934
1273
  }
935
1274
  }, {
@@ -939,17 +1278,32 @@ var TRTCCloud = /*#__PURE__*/function () {
939
1278
  this.role = exports.TRTCRoleType.TRTCRoleAnchor;
940
1279
  this.userId = '';
941
1280
  this.isEnterRoom = false;
942
- this.isMuted = false;
1281
+ this.isVideoMuted = false;
1282
+ this.isMicMuted = false;
943
1283
  this.isOpenCamera = false;
944
1284
  Object.keys(this.allTimer).forEach(function (key) {
945
1285
  clearInterval(_this.allTimer[key]);
946
1286
  _this.allTimer[key] = null;
947
1287
  });
948
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
+ }
949
1303
  }, {
950
1304
  key: "bindTRTCEvent",
951
1305
  value: function bindTRTCEvent() {
952
- var _this2 = this;
1306
+ var _this3 = this;
953
1307
  this.trtc.on(this.TRTC_EVENT.LOCAL_LEAVE, function (event) {
954
1308
  // todo 第二个参数为进房耗时 此处调用start的时候处理
955
1309
  // this.emit('onEnterRoom', 0)
@@ -958,42 +1312,42 @@ var TRTCCloud = /*#__PURE__*/function () {
958
1312
  var _event$data = event.data,
959
1313
  code = _event$data.code,
960
1314
  message = _event$data.message;
961
- _this2.emit('onError', code, message);
1315
+ _this3.emit('onError', code, message);
962
1316
  });
963
1317
  this.trtc.on(this.TRTC_EVENT.REMOTE_USER_JOIN, function (event) {
964
1318
  var userID = event.data.userID;
965
- _this2.emit('onRemoteUserEnterRoom', userID);
1319
+ _this3.emit('onRemoteUserEnterRoom', userID);
966
1320
  });
967
1321
  // 远端用户退出
968
1322
  this.trtc.on(this.TRTC_EVENT.REMOTE_USER_LEAVE, function (event) {
969
1323
  var _event$data2 = event.data,
970
1324
  userID = _event$data2.userID;
971
1325
  _event$data2.playerList;
972
- _this2.InterfaceEventEmitter.emit('onRemoteUserLeaveRoom', userID, 0);
973
- _this2.emit('onUserVideoAvailable', userID, 0);
974
- _this2.emit('onUserSubStreamAvailable', userID, 0);
975
- _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);
976
1330
  });
977
1331
  // 远端用户推送视频
978
1332
  this.trtc.on(this.TRTC_EVENT.REMOTE_VIDEO_ADD, function (event) {
979
1333
  var player = event.data.player;
980
- _this2.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 1);
1334
+ _this3.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 1);
981
1335
  });
982
1336
  // 远端用户取消推送视频
983
1337
  this.trtc.on(this.TRTC_EVENT.REMOTE_VIDEO_REMOVE, function (event) {
984
1338
  var player = event.data.player;
985
- _this2.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 0);
1339
+ _this3.emit(player.streamType === 'aux' ? 'onUserSubStreamAvailable' : 'onUserVideoAvailable', player.userID, 0);
986
1340
  });
987
1341
  // 远端用户推送音频
988
1342
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_ADD, function (event) {
989
1343
  var player = event.data.player;
990
- _this2.emit('onUserAudioAvailable', player.userID, 1);
991
- _this2.muteRemoteAudio(player.userID, false);
1344
+ _this3.emit('onUserAudioAvailable', player.userID, 1);
1345
+ _this3.muteRemoteAudio(player.userID, false);
992
1346
  });
993
1347
  // 远端用户取消推送音频
994
1348
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_REMOVE, function (event) {
995
1349
  var player = event.data.player;
996
- _this2.emit('onUserAudioAvailable', player.userID, 0);
1350
+ _this3.emit('onUserAudioAvailable', player.userID, 0);
997
1351
  });
998
1352
  this.trtc.on(this.TRTC_EVENT.REMOTE_AUDIO_VOLUME_UPDATE, function (event) {
999
1353
  var playerList = event.data.playerList;
@@ -1003,7 +1357,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1003
1357
  volume: player.volume
1004
1358
  };
1005
1359
  });
1006
- _this2.handleAudioVolumeUpdate(userVolumes);
1360
+ _this3.handleAudioVolumeUpdate(userVolumes);
1007
1361
  });
1008
1362
  this.trtc.on(this.TRTC_EVENT.LOCAL_AUDIO_VOLUME_UPDATE, function (event) {
1009
1363
  var pusher = event.data.pusher;
@@ -1011,25 +1365,39 @@ var TRTCCloud = /*#__PURE__*/function () {
1011
1365
  userId: pusher.userID,
1012
1366
  volume: pusher.volume
1013
1367
  }];
1014
- _this2.handleAudioVolumeUpdate(userVolumes);
1368
+ _this3.handleAudioVolumeUpdate(userVolumes);
1015
1369
  });
1016
1370
  this.trtc.on(this.TRTC_EVENT.LOCAL_NET_STATE_UPDATE, function (event) {
1017
1371
  var pusher = event.data.pusher;
1018
- _this2.handleNetworkQuality({
1372
+ _this3.handleNetworkQuality({
1019
1373
  pusher: pusher
1020
1374
  });
1021
1375
  });
1022
1376
  this.trtc.on(this.TRTC_EVENT.REMOTE_NET_STATE_UPDATE, function (event) {
1023
1377
  var playerList = event.data.playerList;
1024
- _this2.handleNetworkQuality({
1378
+ _this3.handleNetworkQuality({
1025
1379
  playerList: playerList
1026
1380
  });
1027
1381
  });
1028
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
+ }
1029
1397
  }, {
1030
1398
  key: "getHandleAudioVolumeUpdate",
1031
1399
  value: function getHandleAudioVolumeUpdate(interval) {
1032
- var _this3 = this;
1400
+ var _this4 = this;
1033
1401
  var _a;
1034
1402
  if ((_a = this.allTimer) === null || _a === void 0 ? void 0 : _a.AudioVolume) {
1035
1403
  clearInterval(this.allTimer.AudioVolume);
@@ -1046,12 +1414,12 @@ var TRTCCloud = /*#__PURE__*/function () {
1046
1414
  this.InterfaceEventEmitter.on('onRemoteUserLeaveRoom', filterUselessItem, this.getHandleAudioVolumeUpdate);
1047
1415
  return function (userVolumes) {
1048
1416
  tempUserVolumes = uniqueFunc([].concat(_toConsumableArray(userVolumes), _toConsumableArray(tempUserVolumes)), 'userId');
1049
- if (_this3.allTimer.AudioVolume) return;
1417
+ if (_this4.allTimer.AudioVolume) return;
1050
1418
  var timer = setInterval(function () {
1051
- _this3.emit('onUserVoiceVolume', tempUserVolumes, tempUserVolumes.length, 0 // todo 此参数无用,暂时废弃
1419
+ _this4.emit('onUserVoiceVolume', tempUserVolumes, tempUserVolumes.length, 0 // todo 此参数无用,暂时废弃
1052
1420
  );
1053
1421
  }, interval);
1054
- _this3.allTimer.AudioVolume = timer;
1422
+ _this4.allTimer.AudioVolume = timer;
1055
1423
  };
1056
1424
  }
1057
1425
  }, {
@@ -1060,7 +1428,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1060
1428
  }, {
1061
1429
  key: "getHandleNetworkQuality",
1062
1430
  value: function getHandleNetworkQuality(interval) {
1063
- var _this4 = this;
1431
+ var _this5 = this;
1064
1432
  var _a;
1065
1433
  if ((_a = this.allTimer) === null || _a === void 0 ? void 0 : _a.networkQuality) {
1066
1434
  clearInterval(this.allTimer.networkQuality);
@@ -1091,11 +1459,11 @@ var TRTCCloud = /*#__PURE__*/function () {
1091
1459
  };
1092
1460
  });
1093
1461
  }
1094
- if (_this4.allTimer.networkQuality) return;
1462
+ if (_this5.allTimer.networkQuality) return;
1095
1463
  var timer = setInterval(function () {
1096
- _this4.emit('onNetworkQuality', resultQuality.localQuality, resultQuality.remoteQuality);
1464
+ _this5.emit('onNetworkQuality', resultQuality.localQuality, resultQuality.remoteQuality);
1097
1465
  }, interval);
1098
- _this4.allTimer.networkQuality = timer;
1466
+ _this5.allTimer.networkQuality = timer;
1099
1467
  };
1100
1468
  }
1101
1469
  }, {
@@ -1135,67 +1503,78 @@ var TRTCCloud = /*#__PURE__*/function () {
1135
1503
  }, {
1136
1504
  key: "enterRoom",
1137
1505
  value: function enterRoom(params, scene) {
1138
- var _this5 = this;
1139
- var startTime = new Date().getTime();
1140
- var sdkAppId = params.sdkAppId,
1141
- userId = params.userId,
1142
- userSig = params.userSig,
1143
- roomId = params.roomId,
1144
- strRoomId = params.strRoomId,
1145
- role = params.role,
1146
- privateMapKey = params.privateMapKey;
1147
- logger.setInfo({
1148
- sdkAppId: sdkAppId,
1149
- userId: userId,
1150
- roomId: strRoomId
1151
- });
1152
- logger.info('enterRoom with options: ', JSON.stringify(params), scene);
1153
- this.userId = userId;
1154
- this.trtc.createPusher({});
1155
- var pusher = this.trtc.enterRoom({
1156
- sdkAppID: sdkAppId,
1157
- userID: userId,
1158
- userSig: userSig,
1159
- roomID: roomId,
1160
- strRoomID: strRoomId,
1161
- role: role,
1162
- privateMapKey: privateMapKey,
1163
- scene: translateTRTCAppScene(scene),
1164
- enableMic: false,
1165
- enableCamera: false,
1166
- videoPreview: false
1167
- });
1168
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1169
- pusher: pusher,
1170
- callback: function callback() {
1171
- _this5.trtc.getPusherInstance().start({
1172
- success: function success() {
1173
- logger.info('enterRoom success');
1174
- _this5.scene = scene;
1175
- _this5.isEnterRoom = true;
1176
- var endTime = new Date().getTime();
1177
- _this5.emit('onEnterRoom', endTime - startTime);
1178
- if (_this5.trtc.getPusherAttributes().videoPreview === true) {
1179
- // 如果进房前有打开摄像头,需要开启视频上行,并抛出 onSendFirstLocalVideoFrame 事件
1180
- var _pusher = _this5.trtc.setPusherAttributes({
1181
- videoPreview: false,
1182
- enableCamera: true
1183
- });
1184
- _this5.InterfaceEventEmitter.emit('pusherAttributesChange', {
1185
- pusher: _pusher,
1186
- callback: function callback() {
1187
- _this5.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1188
- }
1189
- });
1190
- }
1191
- },
1192
- fail: function fail() {
1193
- logger.info('enterRoom fail');
1194
- _this5.emit('onEnterRoom', -1);
1195
- }
1196
- });
1197
- }
1198
- });
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
+ }));
1199
1578
  }
1200
1579
  /**
1201
1580
  * @category 房间
@@ -1203,7 +1582,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1203
1582
  }, {
1204
1583
  key: "exitRoom",
1205
1584
  value: function exitRoom() {
1206
- var _this6 = this;
1585
+ var _this7 = this;
1207
1586
  logger.info('exitRoom');
1208
1587
  var _this$trtc$exitRoom = this.trtc.exitRoom(),
1209
1588
  pusher = _this$trtc$exitRoom.pusher;
@@ -1211,8 +1590,8 @@ var TRTCCloud = /*#__PURE__*/function () {
1211
1590
  pusher: pusher,
1212
1591
  callback: function callback() {
1213
1592
  logger.info('exitRoom success');
1214
- _this6.reset();
1215
- _this6.emit('onExitRoom', 0);
1593
+ _this7.reset();
1594
+ _this7.emit('onExitRoom', 0);
1216
1595
  }
1217
1596
  });
1218
1597
  }
@@ -1229,26 +1608,36 @@ var TRTCCloud = /*#__PURE__*/function () {
1229
1608
  }, {
1230
1609
  key: "switchRole",
1231
1610
  value: function switchRole(role) {
1232
- var _this7 = this;
1233
- logger.info('switchRole with options: ', role);
1234
- var tempRole = this.role;
1235
- this.role = role;
1236
- if (tempRole === role || role === exports.TRTCRoleType.TRTCRoleAnchor) {
1237
- logger.info('switchRole success');
1238
- this.emit('onSwitchRole', 0, '');
1239
- return;
1240
- }
1241
- var pusher = this.trtc.setPusherAttributes({
1242
- enableCamera: false,
1243
- enableMic: false
1244
- });
1245
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1246
- pusher: pusher,
1247
- callback: function callback() {
1248
- logger.info('switchRole success');
1249
- _this7.emit('onSwitchRole', 0, '');
1250
- }
1251
- });
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
+ }));
1252
1641
  }
1253
1642
  }, {
1254
1643
  key: "connectOtherRoom",
@@ -1266,42 +1655,42 @@ var TRTCCloud = /*#__PURE__*/function () {
1266
1655
  }, {
1267
1656
  key: "startLocalPreview",
1268
1657
  value: function startLocalPreview() {
1269
- var _this8 = this;
1270
1658
  var frontCamera = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1271
- logger.info('startLocalPreview with options: ', frontCamera);
1272
- return new Promise(function (resolve, reject) {
1273
- if (_this8.role !== exports.TRTCRoleType.TRTCRoleAnchor) {
1274
- resolve(null);
1275
- return;
1276
- }
1277
- var pusher = _this8.trtc.setPusherAttributes({
1278
- videoPreview: _this8.isEnterRoom ? _this8.isMuted : true,
1279
- enableCamera: _this8.isEnterRoom ? !_this8.isMuted : false,
1280
- frontCamera: frontCamera ? 'front' : 'back'
1281
- });
1282
- _this8.InterfaceEventEmitter.emit('pusherAttributesChange', {
1283
- pusher: pusher,
1284
- callback: function callback() {
1285
- return __awaiter(_this8, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1286
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1287
- while (1) switch (_context.prev = _context.next) {
1288
- case 0:
1289
- logger.info('startLocalPreview success');
1290
- this.emit('onFirstVideoFrame', '', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig, pusher.videoWidth, pusher.videoHeight);
1291
- if (this.isEnterRoom) {
1292
- this.emit('onSendFirstLocalVideoFrame', exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig);
1293
- }
1294
- resolve(null);
1295
- this.isOpenCamera = true;
1296
- case 5:
1297
- case "end":
1298
- return _context.stop();
1299
- }
1300
- }, _callee, this);
1301
- }));
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();
1302
1691
  }
1303
- });
1304
- });
1692
+ }, _callee4, this);
1693
+ }));
1305
1694
  }
1306
1695
  /**
1307
1696
  * 停止本地摄像头采集和预览
@@ -1310,20 +1699,26 @@ var TRTCCloud = /*#__PURE__*/function () {
1310
1699
  }, {
1311
1700
  key: "stopLocalPreview",
1312
1701
  value: function stopLocalPreview() {
1313
- var _this9 = this;
1314
- logger.info('stopLocalPreview');
1315
- var pusher = this.trtc.setPusherAttributes({
1316
- videoPreview: false,
1317
- enableCamera: false
1318
- });
1319
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1320
- pusher: pusher,
1321
- callback: function callback() {
1322
- logger.info('stopLocalPreview success');
1323
- _this9.isOpenCamera = false;
1324
- _this9.emit('onUserVideoAvailable', _this9.userId, 0);
1325
- }
1326
- });
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
+ }));
1327
1722
  }
1328
1723
  /**
1329
1724
  * 修改本地摄像头预览的 HTML 元素,小程序不支持
@@ -1348,34 +1743,36 @@ var TRTCCloud = /*#__PURE__*/function () {
1348
1743
  }, {
1349
1744
  key: "muteLocalVideo",
1350
1745
  value: function muteLocalVideo(mute, streamType) {
1351
- var _this10 = this;
1352
- logger.info('muteLocalVideo with options: ', mute, streamType);
1353
- return new Promise(function (resolve, reject) {
1354
- if (!_this10.isOpenCamera) {
1355
- resolve(null);
1356
- return;
1357
- }
1358
- var pusher = {};
1359
- switch (streamType) {
1360
- case exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig:
1361
- case exports.TRTCVideoStreamType.TRTCVideoStreamTypeSub:
1362
- _this10.isMuted = mute;
1363
- pusher = _this10.trtc.setPusherAttributes({
1364
- videoPreview: mute,
1365
- enableCamera: !mute
1366
- });
1367
- _this10.InterfaceEventEmitter.emit('pusherAttributesChange', {
1368
- pusher: pusher,
1369
- callback: function callback() {
1370
- logger.info('muteLocalVideo success');
1371
- 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;
1372
1754
  }
1373
- });
1374
- break;
1375
- default:
1376
- resolve(null);
1377
- }
1378
- });
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
+ }));
1379
1776
  }
1380
1777
  /**
1381
1778
  * 开始显示远端视频画面
@@ -1387,7 +1784,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1387
1784
  }, {
1388
1785
  key: "startRemoteView",
1389
1786
  value: function startRemoteView(userId, view, streamType) {
1390
- var _this11 = this;
1787
+ var _this9 = this;
1391
1788
  logger.info('startRemoteView with options: ', userId, view, streamType);
1392
1789
  var streamId = translateTRTCStreamId(userId, streamType);
1393
1790
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
@@ -1401,7 +1798,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1401
1798
  playerAttributes: playerAttributes,
1402
1799
  callback: function callback() {
1403
1800
  logger.info('startRemoteView success');
1404
- _this11.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1801
+ _this9.emit('onFirstVideoFrame', userId, streamType, 0, 0);
1405
1802
  }
1406
1803
  });
1407
1804
  }
@@ -1451,18 +1848,18 @@ var TRTCCloud = /*#__PURE__*/function () {
1451
1848
  }, {
1452
1849
  key: "stopAllRemoteView",
1453
1850
  value: function stopAllRemoteView() {
1454
- var _this12 = this;
1851
+ var _this10 = this;
1455
1852
  logger.info('stopAllRemoteView');
1456
1853
  var playerList = this.trtc.getPlayerList();
1457
1854
  playerList.forEach(function (player) {
1458
1855
  var streamId = player.streamID;
1459
- var playerAttributes = _this12.setTRTCPlayerAttributes(streamId, {
1856
+ var playerAttributes = _this10.setTRTCPlayerAttributes(streamId, {
1460
1857
  muteVideo: true,
1461
1858
  stopVideo: true
1462
1859
  });
1463
- _this12.InterfaceEventEmitter.emit('playerAttributesChange', {
1860
+ _this10.InterfaceEventEmitter.emit('playerAttributesChange', {
1464
1861
  streamId: streamId,
1465
- view: _this12.renderMap.get(streamId),
1862
+ view: _this10.renderMap.get(streamId),
1466
1863
  playerAttributes: playerAttributes,
1467
1864
  callback: function callback() {
1468
1865
  logger.info('stopAllRemoteView success');
@@ -1492,17 +1889,17 @@ var TRTCCloud = /*#__PURE__*/function () {
1492
1889
  }, {
1493
1890
  key: "muteAllRemoteVideoStreams",
1494
1891
  value: function muteAllRemoteVideoStreams(mute) {
1495
- var _this13 = this;
1892
+ var _this11 = this;
1496
1893
  logger.info('muteAllRemoteVideoStreams with options: ', mute);
1497
1894
  var playerList = this.trtc.getPlayerList();
1498
1895
  playerList.forEach(function (player) {
1499
1896
  var streamId = player.streamID;
1500
- var playerAttributes = _this13.setTRTCPlayerAttributes(streamId, {
1897
+ var playerAttributes = _this11.setTRTCPlayerAttributes(streamId, {
1501
1898
  muteVideo: mute
1502
1899
  });
1503
- _this13.InterfaceEventEmitter.emit('playerAttributesChange', {
1900
+ _this11.InterfaceEventEmitter.emit('playerAttributesChange', {
1504
1901
  streamId: streamId,
1505
- view: _this13.renderMap.get(streamId),
1902
+ view: _this11.renderMap.get(streamId),
1506
1903
  playerAttributes: playerAttributes,
1507
1904
  callback: function callback() {
1508
1905
  logger.info('muteAllRemoteVideoStreams success');
@@ -1521,49 +1918,56 @@ var TRTCCloud = /*#__PURE__*/function () {
1521
1918
  }, {
1522
1919
  key: "setVideoEncoderParam",
1523
1920
  value: function setVideoEncoderParam(params) {
1524
- logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1525
- var videoResolution = params.videoResolution;
1526
- params.resMode;
1527
- var videoFps = params.videoFps;
1528
- params.videoBitrate;
1529
- var minVideoBitrate = params.minVideoBitrate;
1530
- var _translateTRTCVideoRe = translateTRTCVideoResolution(videoResolution),
1531
- videoWidth = _translateTRTCVideoRe.videoWidth,
1532
- videoHeight = _translateTRTCVideoRe.videoHeight;
1533
- // const videoOrientation = translateTRTCVideoResolutionMode(resMode);
1534
- var pusher = this.trtc.setPusherAttributes({
1535
- videoWidth: videoWidth,
1536
- videoHeight: videoHeight,
1537
- // videoOrientation,
1538
- fps: videoFps,
1539
- minBitrate: minVideoBitrate
1540
- });
1541
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1542
- pusher: pusher,
1543
- callback: function callback() {
1544
- logger.info('setVideoEncoderParam success');
1545
- }
1546
- });
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
+ }));
1547
1945
  }
1548
1946
  }, {
1549
1947
  key: "setLocalRenderParams",
1550
1948
  value: function setLocalRenderParams(params) {
1551
- logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1552
- var rotation = params.rotation;
1553
- params.fillMode;
1554
- var mirrorType = params.mirrorType;
1555
- var videoOrientation = translateTRTCVideoRotation(rotation);
1556
- var localMirror = translateTRTCVideoMirrorType(mirrorType);
1557
- var pusher = this.trtc.setPusherAttributes({
1558
- videoOrientation: videoOrientation,
1559
- localMirror: localMirror
1560
- });
1561
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1562
- pusher: pusher,
1563
- callback: function callback() {
1564
- logger.info('setLocalRenderParams success');
1565
- }
1566
- });
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
+ }));
1567
1971
  }
1568
1972
  /**
1569
1973
  * 设置远端图像的渲染模式
@@ -1595,54 +1999,88 @@ var TRTCCloud = /*#__PURE__*/function () {
1595
1999
  }, {
1596
2000
  key: "startLocalAudio",
1597
2001
  value: function startLocalAudio(quality) {
1598
- var _this14 = this;
1599
- logger.info('startLocalAudio with options: ', quality);
1600
- var pusher = this.trtc.setPusherAttributes({
1601
- enableMic: true
1602
- });
1603
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1604
- pusher: pusher,
1605
- callback: function callback() {
1606
- logger.info('startLocalAudio success');
1607
- _this14.emit('onMicDidReady');
1608
- _this14.emit('onUserAudioAvailable', _this14.userId, 1);
1609
- if (_this14.enterRoom) {
1610
- _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();
1611
2036
  }
1612
- }
1613
- });
2037
+ }, _callee9, this);
2038
+ }));
1614
2039
  }
1615
2040
  }, {
1616
2041
  key: "stopLocalAudio",
1617
2042
  value: function stopLocalAudio() {
1618
- var _this15 = this;
1619
- logger.info('stopLocalAudio');
1620
- var pusher = this.trtc.setPusherAttributes({
1621
- enableMic: false
1622
- });
1623
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1624
- pusher: pusher,
1625
- callback: function callback() {
1626
- logger.info('stopLocalAudio success');
1627
- _this15.emit('onUserAudioAvailable', _this15.userId, 0);
1628
- }
1629
- });
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
+ }));
1630
2061
  }
1631
2062
  }, {
1632
2063
  key: "muteLocalAudio",
1633
2064
  value: function muteLocalAudio(mute) {
1634
- var _this16 = this;
1635
- logger.info('muteLocalAudio with options: ', mute);
1636
- var pusher = this.trtc.setPusherAttributes({
1637
- enableMic: !mute
1638
- });
1639
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1640
- pusher: pusher,
1641
- callback: function callback() {
1642
- logger.info('muteLocalAudio success');
1643
- _this16.emit('onUserAudioAvailable', _this16.userId, mute === true ? 0 : 1);
1644
- }
1645
- });
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
+ }));
1646
2084
  }
1647
2085
  }, {
1648
2086
  key: "muteRemoteAudio",
@@ -1664,17 +2102,17 @@ var TRTCCloud = /*#__PURE__*/function () {
1664
2102
  }, {
1665
2103
  key: "muteAllRemoteAudio",
1666
2104
  value: function muteAllRemoteAudio(mute) {
1667
- var _this17 = this;
2105
+ var _this13 = this;
1668
2106
  logger.info('muteAllRemoteAudio with options: ', mute);
1669
2107
  var playerList = this.trtc.getPlayerList();
1670
2108
  playerList.forEach(function (player) {
1671
2109
  var streamId = player.streamID;
1672
- var playerAttributes = _this17.setTRTCPlayerAttributes(streamId, {
2110
+ var playerAttributes = _this13.setTRTCPlayerAttributes(streamId, {
1673
2111
  muteAudio: mute
1674
2112
  });
1675
- _this17.InterfaceEventEmitter.emit('playerAttributesChange', {
2113
+ _this13.InterfaceEventEmitter.emit('playerAttributesChange', {
1676
2114
  streamId: streamId,
1677
- view: _this17.renderMap.get(streamId),
2115
+ view: _this13.renderMap.get(streamId),
1678
2116
  playerAttributes: playerAttributes,
1679
2117
  callback: function callback() {
1680
2118
  logger.info('muteAllRemoteAudio success');
@@ -1694,23 +2132,30 @@ var TRTCCloud = /*#__PURE__*/function () {
1694
2132
  }, {
1695
2133
  key: "switchCamera",
1696
2134
  value: function switchCamera(frontCamera) {
1697
- var _this18 = this;
2135
+ var _this14 = this;
1698
2136
  logger.info('switchCamera with options: ', frontCamera);
1699
2137
  var pusher = this.trtc.getPusherInstance();
1700
2138
  if (frontCamera === (pusher.pusherAttributes.frontCamera === 'front')) return Promise.resolve();
1701
2139
  return new Promise(function (resolve, reject) {
1702
2140
  wx.createLivePusherContext().switchCamera({
1703
2141
  success: function success(event) {
1704
- var pusher = _this18.trtc.setPusherAttributes({
1705
- frontCamera: true
1706
- });
1707
- _this18.InterfaceEventEmitter.emit('pusherAttributesChange', {
1708
- pusher: pusher,
1709
- callback: function callback() {
1710
- logger.info('switchCamera success');
1711
- }
1712
- });
1713
- 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
+ }));
1714
2159
  },
1715
2160
  fail: function fail(error) {
1716
2161
  logger.info('switchCamera fail');
@@ -1722,18 +2167,25 @@ var TRTCCloud = /*#__PURE__*/function () {
1722
2167
  }, {
1723
2168
  key: "setBeautyStyle",
1724
2169
  value: function setBeautyStyle(style, beauty, white, ruddiness) {
1725
- logger.info('setBeautyStyle with options: ', style, beauty, white, ruddiness);
1726
- var pusher = this.trtc.setPusherAttributes({
1727
- beautyStyle: style,
1728
- beautyLevel: beauty,
1729
- whitenessLevel: white
1730
- });
1731
- this.InterfaceEventEmitter.emit('pusherAttributesChange', {
1732
- pusher: pusher,
1733
- callback: function callback() {
1734
- logger.info('setBeautyStyle success');
1735
- }
1736
- });
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
+ }));
1737
2189
  }
1738
2190
  }, {
1739
2191
  key: "sendSEIMsg",
@@ -1897,6 +2349,40 @@ var TRTCCloud = /*#__PURE__*/function () {
1897
2349
  }
1898
2350
  }
1899
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
+ }
1900
2386
  }], [{
1901
2387
  key: "getTRTCShareInstance",
1902
2388
  value: function getTRTCShareInstance() {
@@ -1919,6 +2405,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1919
2405
  }]);
1920
2406
  return TRTCCloud;
1921
2407
  }();
2408
+ __decorate([setHandle], TRTCCloud.prototype, "setPusherAttributes", null);
1922
2409
 
1923
2410
  exports.TRTCCloud = TRTCCloud;
1924
2411
  exports.default = TRTCCloud;