@tencentcloud/trtc-cloud-wx 0.0.6 → 0.0.8

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 +2 -2
  2. package/trtc-cloud-wx.js +161 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/trtc-cloud-wx",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "",
5
5
  "main": "./trtc-cloud-wx.js",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "author": "",
9
9
  "license": "ISC",
10
10
  "dependencies": {
11
- "mitt": "^3.0.0",
11
+ "aegis-mp-sdk": "^1.37.7",
12
12
  "eventemitter3": "^5.0.0",
13
13
  "trtc-wx-sdk": "^1.1.5"
14
14
  }
package/trtc-cloud-wx.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var EventEmitter = require('eventemitter3');
6
6
  var TRTC = require('trtc-wx-sdk');
7
+ var Aegis = require('aegis-mp-sdk');
7
8
 
8
9
  function _iterableToArrayLimit(arr, i) {
9
10
  var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
@@ -676,6 +677,126 @@ function safelyParse(data) {
676
677
  }
677
678
  return result;
678
679
  }
680
+ var formatTime = function formatTime() {
681
+ var timestamp = new Date().getTime();
682
+ var date = new Date(timestamp);
683
+ // const year = date.getFullYear()
684
+ // const month = date.getMonth() + 1
685
+ // const day = date.getDate()
686
+ var hour = date.getHours();
687
+ var minute = date.getMinutes();
688
+ var second = date.getSeconds();
689
+ var millisecond = date.getMilliseconds();
690
+ hour = hour < 10 ? "0".concat(hour) : hour;
691
+ minute = minute < 10 ? "0".concat(minute) : minute;
692
+ second = second < 10 ? "0".concat(second) : second;
693
+ return "".concat(hour, ":").concat(minute, ":").concat(second, ".").concat(millisecond);
694
+ };
695
+
696
+ var aegis = new Aegis({
697
+ id: 'iHWefAYqxoRsFYGQvR' // 项目ID,即上报id
698
+ });
699
+
700
+ var LOGLEVEL = {
701
+ LOG: 0,
702
+ INFO: 1,
703
+ WARN: 2,
704
+ ERROR: 3,
705
+ NON_LOGGING: 4 // 无日志记录级别,sdk将不打印任何日志
706
+ };
707
+
708
+ var Logger = /*#__PURE__*/function () {
709
+ function Logger(tagName) {
710
+ _classCallCheck(this, Logger);
711
+ this.logLevel = 0;
712
+ this.TAG_NAME = '';
713
+ this.TAG_NAME = tagName || '[TRTCCloud-WX]';
714
+ }
715
+ _createClass(Logger, [{
716
+ key: "loggerInfo",
717
+ value: function loggerInfo() {
718
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
719
+ args[_key] = arguments[_key];
720
+ }
721
+ aegis.infoAll({
722
+ msg: "sdkAppId=".concat(this.sdkAppId, "\u3001roomId=").concat(this.roomId, "\u3001userId=").concat(this.userId, "\n").concat(String(args)),
723
+ ext1: this.sdkAppId,
724
+ ext2: this.roomId,
725
+ ext3: this.userId
726
+ });
727
+ }
728
+ }, {
729
+ key: "setInfo",
730
+ value: function setInfo(params) {
731
+ var sdkAppId = params.sdkAppId,
732
+ userId = params.userId,
733
+ roomId = params.roomId;
734
+ this.sdkAppId = sdkAppId;
735
+ this.userId = userId;
736
+ this.roomId = roomId;
737
+ }
738
+ }, {
739
+ key: "setLogLevel",
740
+ value: function setLogLevel(level) {
741
+ this.logLevel = level;
742
+ }
743
+ // 打印普通日志
744
+ }, {
745
+ key: "log",
746
+ value: function log() {
747
+ if (this.logLevel === LOGLEVEL.LOG) {
748
+ var _console;
749
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
750
+ args[_key2] = arguments[_key2];
751
+ }
752
+ (_console = console).log.apply(_console, [this.TAG_NAME, formatTime()].concat(args));
753
+ this.loggerInfo.apply(this, [this.TAG_NAME, formatTime()].concat(args));
754
+ }
755
+ }
756
+ }, {
757
+ key: "info",
758
+ value: function info() {
759
+ if (this.logLevel <= LOGLEVEL.INFO) {
760
+ var _console2;
761
+ for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
762
+ args[_key3] = arguments[_key3];
763
+ }
764
+ (_console2 = console).info.apply(_console2, [this.TAG_NAME, formatTime()].concat(args));
765
+ this.loggerInfo.apply(this, [this.TAG_NAME, formatTime()].concat(args));
766
+ }
767
+ }
768
+ // 打印告警日志
769
+ }, {
770
+ key: "warn",
771
+ value: function warn() {
772
+ // SDK 上报的相关事件
773
+ if (this.logLevel <= LOGLEVEL.WARN) {
774
+ var _console3;
775
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
776
+ args[_key4] = arguments[_key4];
777
+ }
778
+ (_console3 = console).warn.apply(_console3, [this.TAG_NAME, formatTime()].concat(args));
779
+ this.loggerInfo.apply(this, [this.TAG_NAME, formatTime()].concat(args));
780
+ }
781
+ }
782
+ // 打印错误日志
783
+ }, {
784
+ key: "error",
785
+ value: function error() {
786
+ // 状态机内部错误信息
787
+ if (this.logLevel <= LOGLEVEL.ERROR) {
788
+ var _console4;
789
+ for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
790
+ args[_key5] = arguments[_key5];
791
+ }
792
+ (_console4 = console).error.apply(_console4, [this.TAG_NAME, formatTime()].concat(args));
793
+ this.loggerInfo.apply(this, [this.TAG_NAME, formatTime()].concat(args));
794
+ }
795
+ }
796
+ }]);
797
+ return Logger;
798
+ }();
799
+ var logger = new Logger();
679
800
 
