trtc-electron-sdk 12.0.605 → 12.1.607
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.
- package/README.md +117 -204
- package/liteav/VideoRenderControl/VideoRenderFPSMonitor.d.ts +37 -0
- package/liteav/VideoRenderControl/VideoRenderFPSMonitor.js +127 -0
- package/liteav/trtc.d.ts +57 -11
- package/liteav/trtc.js +77 -26
- package/liteav/trtc_define.d.ts +18 -16
- package/liteav/trtc_define.js +73 -9
- package/package.json +15 -9
- package/scripts/copy-sdk.js +4 -0
- package/scripts/download.js +228 -187
- package/scripts/utils.js +91 -26
package/scripts/download.js
CHANGED
|
@@ -1,203 +1,244 @@
|
|
|
1
|
-
const download = require(
|
|
2
|
-
const path = require(
|
|
3
|
-
const fs = require(
|
|
4
|
-
const rimraf = require(
|
|
5
|
-
const signale = require(
|
|
6
|
-
const {
|
|
7
|
-
const { HttpsProxyAgent } = require('hpagent');
|
|
1
|
+
const download = require("download");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const fs = require("fs-extra");
|
|
4
|
+
const rimraf = require("rimraf");
|
|
5
|
+
const signale = require("signale");
|
|
6
|
+
const { HttpsProxyAgent } = require("hpagent");
|
|
8
7
|
|
|
9
8
|
const currentPath = process.cwd();
|
|
10
|
-
const pathFlagValue = `packages${
|
|
9
|
+
const pathFlagValue = `packages${
|
|
10
|
+
process.platform === "win32" ? "\\" : "/"
|
|
11
|
+
}trtc-electron-sdk`;
|
|
11
12
|
if (currentPath.indexOf(pathFlagValue) !== -1) {
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
signale.info(
|
|
14
|
+
"trtc-electron-sdk: development mode, skip native sdk lib download"
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
const {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
readCliArgv,
|
|
21
|
+
readArgvFromNpmEnv,
|
|
22
|
+
detectOS,
|
|
23
|
+
detectOwnVersion,
|
|
24
|
+
detectOwnName,
|
|
25
|
+
readProxyUrlFromEnv,
|
|
26
|
+
readArgvFromPkgJson,
|
|
27
|
+
detectConfigArgv,
|
|
28
|
+
} = require("./utils");
|
|
29
|
+
const { Platform } = require("./constant");
|
|
25
30
|
|
|
26
31
|
const buildDownloadInfo = () => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
32
|
+
let configArgv = Object.assign(
|
|
33
|
+
{
|
|
34
|
+
arch: process.arch,
|
|
35
|
+
platform: process.platform,
|
|
36
|
+
},
|
|
37
|
+
readCliArgv(),
|
|
38
|
+
readArgvFromNpmEnv(),
|
|
39
|
+
readArgvFromPkgJson()
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
configArgv = detectConfigArgv(configArgv);
|
|
43
|
+
// build os label
|
|
44
|
+
const osLabel = detectOS(configArgv.arch, configArgv.platform);
|
|
45
|
+
// build version label
|
|
46
|
+
const { version } = detectOwnVersion();
|
|
47
|
+
signale.info("buildDownloadInfo version=", version);
|
|
48
|
+
|
|
49
|
+
const name = detectOwnName();
|
|
50
|
+
signale.info("buildDownloadInfo name=", name);
|
|
51
|
+
console.log("detectedArgv", osLabel);
|
|
52
|
+
// generate download url
|
|
53
|
+
return {
|
|
54
|
+
platform: osLabel,
|
|
55
|
+
downloadUrl: `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${osLabel}-${version}.zip`,
|
|
56
|
+
name,
|
|
57
|
+
version,
|
|
58
|
+
archType: configArgv.arch,
|
|
59
|
+
};
|
|
50
60
|
};
|
|
51
61
|
|
|
52
62
|
const main = () => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
const {
|
|
64
|
+
platform,
|
|
65
|
+
downloadUrl,
|
|
66
|
+
name,
|
|
67
|
+
version,
|
|
68
|
+
archType,
|
|
69
|
+
} = buildDownloadInfo();
|
|
70
|
+
|
|
71
|
+
const outputDir = path.join(__dirname, "../temp");
|
|
72
|
+
const buildDir = path.join(__dirname, "../build");
|
|
73
|
+
|
|
74
|
+
rimraf.sync(outputDir);
|
|
75
|
+
rimraf(buildDir, (err) => {
|
|
76
|
+
if (err) {
|
|
77
|
+
signale.fatal(err);
|
|
78
|
+
process.exit(1);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// print download info
|
|
82
|
+
signale.info("removeDir =", buildDir);
|
|
83
|
+
signale.info("outputDir =", outputDir);
|
|
84
|
+
|
|
85
|
+
signale.info("Package Version =", version);
|
|
86
|
+
signale.info("Platform =", platform);
|
|
87
|
+
signale.info("Download Url =", downloadUrl, "\n");
|
|
88
|
+
|
|
89
|
+
signale.pending("Downloading C++ addon Electron SDK...\n");
|
|
90
|
+
const downloadOptions = {
|
|
91
|
+
strip: 0,
|
|
92
|
+
extract: true,
|
|
93
|
+
};
|
|
94
|
+
const proxyUrl = readProxyUrlFromEnv(downloadUrl);
|
|
95
|
+
if (proxyUrl) {
|
|
96
|
+
downloadOptions.agent = {
|
|
97
|
+
https: new HttpsProxyAgent({
|
|
98
|
+
keepAlive: true,
|
|
99
|
+
keepAliveMsecs: 1000,
|
|
100
|
+
maxSockets: 256,
|
|
101
|
+
maxFreeSockets: 256,
|
|
102
|
+
scheduling: "lifo",
|
|
103
|
+
proxy: proxyUrl,
|
|
104
|
+
}),
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
download(downloadUrl, outputDir, downloadOptions)
|
|
108
|
+
.then(() => {
|
|
109
|
+
signale.success(`Download finished - ${platform}`);
|
|
110
|
+
|
|
111
|
+
fs.copySync(
|
|
112
|
+
path.join(outputDir, "./build/Release"),
|
|
113
|
+
path.join(buildDir, "Release")
|
|
114
|
+
);
|
|
115
|
+
signale.success(`copy success! - ${platform}`);
|
|
116
|
+
|
|
117
|
+
if (
|
|
118
|
+
platform === Platform.WINDOWS32 ||
|
|
119
|
+
platform === Platform.WINDOWS64
|
|
120
|
+
) {
|
|
121
|
+
// windows 下
|
|
122
|
+
rimraf.sync(outputDir);
|
|
123
|
+
} else if (
|
|
124
|
+
platform === Platform.MACOS ||
|
|
125
|
+
platform === Platform.MACOS_ARM
|
|
126
|
+
) {
|
|
127
|
+
// mac 下
|
|
128
|
+
const arch = archType;
|
|
129
|
+
fs.copySync(
|
|
130
|
+
path.join(outputDir, "./build/Release/trtc_electron_sdk.node"),
|
|
131
|
+
path.join(buildDir, "Release", arch, "trtc_electron_sdk.node")
|
|
132
|
+
);
|
|
133
|
+
fs.copySync(
|
|
134
|
+
path.join(outputDir, "./build/mac-framework", arch),
|
|
135
|
+
path.join(buildDir, "mac-framework", arch)
|
|
136
|
+
);
|
|
137
|
+
signale.success(`copy success! - mac ${arch}`, "\n");
|
|
138
|
+
|
|
139
|
+
let anotherPlatform, anotherArch;
|
|
140
|
+
if (arch === "x64") {
|
|
141
|
+
// download arm64
|
|
142
|
+
anotherPlatform = Platform.MACOS_ARM;
|
|
143
|
+
anotherArch = "arm64";
|
|
144
|
+
} else {
|
|
145
|
+
// arch = arm64, download x64
|
|
146
|
+
anotherPlatform = Platform.MACOS;
|
|
147
|
+
anotherArch = "x64";
|
|
148
|
+
}
|
|
149
|
+
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
150
|
+
signale.info("Download Url =", anotherDownloadUrl, "\n");
|
|
151
|
+
signale.pending(
|
|
152
|
+
`Downloading C++ addon Electron SDK... ${anotherArch}\n`
|
|
153
|
+
);
|
|
154
|
+
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
155
|
+
strip: 0,
|
|
156
|
+
extract: true,
|
|
157
|
+
})
|
|
158
|
+
.then(() => {
|
|
159
|
+
signale.success(`Download finished - mac ${anotherArch}`);
|
|
160
|
+
|
|
161
|
+
fs.copySync(
|
|
162
|
+
path.join(
|
|
163
|
+
outputDir,
|
|
164
|
+
anotherPlatform,
|
|
165
|
+
"/build/Release/trtc_electron_sdk.node"
|
|
166
|
+
),
|
|
167
|
+
path.join(
|
|
168
|
+
buildDir,
|
|
169
|
+
"Release",
|
|
170
|
+
anotherArch,
|
|
171
|
+
"trtc_electron_sdk.node"
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
fs.copySync(
|
|
175
|
+
path.join(
|
|
176
|
+
outputDir,
|
|
177
|
+
anotherPlatform,
|
|
178
|
+
"/build/mac-framework",
|
|
179
|
+
anotherArch
|
|
180
|
+
),
|
|
181
|
+
path.join(buildDir, "mac-framework", anotherArch)
|
|
182
|
+
);
|
|
183
|
+
signale.success(`copy success! - mac ${anotherArch}`);
|
|
184
|
+
|
|
185
|
+
rimraf.sync(outputDir);
|
|
186
|
+
})
|
|
187
|
+
.catch((err) => {
|
|
188
|
+
signale.fatal(`download error! - mac ${anotherPlatform}`, err);
|
|
189
|
+
});
|
|
190
|
+
} else if (
|
|
191
|
+
platform === Platform.LINUX_X64 ||
|
|
192
|
+
platform === Platform.LINUX_ARM64
|
|
193
|
+
) {
|
|
194
|
+
// Linux 下
|
|
195
|
+
const arch = process.arch;
|
|
196
|
+
fs.copySync(
|
|
197
|
+
path.join(outputDir, "./build/Release"),
|
|
198
|
+
path.join(buildDir, "Release", arch)
|
|
199
|
+
);
|
|
200
|
+
signale.success(`copy success! - linux ${arch}`, "\n");
|
|
201
|
+
|
|
202
|
+
let anotherPlatform, anotherArch;
|
|
203
|
+
if (arch === "x64") {
|
|
204
|
+
// download arm64
|
|
205
|
+
anotherPlatform = Platform.LINUX_ARM64;
|
|
206
|
+
anotherArch = "arm64";
|
|
207
|
+
} else {
|
|
208
|
+
// arch = arm64, download x64
|
|
209
|
+
anotherPlatform = Platform.LINUX_X64;
|
|
210
|
+
anotherArch = "x64";
|
|
211
|
+
}
|
|
212
|
+
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
213
|
+
signale.info("Download Url =", anotherDownloadUrl, "\n");
|
|
214
|
+
signale.pending(
|
|
215
|
+
`Downloading C++ addon Electron SDK... ${anotherArch}\n`
|
|
216
|
+
);
|
|
217
|
+
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
81
218
|
strip: 0,
|
|
82
|
-
extract: true
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
219
|
+
extract: true,
|
|
220
|
+
})
|
|
221
|
+
.then(() => {
|
|
222
|
+
signale.success(`Download finished - linux ${anotherArch}`);
|
|
223
|
+
fs.copySync(
|
|
224
|
+
path.join(outputDir, anotherPlatform, "/build/Release"),
|
|
225
|
+
path.join(buildDir, "Release", anotherArch)
|
|
226
|
+
);
|
|
227
|
+
signale.success(`copy success! - linux ${anotherArch}`);
|
|
228
|
+
|
|
229
|
+
rimraf.sync(outputDir);
|
|
230
|
+
})
|
|
231
|
+
.catch((err) => {
|
|
232
|
+
signale.fatal(`download error! - linux ${anotherPlatform}`, err);
|
|
233
|
+
});
|
|
234
|
+
} else {
|
|
235
|
+
signale.warn(`Not supported platform: ${platform}`);
|
|
96
236
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
path.join(buildDir, 'Release')
|
|
103
|
-
);
|
|
104
|
-
signale.success(`copy success! - ${platform}`);
|
|
105
|
-
|
|
106
|
-
if (platform === Platform.WINDOWS32 || platform === Platform.WINDOWS64) {
|
|
107
|
-
// windows 下
|
|
108
|
-
rimraf.sync(outputDir);
|
|
109
|
-
} else if (platform === 'mac' || platform === 'mac-arm64') {
|
|
110
|
-
// mac 下
|
|
111
|
-
const arch = archType;
|
|
112
|
-
fs.copySync(
|
|
113
|
-
path.join(outputDir, './build/Release/trtc_electron_sdk.node'),
|
|
114
|
-
path.join(buildDir, 'Release', arch, 'trtc_electron_sdk.node')
|
|
115
|
-
);
|
|
116
|
-
fs.copySync(
|
|
117
|
-
path.join(outputDir, './build/mac-framework', arch),
|
|
118
|
-
path.join(buildDir, 'mac-framework', arch)
|
|
119
|
-
);
|
|
120
|
-
signale.success(`copy success! - mac ${arch}`, '\n');
|
|
121
|
-
|
|
122
|
-
let anotherPlatform, anotherArch;
|
|
123
|
-
if (arch === 'x64') {
|
|
124
|
-
// download arm64
|
|
125
|
-
anotherPlatform = Platform.MACOS_ARM;
|
|
126
|
-
anotherArch = 'arm64';
|
|
127
|
-
} else {
|
|
128
|
-
// arch = arm64, download x64
|
|
129
|
-
anotherPlatform = Platform.MACOS;
|
|
130
|
-
anotherArch = 'x64';
|
|
131
|
-
}
|
|
132
|
-
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
133
|
-
signale.info('Download Url =', anotherDownloadUrl, '\n');
|
|
134
|
-
signale.pending(`Downloading C++ addon Electron SDK... ${anotherArch}\n`);
|
|
135
|
-
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
136
|
-
strip: 0,
|
|
137
|
-
extract: true
|
|
138
|
-
})
|
|
139
|
-
.then(() => {
|
|
140
|
-
signale.success(`Download finished - mac ${anotherArch}`);
|
|
141
|
-
|
|
142
|
-
fs.copySync(
|
|
143
|
-
path.join(outputDir, anotherPlatform, '/build/Release/trtc_electron_sdk.node'),
|
|
144
|
-
path.join(buildDir, 'Release', anotherArch, 'trtc_electron_sdk.node')
|
|
145
|
-
);
|
|
146
|
-
fs.copySync(
|
|
147
|
-
path.join(outputDir, anotherPlatform, '/build/mac-framework', anotherArch),
|
|
148
|
-
path.join(buildDir, 'mac-framework', anotherArch)
|
|
149
|
-
);
|
|
150
|
-
signale.success(`copy success! - mac ${anotherArch}`);
|
|
151
|
-
|
|
152
|
-
rimraf.sync(outputDir);
|
|
153
|
-
})
|
|
154
|
-
.catch(err => {
|
|
155
|
-
signale.fatal(`download error! - mac ${anotherPlatform}`, err);
|
|
156
|
-
});
|
|
157
|
-
} else if (platform === 'linux-x64' || platform === 'linux-arm64') {
|
|
158
|
-
// Linux 下
|
|
159
|
-
const arch = process.arch;
|
|
160
|
-
fs.copySync(
|
|
161
|
-
path.join(outputDir, './build/Release'),
|
|
162
|
-
path.join(buildDir, 'Release', arch)
|
|
163
|
-
);
|
|
164
|
-
signale.success(`copy success! - linux ${arch}`, '\n');
|
|
165
|
-
|
|
166
|
-
let anotherPlatform, anotherArch;
|
|
167
|
-
if (arch === 'x64') {
|
|
168
|
-
// download arm64
|
|
169
|
-
anotherPlatform = Platform.LINUX_ARM64;
|
|
170
|
-
anotherArch = 'arm64';
|
|
171
|
-
} else {
|
|
172
|
-
// arch = arm64, download x64
|
|
173
|
-
anotherPlatform = Platform.LINUX_X64;
|
|
174
|
-
anotherArch = 'x64';
|
|
175
|
-
}
|
|
176
|
-
const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
|
|
177
|
-
signale.info('Download Url =', anotherDownloadUrl, '\n');
|
|
178
|
-
signale.pending(`Downloading C++ addon Electron SDK... ${anotherArch}\n`);
|
|
179
|
-
download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
|
|
180
|
-
strip: 0,
|
|
181
|
-
extract: true
|
|
182
|
-
}).then(() => {
|
|
183
|
-
signale.success(`Download finished - linux ${anotherArch}`);
|
|
184
|
-
fs.copySync(
|
|
185
|
-
path.join(outputDir, anotherPlatform, '/build/Release'),
|
|
186
|
-
path.join(buildDir, 'Release', anotherArch)
|
|
187
|
-
);
|
|
188
|
-
signale.success(`copy success! - linux ${anotherArch}`);
|
|
189
|
-
|
|
190
|
-
rimraf.sync(outputDir);
|
|
191
|
-
}).catch(err => {
|
|
192
|
-
signale.fatal(`download error! - linux ${anotherPlatform}`, err);
|
|
193
|
-
})
|
|
194
|
-
} else {
|
|
195
|
-
signale.warn(`Not supported platform: ${platform}`);
|
|
196
|
-
}
|
|
197
|
-
}).catch(err => {
|
|
198
|
-
signale.fatal(`Failed! Download error - ${platform}`, err);
|
|
199
|
-
});
|
|
200
|
-
});
|
|
237
|
+
})
|
|
238
|
+
.catch((err) => {
|
|
239
|
+
signale.fatal(`Failed! Download error - ${platform}`, err);
|
|
240
|
+
});
|
|
241
|
+
});
|
|
201
242
|
};
|
|
202
243
|
|
|
203
244
|
main();
|
package/scripts/utils.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Utils for command line tools
|
|
3
3
|
*/
|
|
4
|
-
const semver = require(
|
|
5
|
-
const pkg = require(
|
|
4
|
+
const semver = require("semver");
|
|
5
|
+
const pkg = require("../package.json");
|
|
6
|
+
const { Platform } = require("./constant");
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
module.exports.readCliArgv = function() {
|
|
8
|
+
module.exports.readCliArgv = function () {
|
|
10
9
|
const cliArgv = process.argv;
|
|
11
10
|
const newArgv = {};
|
|
12
11
|
let tmp = [];
|
|
13
|
-
console.log(
|
|
14
|
-
for (let i = 0, len = cliArgv.length
|
|
12
|
+
console.log("readCliArgv", cliArgv);
|
|
13
|
+
for (let i = 0, len = cliArgv.length; i < len; i++) {
|
|
15
14
|
if (i === 0) {
|
|
16
15
|
newArgv.nodeDir = cliArgv[i];
|
|
17
16
|
continue;
|
|
@@ -20,21 +19,21 @@ module.exports.readCliArgv = function() {
|
|
|
20
19
|
newArgv.scriptDir = cliArgv[i];
|
|
21
20
|
continue;
|
|
22
21
|
}
|
|
23
|
-
tmp = cliArgv[i].replace(
|
|
22
|
+
tmp = cliArgv[i].replace("--", "").split("=");
|
|
24
23
|
newArgv[tmp[0]] = tmp[1];
|
|
25
24
|
tmp = [];
|
|
26
25
|
}
|
|
27
26
|
return newArgv;
|
|
28
27
|
};
|
|
29
28
|
|
|
30
|
-
module.exports.readProxyUrlFromEnv = function(downloadUrl) {
|
|
31
|
-
if (downloadUrl.indexOf(
|
|
32
|
-
return process.env.https_proxy ||
|
|
29
|
+
module.exports.readProxyUrlFromEnv = function (downloadUrl) {
|
|
30
|
+
if (downloadUrl.indexOf("https") === 0) {
|
|
31
|
+
return process.env.https_proxy || "";
|
|
33
32
|
}
|
|
34
|
-
return process.env.http_proxy ||
|
|
35
|
-
}
|
|
33
|
+
return process.env.http_proxy || "";
|
|
34
|
+
};
|
|
36
35
|
|
|
37
|
-
module.exports.readArgvFromNpmEnv = function() {
|
|
36
|
+
module.exports.readArgvFromNpmEnv = function () {
|
|
38
37
|
const result = {};
|
|
39
38
|
if (process.env.npm_config_trtc_electron_arch) {
|
|
40
39
|
result.arch = process.env.npm_config_trtc_electron_arch;
|
|
@@ -45,25 +44,89 @@ module.exports.readArgvFromNpmEnv = function() {
|
|
|
45
44
|
return result;
|
|
46
45
|
};
|
|
47
46
|
|
|
48
|
-
module.exports.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
module.exports.readArgvFromPkgJson = function () {
|
|
48
|
+
let INIT_CWD = process.env["INIT_CWD"];
|
|
49
|
+
if (!INIT_CWD) return {};
|
|
50
|
+
let rootDirIndex = 0;
|
|
51
|
+
let PkgJsonDir = "";
|
|
52
|
+
if (process.platform === "win32") {
|
|
53
|
+
INIT_CWD = INIT_CWD.split("\\");
|
|
54
|
+
rootDirIndex = INIT_CWD.findIndex((item) => item === "node_modules");
|
|
55
|
+
PkgJsonDir =
|
|
56
|
+
INIT_CWD.splice(0, rootDirIndex).join("\\\\") + "\\\\package.json";
|
|
57
|
+
} else {
|
|
58
|
+
INIT_CWD = INIT_CWD.split("/");
|
|
59
|
+
rootDirIndex = INIT_CWD.findIndex((item) => item === "node_modules");
|
|
60
|
+
PkgJsonDir = INIT_CWD.splice(0, rootDirIndex).join("/") + "/package.json";
|
|
61
|
+
}
|
|
62
|
+
const { trtc_electron } = require(PkgJsonDir);
|
|
63
|
+
console.log(
|
|
64
|
+
"INIT_CWD",
|
|
65
|
+
INIT_CWD,
|
|
66
|
+
"PkgJsonDir",
|
|
67
|
+
PkgJsonDir,
|
|
68
|
+
"trtc_electron",
|
|
69
|
+
trtc_electron
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!trtc_electron) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
const { platform, arch } = trtc_electron;
|
|
76
|
+
const result = {};
|
|
77
|
+
if (platform) {
|
|
78
|
+
result.platform = platform;
|
|
79
|
+
}
|
|
80
|
+
if (arch) {
|
|
81
|
+
result.arch = arch;
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
module.exports.detectConfigArgv = function (configArgv) {
|
|
87
|
+
if (Object.prototype.toString.call(configArgv) === "[object Object]") {
|
|
88
|
+
const { platform, arch } = configArgv;
|
|
89
|
+
if (platform === "darwin") {
|
|
90
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
91
|
+
configArgv.arch = "x64";
|
|
92
|
+
}
|
|
93
|
+
} else if (platform === "win32") {
|
|
94
|
+
if (arch !== "ia32" && arch !== "x64") {
|
|
95
|
+
configArgv.arch = "x64";
|
|
96
|
+
}
|
|
97
|
+
} else if (platform === "linux") {
|
|
98
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
99
|
+
configArgv.arch = "x64";
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return configArgv;
|
|
103
|
+
} else {
|
|
104
|
+
return {
|
|
105
|
+
platform: process.arch,
|
|
106
|
+
arch: process.platform,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
module.exports.detectOS = (archType = "", platformType = "") => {
|
|
112
|
+
const platform = platformType !== "" ? platformType : process.platform;
|
|
113
|
+
const arch = archType !== "" ? archType : process.arch;
|
|
114
|
+
if (platform === "darwin") {
|
|
115
|
+
if (arch === "x64") {
|
|
53
116
|
return Platform.MACOS;
|
|
54
117
|
} else {
|
|
55
118
|
return Platform.MACOS_ARM;
|
|
56
119
|
}
|
|
57
|
-
} else if (platform ===
|
|
58
|
-
if (arch ===
|
|
120
|
+
} else if (platform === "win32") {
|
|
121
|
+
if (arch === "x64") {
|
|
59
122
|
return Platform.WINDOWS64;
|
|
60
123
|
} else {
|
|
61
124
|
return Platform.WINDOWS32;
|
|
62
125
|
}
|
|
63
|
-
} else if (platform ===
|
|
64
|
-
if (arch ===
|
|
126
|
+
} else if (platform === "linux") {
|
|
127
|
+
if (arch === "x64") {
|
|
65
128
|
return Platform.LINUX_X64;
|
|
66
|
-
} else if (arch ===
|
|
129
|
+
} else if (arch === "arm64") {
|
|
67
130
|
return Platform.LINUX_ARM64;
|
|
68
131
|
} else {
|
|
69
132
|
// unsupported
|
|
@@ -75,7 +138,10 @@ module.exports.detectOS = (archType = '', platformType = '') => {
|
|
|
75
138
|
module.exports.detectOwnVersion = () => {
|
|
76
139
|
const { major, minor, patch } = semver.coerce(pkg.version);
|
|
77
140
|
return {
|
|
78
|
-
major,
|
|
141
|
+
major,
|
|
142
|
+
minor,
|
|
143
|
+
patch,
|
|
144
|
+
version: pkg.version,
|
|
79
145
|
};
|
|
80
146
|
};
|
|
81
147
|
|
|
@@ -83,4 +149,3 @@ module.exports.detectOwnName = () => {
|
|
|
83
149
|
const name = pkg.name;
|
|
84
150
|
return name;
|
|
85
151
|
};
|
|
86
|
-
|