node-nim 10.9.30-beta.44 → 10.9.30
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v2_nim_struct_def.js","sourceRoot":"","sources":["../../ts/v2_def/v2_nim_struct_def.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"v2_nim_struct_def.js","sourceRoot":"","sources":["../../ts/v2_def/v2_nim_struct_def.ts"],"names":[],"mappings":";;AAuMC,CAAC;AA8dD,CAAC;AAy4BD,CAAC"}
|
package/node-nim-tester.js
CHANGED
|
@@ -3,43 +3,149 @@
|
|
|
3
3
|
const { Command } = require('commander')
|
|
4
4
|
const WebAT = require('hawk-web')
|
|
5
5
|
const program = new Command()
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const v8 = require('v8');
|
|
10
|
+
const { createLogger, format, transports } = require('winston');
|
|
11
|
+
const { combine, timestamp, label, printf } = format;
|
|
6
12
|
const downloadSDK = require('./script/download-sdk.js').downloadSDK
|
|
13
|
+
|
|
14
|
+
const loggerFormat = printf(({ level, message, label, timestamp }) => {
|
|
15
|
+
return `${timestamp} [${label}] ${level}: ${message}`;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const logger = createLogger({
|
|
19
|
+
level: 'info',
|
|
20
|
+
format: combine(
|
|
21
|
+
label({ label: 'right meow!' }),
|
|
22
|
+
timestamp({
|
|
23
|
+
format: () => {
|
|
24
|
+
const now = new Date();
|
|
25
|
+
const dateStr = now.toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai' });
|
|
26
|
+
const ms = now.getMilliseconds().toString().padStart(3, '0');
|
|
27
|
+
return `${dateStr}.${ms}`;
|
|
28
|
+
}
|
|
29
|
+
}),
|
|
30
|
+
loggerFormat
|
|
31
|
+
),
|
|
32
|
+
defaultMeta: { service: 'user-service' },
|
|
33
|
+
transports: [
|
|
34
|
+
new transports.File({
|
|
35
|
+
filename: (() => {
|
|
36
|
+
const logDir = path.join(os.homedir(), 'Downloads', 'node-nim');
|
|
37
|
+
// 如果文件夹不存在则创建
|
|
38
|
+
if (!fs.existsSync(logDir)) {
|
|
39
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
40
|
+
}
|
|
41
|
+
return path.join(logDir, `node-memory-${new Date().toISOString().split('T')[0]}-${process.pid}.log`);
|
|
42
|
+
})()
|
|
43
|
+
}),
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function getSystemMemoryInfo() {
|
|
48
|
+
const totalMemory = os.totalmem();
|
|
49
|
+
const freeMemory = os.freemem();
|
|
50
|
+
const usedMemory = totalMemory - freeMemory;
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
total: Math.round(totalMemory / 1024 / 1024), // MB
|
|
54
|
+
free: Math.round(freeMemory / 1024 / 1024), // MB
|
|
55
|
+
used: Math.round(usedMemory / 1024 / 1024), // MB
|
|
56
|
+
usagePercent: Math.round((usedMemory / totalMemory) * 100) // 百分比
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getProcessMemoryInfo() {
|
|
61
|
+
const usage = process.memoryUsage();
|
|
62
|
+
return {
|
|
63
|
+
rss: Math.round(usage.rss / 1024 / 1024), // 常驻内存大小
|
|
64
|
+
heapTotal: Math.round(usage.heapTotal / 1024 / 1024), // 堆总大小
|
|
65
|
+
heapUsed: Math.round(usage.heapUsed / 1024 / 1024), // 堆已使用
|
|
66
|
+
external: Math.round(usage.external / 1024 / 1024), // V8 外部内存
|
|
67
|
+
arrayBuffers: Math.round((usage.arrayBuffers || 0) / 1024 / 1024) // ArrayBuffer 大小
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function getV8HeapDetails() {
|
|
72
|
+
const heapStats = v8.getHeapStatistics();
|
|
73
|
+
const heapSpaceStats = v8.getHeapSpaceStatistics();
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
heap: {
|
|
77
|
+
totalHeapSize: Math.round(heapStats.total_heap_size / 1024 / 1024), // 总堆大小 MB
|
|
78
|
+
totalHeapSizeExecutable: Math.round(heapStats.total_heap_size_executable / 1024 / 1024), // 可执行堆大小 MB
|
|
79
|
+
totalPhysicalSize: Math.round(heapStats.total_physical_size / 1024 / 1024), // 物理大小 MB
|
|
80
|
+
totalAvailableSize: Math.round(heapStats.total_available_size / 1024 / 1024), // 可用大小 MB
|
|
81
|
+
usedHeapSize: Math.round(heapStats.used_heap_size / 1024 / 1024), // 已使用堆大小 MB
|
|
82
|
+
heapSizeLimit: Math.round(heapStats.heap_size_limit / 1024 / 1024), // 堆大小限制 MB (max-old-space-size)
|
|
83
|
+
mallocedMemory: Math.round(heapStats.malloced_memory / 1024 / 1024), // malloc 分配的内存 MB
|
|
84
|
+
peakMallocedMemory: Math.round(heapStats.peak_malloced_memory / 1024 / 1024), // 峰值 malloc 内存 MB
|
|
85
|
+
numberOfNativeContexts: heapStats.number_of_native_contexts, // 原生上下文数量
|
|
86
|
+
numberOfDetachedContexts: heapStats.number_of_detached_contexts // 分离上下文数量
|
|
87
|
+
},
|
|
88
|
+
spaces: heapSpaceStats.map(space => ({
|
|
89
|
+
name: space.space_name,
|
|
90
|
+
size: Math.round(space.space_size / 1024 / 1024), // 空间大小 MB
|
|
91
|
+
used: Math.round(space.space_used_size / 1024 / 1024), // 已使用大小 MB
|
|
92
|
+
available: Math.round(space.space_available_size / 1024 / 1024), // 可用大小 MB
|
|
93
|
+
physical: Math.round(space.physical_space_size / 1024 / 1024) // 物理大小 MB
|
|
94
|
+
}))
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
7
98
|
program
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
99
|
+
.command('run')
|
|
100
|
+
.description('run node-nim tester')
|
|
101
|
+
.requiredOption('--deviceId <deviceId>', 'tester device id')
|
|
102
|
+
.option('--taskId <taskId>', 'hawk test suite task id')
|
|
103
|
+
.option('--url <url>', 'hawk websocket url')
|
|
104
|
+
.option('--version <version>', 'test sdk version')
|
|
105
|
+
.option('--nimSdkUrl <nimSdkUrl>', 'nim native sdk download url')
|
|
106
|
+
.allowUnknownOption(true)
|
|
107
|
+
.action(async (options) => {
|
|
108
|
+
logger.info(`run node-nim tester, options: ${JSON.stringify(options)}`);
|
|
109
|
+
const heapStats = v8.getHeapStatistics();
|
|
110
|
+
logger.info(`V8 heap limit (max-old-space-size): ${Math.round(heapStats.heap_size_limit / 1024 / 1024)} MB`);
|
|
111
|
+
setInterval(() => {
|
|
112
|
+
const processMemoryUsage = getProcessMemoryInfo()
|
|
113
|
+
logger.info(`System memory usage: ${JSON.stringify(getSystemMemoryInfo(), null, 2)}`)
|
|
114
|
+
logger.info(`Process memory usage: ${JSON.stringify(getProcessMemoryInfo(), null, 2)}`)
|
|
115
|
+
logger.info(`V8 heap details: ${JSON.stringify(getV8HeapDetails())}`)
|
|
116
|
+
if (processMemoryUsage.heapTotal > 1000) {
|
|
117
|
+
const logDir = path.join(os.homedir(), 'Downloads', 'node-nim');
|
|
118
|
+
// 如果文件夹不存在则创建
|
|
119
|
+
if (!fs.existsSync(logDir)) {
|
|
120
|
+
fs.mkdirSync(logDir, { recursive: true });
|
|
121
|
+
}
|
|
122
|
+
const heapSnapshotFile = path.join(logDir, `node-heap-snapshot-${new Date().toISOString().split('T')[0]}-${process.pid}.log`);
|
|
123
|
+
if (!fs.existsSync(heapSnapshotFile)) {
|
|
124
|
+
logger.info(`Writing heap snapshot to ${heapSnapshotFile}`);
|
|
125
|
+
require('v8').writeHeapSnapshot(heapSnapshotFile);
|
|
25
126
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
127
|
+
}
|
|
128
|
+
}, 5 * 1000)
|
|
129
|
+
if (options.nimSdkUrl) {
|
|
130
|
+
await downloadSDK(options.nimSdkUrl)
|
|
131
|
+
}
|
|
132
|
+
const NIM = require('./dist/node-nim')
|
|
133
|
+
new WebAT({
|
|
134
|
+
applicationName: 'nim',
|
|
135
|
+
platform: 'Windows&MacOS',
|
|
136
|
+
version: options.version,
|
|
137
|
+
url: options.url,
|
|
138
|
+
deviceId: options.deviceId,
|
|
139
|
+
taskId: options.taskId,
|
|
140
|
+
targets: {
|
|
141
|
+
NIM
|
|
142
|
+
},
|
|
143
|
+
oncompleted: () => {
|
|
144
|
+
// 执行完成后退出进程
|
|
145
|
+
process.exit(0)
|
|
146
|
+
}
|
|
42
147
|
})
|
|
148
|
+
})
|
|
43
149
|
|
|
44
150
|
// parse
|
|
45
151
|
program.parse()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-nim",
|
|
3
|
-
"version": "10.9.30
|
|
3
|
+
"version": "10.9.30",
|
|
4
4
|
"description": "NetEase IM nodejs wrapper based on NetEase IM C++ SDK",
|
|
5
5
|
"main": "dist/node-nim.js",
|
|
6
6
|
"bin": {
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"sinon": "^18.0.0",
|
|
61
61
|
"typedoc": "^0.26.6",
|
|
62
62
|
"typedoc-github-theme": "^0.1.2",
|
|
63
|
-
"typescript": "^4.9.5"
|
|
63
|
+
"typescript": "^4.9.5",
|
|
64
|
+
"winston": "^3.17.0"
|
|
64
65
|
},
|
|
65
66
|
"keywords": [
|
|
66
67
|
"netease",
|
package/script/download-sdk.js
CHANGED
|
@@ -98,4 +98,10 @@ async function downloadSDK(custom_sdk_url) {
|
|
|
98
98
|
console.error(`[node-nim] Failed to download, error: ${err}`)
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
+
if (require.main === module) {
|
|
102
|
+
const args = process.argv
|
|
103
|
+
const downloadUrlIndex = args.indexOf('--nimSdkUrl');
|
|
104
|
+
const url = downloadUrlIndex !== -1 ? args[downloadUrlIndex + 1] : '';
|
|
105
|
+
downloadSDK(url)
|
|
106
|
+
}
|
|
101
107
|
exports.downloadSDK = downloadSDK
|
|
@@ -91,6 +91,8 @@ export interface V2NIMDatabaseOption {
|
|
|
91
91
|
backupFolder?: string;
|
|
92
92
|
/** SQLCipher 版本, 仅 macOS / Linux 平台有效 */
|
|
93
93
|
sqlcipherVersion?: V2NIMSQLCipherVersion;
|
|
94
|
+
/** 数据库备份间隔时间(秒),为 0 表示使用默认值(3 天备份一次)@since v10.9.30 */
|
|
95
|
+
backupIntervalTimeInSeconds?: number;
|
|
94
96
|
}
|
|
95
97
|
export interface V2NIMBasicOption {
|
|
96
98
|
/** 是否使用 https */
|
|
@@ -142,8 +144,6 @@ export interface V2NIMInitOption {
|
|
|
142
144
|
databaseOption?: V2NIMDatabaseOption;
|
|
143
145
|
/** 融合存储配置 */
|
|
144
146
|
fcsOption?: V2NIMFCSOption;
|
|
145
|
-
/** 登录路由(抄送)配置 */
|
|
146
|
-
routeConfig?: V2NIMRouteConfig;
|
|
147
147
|
/** 私有化配置 */
|
|
148
148
|
privateServerOption?: V2NIMPrivateServerOption;
|
|
149
149
|
}
|
|
@@ -1022,6 +1022,8 @@ export interface V2NIMLoginOption {
|
|
|
1022
1022
|
loginExtensionProvider?: V2NIMLoginExtensionProvider;
|
|
1023
1023
|
/** 数据同步等级 */
|
|
1024
1024
|
syncLevel?: V2NIMDataSyncDetail;
|
|
1025
|
+
/** 登录路由(抄送)配置 @since v10.9.30 */
|
|
1026
|
+
routeConfig?: V2NIMRouteConfig;
|
|
1025
1027
|
}
|
|
1026
1028
|
export interface V2NIMLoginClient {
|
|
1027
1029
|
/** 客户端类型 */
|
|
@@ -1569,6 +1571,8 @@ export interface V2NIMChatroomLoginOption {
|
|
|
1569
1571
|
tokenProvider?: V2NIMChatroomTokenProvider;
|
|
1570
1572
|
/** 登陆扩展回调 */
|
|
1571
1573
|
loginExtensionProvider?: V2NIMChatroomLoginExtensionProvider;
|
|
1574
|
+
/** 登录路由(抄送)配置 */
|
|
1575
|
+
routeConfig?: V2NIMRouteConfig;
|
|
1572
1576
|
}
|
|
1573
1577
|
export interface V2NIMChatroomTagConfig {
|
|
1574
1578
|
/** 登陆标签 */
|