680
801
  var name = "@tencentcloud/trtc-cloud-wx";
681
802
  var version = "0.0.6";
@@ -727,6 +848,7 @@ var devDependencies = {
727
848
  typescript: "^5.0.2"
728
849
  };
729
850
  var dependencies = {
851
+ "aegis-mp-sdk": "^1.37.7",
730
852
  eventemitter3: "^5.0.0",
731
853
  "trtc-wx-sdk": "^1.1.5"
732
854
  };
@@ -766,6 +888,7 @@ var TRTCCloud = /*#__PURE__*/function () {
766
888
  this.audioVolumeEvaluation = 0;
767
889
  this.allTimer = {};
768
890
  this.renderMap = new Map();
891
+ this.logger = logger;
769
892
  this.init();
770
893
  }
771
894
  /**
@@ -969,7 +1092,6 @@ var TRTCCloud = /*#__PURE__*/function () {
969
1092
  }, {
970
1093
  key: "on",
971
1094
  value: function on(eventName, handler, context) {
972
- console.log('[TRTCCloud-WX:on]:', eventName);
973
1095
  this.EventEmitter.on(eventName, handler, context);
974
1096
  }
975
1097
  /**
@@ -1007,6 +1129,12 @@ var TRTCCloud = /*#__PURE__*/function () {
1007
1129
  strRoomId = params.strRoomId,
1008
1130
  role = params.role,
1009
1131
  privateMapKey = params.privateMapKey;
1132
+ logger.setInfo({
1133
+ sdkAppId: sdkAppId,
1134
+ userId: userId,
1135
+ roomId: roomId
1136
+ });
1137
+ logger.info('enterRoom with options: ', JSON.stringify(params), scene);
1010
1138
  this.userId = userId;
1011
1139
  this.trtc.createPusher({});
1012
1140
  var pusher = this.trtc.enterRoom({
@@ -1046,6 +1174,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1046
1174
  key: "exitRoom",
1047
1175
  value: function exitRoom() {
1048
1176
  var _this6 = this;
1177
+ logger.info('exitRoom');
1049
1178
  var _this$trtc$exitRoom = this.trtc.exitRoom(),
1050
1179
  pusher = _this$trtc$exitRoom.pusher;
1051
1180
  this.InterfaceEventEmitter.emit('pusherAttributesChange', {
@@ -1070,6 +1199,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1070
1199
  key: "switchRole",
1071
1200
  value: function switchRole(role) {
1072
1201
  var _this7 = this;
1202
+ logger.info('switchRole with options: ', role);
1073
1203
  var tempRole = this.role;
1074
1204
  this.role = role;
1075
1205
  if (tempRole === role || role === exports.TRTCRoleType.TRTCRoleAnchor) {
@@ -1105,6 +1235,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1105
1235
  value: function startLocalPreview() {
1106
1236
  var _this8 = this;
1107
1237
  var frontCamera = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1238
+ logger.info('startLocalPreview with options: ', frontCamera);
1108
1239
  return new Promise(function (resolve, reject) {
1109
1240
  if (_this8.role !== exports.TRTCRoleType.TRTCRoleAnchor) {
1110
1241
  resolve(null);
@@ -1146,6 +1277,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1146
1277
  key: "stopLocalPreview",
1147
1278
  value: function stopLocalPreview() {
1148
1279
  var _this9 = this;
1280
+ logger.info('stopLocalPreview');
1149
1281
  var pusher = this.trtc.setPusherAttributes({
1150
1282
  videoPreview: false,
1151
1283
  enableCamera: false
@@ -1165,6 +1297,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1165
1297
  }, {
1166
1298
  key: "updateLocalView",
1167
1299
  value: function updateLocalView(view) {
1300
+ logger.info('updateLocalView with options: ', view);
1168
1301
  if (view !== null) {
1169
1302
  this.startLocalPreview();
1170
1303
  return;
@@ -1181,6 +1314,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1181
1314
  key: "muteLocalVideo",
1182
1315
  value: function muteLocalVideo(mute, streamType) {
1183
1316
  var _this10 = this;
1317
+ logger.info('muteLocalVideo with options: ', mute, streamType);
1184
1318
  return new Promise(function (resolve, reject) {
1185
1319
  if (!_this10.isOpenCamera) {
1186
1320
  resolve(null);
@@ -1218,6 +1352,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1218
1352
  key: "startRemoteView",
1219
1353
  value: function startRemoteView(userId, view, streamType) {
1220
1354
  var _this11 = this;
1355
+ logger.info('startRemoteView with options: ', userId, view, streamType);
1221
1356
  var streamId = translateTRTCStreamId(userId, streamType);
1222
1357
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1223
1358
  muteVideo: false,
@@ -1241,6 +1376,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1241
1376
  }, {
1242
1377
  key: "stopRemoteView",
1243
1378
  value: function stopRemoteView(userId, streamType) {
1379
+ logger.info('stopRemoteView with options: ', userId, streamType);
1244
1380
  var streamId = translateTRTCStreamId(userId, streamType);
1245
1381
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1246
1382
  muteVideo: true,
@@ -1264,6 +1400,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1264
1400
  }, {
1265
1401
  key: "updateRemoteView",
1266
1402
  value: function updateRemoteView(userId, view, streamType) {
1403
+ logger.info('updateRemoteView with options: ', userId, view, streamType);
1267
1404
  if (view !== null) {
1268
1405
  this.startRemoteView(userId, view, streamType);
1269
1406
  return;
@@ -1275,6 +1412,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1275
1412
  key: "stopAllRemoteView",
1276
1413
  value: function stopAllRemoteView() {
1277
1414
  var _this12 = this;
1415
+ logger.info('stopAllRemoteView');
1278
1416
  var playerList = this.trtc.getPlayerList();
1279
1417
  playerList.forEach(function (player) {
1280
1418
  var streamId = player.streamID;
@@ -1294,6 +1432,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1294
1432
  }, {
1295
1433
  key: "muteRemoteVideoStream",
1296
1434
  value: function muteRemoteVideoStream(userId, mute, streamType) {
1435
+ logger.info('muteRemoteVideoStream');
1297
1436
  var streamId = translateTRTCStreamId(userId, streamType);
1298
1437
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1299
1438
  muteVideo: mute
@@ -1308,6 +1447,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1308
1447
  key: "muteAllRemoteVideoStreams",
1309
1448
  value: function muteAllRemoteVideoStreams(mute) {
1310
1449
  var _this13 = this;
1450
+ logger.info('muteAllRemoteVideoStreams with options: ', mute);
1311
1451
  var playerList = this.trtc.getPlayerList();
1312
1452
  playerList.forEach(function (player) {
1313
1453
  var streamId = player.streamID;
@@ -1324,6 +1464,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1324
1464
  }, {
1325
1465
  key: "setTRTCPlayerAttributes",
1326
1466
  value: function setTRTCPlayerAttributes(streamId, options) {
1467
+ logger.info('setTRTCPlayerAttributes with options: ', streamId, options);
1327
1468
  this.trtc.setPlayerAttributes(streamId, options);
1328
1469
  var _this$trtc$getPlayerI = this.trtc.getPlayerInstance(streamId),
1329
1470
  playerAttributes = _this$trtc$getPlayerI.playerAttributes;
@@ -1332,6 +1473,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1332
1473
  }, {
1333
1474
  key: "setVideoEncoderParam",
1334
1475
  value: function setVideoEncoderParam(params) {
1476
+ logger.info('setVideoEncoderParam with options: ', JSON.stringify(params));
1335
1477
  var videoResolution = params.videoResolution;
1336
1478
  params.resMode;
1337
1479
  var videoFps = params.videoFps;
@@ -1355,6 +1497,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1355
1497
  }, {
1356
1498
  key: "setLocalRenderParams",
1357
1499
  value: function setLocalRenderParams(params) {
1500
+ logger.info('setLocalRenderParams with options: ', JSON.stringify(params));
1358
1501
  var rotation = params.rotation;
1359
1502
  params.fillMode;
1360
1503
  var mirrorType = params.mirrorType;
@@ -1377,6 +1520,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1377
1520
  }, {
1378
1521
  key: "setRemoteRenderParams",
1379
1522
  value: function setRemoteRenderParams(userId, streamType, params) {
1523
+ logger.info('setRemoteRenderParams with options: ', userId, streamType, JSON.stringify(params));
1380
1524
  var fillMode = params.fillMode,
1381
1525
  rotation = params.rotation;
1382
1526
  params.mirrorType;
@@ -1395,6 +1539,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1395
1539
  key: "startLocalAudio",
1396
1540
  value: function startLocalAudio(quality) {
1397
1541
  var _this14 = this;
1542
+ logger.info('startLocalAudio with options: ', quality);
1398
1543
  var pusher = this.trtc.setPusherAttributes({
1399
1544
  enableMic: true
1400
1545
  });
@@ -1413,6 +1558,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1413
1558
  key: "stopLocalAudio",
1414
1559
  value: function stopLocalAudio() {
1415
1560
  var _this15 = this;
1561
+ logger.info('stopLocalAudio');
1416
1562
  var pusher = this.trtc.setPusherAttributes({
1417
1563
  enableMic: false
1418
1564
  });
@@ -1427,6 +1573,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1427
1573
  key: "muteLocalAudio",
1428
1574
  value: function muteLocalAudio(mute) {
1429
1575
  var _this16 = this;
1576
+ logger.info('muteLocalAudio with options: ', mute);
1430
1577
  var pusher = this.trtc.setPusherAttributes({
1431
1578
  enableMic: !mute
1432
1579
  });
@@ -1440,6 +1587,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1440
1587
  }, {
1441
1588
  key: "muteRemoteAudio",
1442
1589
  value: function muteRemoteAudio(userId, mute) {
1590
+ logger.info('muteRemoteAudio with options: ', userId, mute);
1443
1591
  var streamId = translateTRTCStreamId(userId, exports.TRTCVideoStreamType.TRTCVideoStreamTypeBig); // 音频默认都是主流
1444
1592
  var playerAttributes = this.setTRTCPlayerAttributes(streamId, {
1445
1593
  muteAudio: mute
@@ -1454,6 +1602,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1454
1602
  key: "muteAllRemoteAudio",
1455
1603
  value: function muteAllRemoteAudio(mute) {
1456
1604
  var _this17 = this;
1605
+ logger.info('muteAllRemoteAudio with options: ', mute);
1457
1606
  var playerList = this.trtc.getPlayerList();
1458
1607
  playerList.forEach(function (player) {
1459
1608
  var streamId = player.streamID;
@@ -1470,6 +1619,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1470
1619
  }, {
1471
1620
  key: "enableAudioVolumeEvaluation",
1472
1621
  value: function enableAudioVolumeEvaluation(interval) {
1622
+ logger.info('enableAudioVolumeEvaluation with options: ', interval);
1473
1623
  this.handleAudioVolumeUpdate = this.getHandleAudioVolumeUpdate(interval);
1474
1624
  }
1475
1625
  /**
@@ -1479,6 +1629,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1479
1629
  key: "switchCamera",
1480
1630
  value: function switchCamera(frontCamera) {
1481
1631
  var _this18 = this;
1632
+ logger.info('switchCamera with options: ', frontCamera);
1482
1633
  var pusher = this.trtc.getPusherInstance();
1483
1634
  if (frontCamera === (pusher.pusherAttributes.frontCamera === 'front')) return Promise.resolve();
1484
1635
  return new Promise(function (resolve, reject) {
@@ -1501,6 +1652,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1501
1652
  }, {
1502
1653
  key: "setBeautyStyle",
1503
1654
  value: function setBeautyStyle(style, beauty, white, ruddiness) {
1655
+ logger.info('setBeautyStyle with options: ', style, beauty, white, ruddiness);
1504
1656
  var pusher = this.trtc.setPusherAttributes({
1505
1657
  beautyStyle: style,
1506
1658
  beautyLevel: beauty,
@@ -1513,6 +1665,8 @@ var TRTCCloud = /*#__PURE__*/function () {
1513
1665
  }, {
1514
1666
  key: "sendSEIMsg",
1515
1667
  value: function sendSEIMsg(msg) {
1668
+ var repeatCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
1669
+ logger.info('sendSEIMsg with options: ', msg, repeatCount);
1516
1670
  return new Promise(function (resolve, reject) {
1517
1671
  wx.createLivePusherContext().sendMessage({
1518
1672
  msg: msg,
@@ -1528,6 +1682,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1528
1682
  }, {
1529
1683
  key: "startPlayMusic",
1530
1684
  value: function startPlayMusic(musicParam, callbackMap) {
1685
+ logger.info('startPlayMusic with options: ', JSON.stringify(musicParam));
1531
1686
  return new Promise(function (resolve, reject) {
1532
1687
  var path = musicParam.path,
1533
1688
  _musicParam$startTime = musicParam.startTimeMS,
@@ -1550,6 +1705,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1550
1705
  }, {
1551
1706
  key: "stopPlayMusic",
1552
1707
  value: function stopPlayMusic() {
1708
+ logger.info('stopPlayMusic');
1553
1709
  return new Promise(function (resolve, reject) {
1554
1710
  wx.createLivePusherContext().stopBGM({
1555
1711
  success: function success(event) {
@@ -1564,6 +1720,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1564
1720
  }, {
1565
1721
  key: "pausePlayMusic",
1566
1722
  value: function pausePlayMusic() {
1723
+ logger.info('pausePlayMusic');
1567
1724
  return new Promise(function (resolve, reject) {
1568
1725
  wx.createLivePusherContext().pauseBGM({
1569
1726
  success: function success(event) {
@@ -1578,6 +1735,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1578
1735
  }, {
1579
1736
  key: "resumePlayMusic",
1580
1737
  value: function resumePlayMusic() {
1738
+ logger.info('resumePlayMusic');
1581
1739
  return new Promise(function (resolve, reject) {
1582
1740
  wx.createLivePusherContext().resumeBGM({
1583
1741
  success: function success(event) {
@@ -1593,6 +1751,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1593
1751
  }, {
1594
1752
  key: "setAllMusicVolume",
1595
1753
  value: function setAllMusicVolume(volume) {
1754
+ logger.info('setAllMusicVolume with options: ', volume);
1596
1755
  return new Promise(function (resolve, reject) {
1597
1756
  var volumeStr = (volume / 200).toString();
1598
1757
  wx.createLivePusherContext().setBGMVolume({
@@ -1622,6 +1781,7 @@ var TRTCCloud = /*#__PURE__*/function () {
1622
1781
  }, {
1623
1782
  key: "callExperimentalAPI",
1624
1783
  value: function callExperimentalAPI(jsonStr) {
1784
+ logger.info('callExperimentalAPI with options: ', jsonStr);
1625
1785
  var jsonObj = safelyParse(jsonStr);
1626
1786
  if (jsonObj === jsonStr) {
1627
1787
  return;