trtc-electron-sdk 11.9.605 → 11.9.606-beta.1
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 +54 -211
- package/package.json +1 -1
- package/scripts/download.js +228 -187
- package/scripts/utils.js +83 -25
package/README.md
CHANGED
|
@@ -1,221 +1,64 @@
|
|
|
1
|
-
# TRTC
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
##
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-

|
|
38
|
-
3. 如果您在中国大陆,可能会遭遇下载 electron 压缩包很慢的问题:
|
|
39
|
-

|
|
40
|
-
此时可以通过配置国内的镜像地址,或者从 [Github](https://github.com/electron/electron/releases) 下载对应的版本和 `SHASUMS256.txt` 文件到 `C:\Users\[您的用户名]\AppData\Local\electron\Cache` 目录下,如下图:
|
|
41
|
-

|
|
42
|
-
4. 待 npm 的依赖包都安装完成后,继续在命令行窗口运行如下命令,即可运行起 Electron Demo。
|
|
43
|
-
```
|
|
44
|
-
npm start
|
|
45
|
-
```
|
|
46
|
-

|
|
47
|
-
|
|
1
|
+
# TRTC SDK for Electron
|
|
2
|
+
Tencent Real-Time Communication (TRTC) is a set of low-latency, high-quality real-time communication services provided by Tencent Cloud, which is committed to providing stable, reliable and low-cost audio and video transmission capabilities for Tencent Cloud customers.
|
|
3
|
+
|
|
4
|
+
## ✨ Features
|
|
5
|
+
- 📺 [Video call](https://www.tencentcloud.com/document/product/647/35428)
|
|
6
|
+
- 🎵 [Audio call](https://www.tencentcloud.com/document/product/647/35428)
|
|
7
|
+
- 🚿 [Interactive video streaming](https://www.tencentcloud.com/document/product/647/35428)
|
|
8
|
+
- 💧 [Interactive audio streaming](https://www.tencentcloud.com/document/product/647/35428)
|
|
9
|
+
- 📼 [On-Cloud Recording](https://www.tencentcloud.com/document/product/647/45169)
|
|
10
|
+
- 📼 [On-Cloud MixTranscoding](https://www.tencentcloud.com/document/product/647/47858#)
|
|
11
|
+
- ⬆️ [Publishing to CSS CDN](https://www.tencentcloud.com/document/product/647/47858#)
|
|
12
|
+
|
|
13
|
+
## 💻 Environment Support
|
|
14
|
+
- 🍎 Support macOS x64 and arm64(**Electron 11+**)
|
|
15
|
+
- ⚙️ Support Windows ia32 and x64
|
|
16
|
+
- 🌈 Electron: 8.5.0 ~ 24.8.8
|
|
17
|
+
|
|
18
|
+
| macOS | Windows | Electron |
|
|
19
|
+
| :----------: | :---------: | :------------: |
|
|
20
|
+
| x64 \| arm64 | ia32 \| x64 | 8.5.0 ~ 24.8.8 |
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## ⏬ Install
|
|
24
|
+
By default, it will install the SDK compatible with your device Operation System platform and node.js CPU architecture. If you want to install SDK for specific Operating System or CPU architecture. You can configure the `platform` and `arch` you want in `package.json` or `.npmrc` file as following code. If you configure both, the configuration in `package.json` will work and override that in `.npmrc`.
|
|
25
|
+
|
|
26
|
+
```json
|
|
27
|
+
// package.json
|
|
28
|
+
{
|
|
29
|
+
...
|
|
30
|
+
"trtc_electron" : {
|
|
31
|
+
"platform" : "win32",
|
|
32
|
+
"arch" : "ia32"
|
|
33
|
+
}
|
|
34
|
+
...
|
|
35
|
+
}
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
// .npmrc
|
|
38
|
+
trtc_electron_platform=win32
|
|
39
|
+
trtc_electron_arch=ia32 // only support windows
|
|
51
40
|
```
|
|
52
|
-
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
|
|
53
|
-
```
|
|
54
|
-
2. 继续键入如下命令,安装 Node.js:
|
|
55
|
-
```
|
|
56
|
-
$ brew install node
|
|
57
|
-
```
|
|
58
|
-
3. 如果您在中国大陆,可能会发现使用 Homebrew 的默认地址安装 Node.js 会比较慢,此时可以考虑替换为国内镜像地址。
|
|
59
|
-
```cmd
|
|
60
|
-
$ cd `brew --repo`
|
|
61
|
-
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
|
|
62
|
-
$ brew update
|
|
63
|
-
```
|
|
64
|
-
4. 通过 cd 命令定位到 [步骤3](#step3) 中解压到的目标路径,并运行如下命令:
|
|
65
|
-
```
|
|
66
|
-
npm install
|
|
67
|
-
```
|
|
68
|
-

|
|
69
|
-
5. 待 npm 的依赖包都安装完成后,继续在命令行窗口运行如下命令,即可运行起 Electron Demo。
|
|
70
|
-
```
|
|
71
|
-
npm start
|
|
72
|
-
```
|
|
73
|
-

|
|
74
|
-
|
|
75
41
|
|
|
76
|
-
|
|
77
|
-
|
|
42
|
+
Properties detail:
|
|
43
|
+
- platform: darwin or win32
|
|
44
|
+
- arch: if not set, it will be `process.arch` of your installation node.js. **Only windows Supported.**
|
|
78
45
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
#### step1. 通过npm下载trtc库(确认联网状态)
|
|
82
|
-
```
|
|
83
|
-
npm install trtc-electron-sdk@latest --save-dev
|
|
46
|
+
```bash
|
|
47
|
+
npm install trtc-electron-sdk
|
|
84
48
|
```
|
|
85
49
|
|
|
86
|
-
|
|
50
|
+
## 👋 Usage
|
|
87
51
|
```js
|
|
88
|
-
|
|
89
|
-
const TRTCCloud = require('trtc-electron-sdk');
|
|
90
|
-
const {
|
|
91
|
-
TRTCVideoStreamType,
|
|
92
|
-
TRTCAppScene,
|
|
93
|
-
TRTCVideoResolution,
|
|
94
|
-
TRTCVideoResolutionMode,
|
|
95
|
-
TRTCParams
|
|
96
|
-
} = require('trtc-electron-sdk/liteav/trtc_define');
|
|
97
|
-
|
|
98
|
-
//2、构建 TRTCCloud
|
|
99
|
-
this.rtcCloud = new TRTCCloud();
|
|
100
|
-
|
|
101
|
-
//3、注册回调
|
|
102
|
-
subscribeEvents = (rtcCloud) => {
|
|
103
|
-
rtcCloud.on('onError', (errcode, errmsg) => {
|
|
104
|
-
console.info('trtc_demo: onError :' + errcode + " msg" + errmsg);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
rtcCloud.on('onEnterRoom', (elapsed) => {
|
|
108
|
-
console.info('trtc_demo: onEnterRoom elapsed:' + elapsed);
|
|
109
|
-
});
|
|
110
|
-
rtcCloud.on('onExitRoom', (reason) => {
|
|
111
|
-
console.info('trtc_demo: onExitRoom reason:' + reason);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
// 注册远程视频的可用状态
|
|
115
|
-
rtcCloud.on('onUserVideoAvailable', (uid, available) => {
|
|
116
|
-
console.info('trtc_demo: onUserVideoAvailable uid:' + uid + " available:" + available);
|
|
117
|
-
if (available) {
|
|
118
|
-
let view = this.findVideoView(uid, TRTCVideoStreamType.TRTCVideoStreamTypeBig);
|
|
119
|
-
this.rtcCloud.startRemoteView(uid, view);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
this.rtcCloud.stopRemoteView(uid);
|
|
123
|
-
this.destroyVideoView(uid, TRTCVideoStreamType.TRTCVideoStreamTypeBig);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
//.....
|
|
128
|
-
//.....
|
|
129
|
-
};
|
|
130
|
-
subscribeEvents(this.rtcCloud);
|
|
131
|
-
|
|
132
|
-
//4、进入房间
|
|
133
|
-
enterroom () {
|
|
134
|
-
//1. 进房参数
|
|
135
|
-
let param = new TRTCParams();
|
|
136
|
-
param.sdkAppId = sdkInfo.sdkappid;
|
|
137
|
-
param.roomId = parseInt(this.roomId);
|
|
138
|
-
param.userSig = userSig;
|
|
139
|
-
param.userId = this.userId;
|
|
140
|
-
param.privateMapKey = '';
|
|
141
|
-
param.businessInfo = '';
|
|
142
|
-
this.rtcCloud.enterRoom(param, TRTCAppScene.TRTCAppSceneVideoCall);
|
|
143
|
-
//2. 编码参数
|
|
144
|
-
let encparam = new TRTCVideoEncParam();
|
|
145
|
-
encparam.videoResolution = TRTCVideoResolution.TRTCVideoResolution_640_360;
|
|
146
|
-
encparam.resMode = TRTCVideoResolutionMode.TRTCVideoResolutionModeLandscape;
|
|
147
|
-
encparam.videoFps = 15;
|
|
148
|
-
encparam.videoBitrate = 550;
|
|
149
|
-
this.rtcCloud.setVideoEncoderParam(encparam);
|
|
150
|
-
//3. 打开采集和预览本地视频、采集音频
|
|
151
|
-
enableVideoCapture(true);
|
|
152
|
-
enableAudioCapture(true);
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
//5、退出房间
|
|
156
|
-
exitroom() {
|
|
157
|
-
this.rtcCloud.exitRoom();
|
|
158
|
-
},
|
|
159
|
-
|
|
160
|
-
//6、开启视频
|
|
161
|
-
enableVideoCapture(bEnable) {
|
|
162
|
-
if (bEnable) {
|
|
163
|
-
let view = this.findView("local", TRTCVideoStreamType.TRTCVideoStreamTypeBig);
|
|
164
|
-
this.rtcCloud.startLocalPreview(view);
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
this.rtcCloud.stopLocalPreview();
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
//7、开启音频
|
|
172
|
-
enableAudioCapture(bEnable) {
|
|
173
|
-
if (bEnable) {
|
|
174
|
-
this.rtcCloud.startLocalAudio();
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
this.rtcCloud.stopLocalAudio();
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
//8、找个DOM结点,作为视频显示的view
|
|
182
|
-
findVideoView(uid, streamtype) {
|
|
183
|
-
let key = uid + String(streamtype);
|
|
184
|
-
var userVideoEl = document.getElementById(key);
|
|
185
|
-
if (!userVideoEl) {
|
|
186
|
-
userVideoEl = document.createElement('div');
|
|
187
|
-
userVideoEl.id = key;
|
|
188
|
-
userVideoEl.classList.add('video_view');
|
|
189
|
-
document.querySelector("#video_wrap").appendChild(userVideoEl);
|
|
190
|
-
}
|
|
191
|
-
return userVideoEl;
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
//9、在视频退出时,清掉一个DOM结点
|
|
195
|
-
destroyVideoView(uid, streamtype) {
|
|
196
|
-
let key = uid + String(streamtype);
|
|
197
|
-
var userVideoEl = document.getElementById(key);
|
|
198
|
-
if (userVideoEl) {
|
|
199
|
-
document.querySelector("#video_wrap").removeChild(userVideoEl);
|
|
200
|
-
}
|
|
201
|
-
},
|
|
52
|
+
import TRTCCloud from 'trtc-electron-sdk';
|
|
202
53
|
|
|
54
|
+
const rtcCloud = TRTCCloud.getTRTCShareInstance();
|
|
55
|
+
// Obtain the SDK version
|
|
56
|
+
const version = rtcCloud.getSDKVersion();
|
|
203
57
|
```
|
|
204
58
|
|
|
205
|
-
##
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
1. 登录 [实时音视频控制台](https://console.cloud.tencent.com/trtc)。
|
|
212
|
-
2. 在左侧导航栏选择【应用管理】,单击目标应用所在行的【应用信息】。
|
|
213
|
-
3. 选择【快速上手】页签,单击【第二步 获取签发UserSig的密钥】区域的【点此升级】。
|
|
214
|
-
|
|
215
|
-
### 2. 两台设备同时运行 Demo,为什么看不到彼此的画面?
|
|
216
|
-
请确保两台设备在运行 Demo 时使用的是不同的 UserID,TRTC 不支持同一个 UserID (除非 SDKAppID 不同)在两个设备同时使用。
|
|
217
|
-
|
|
218
|
-

|
|
219
|
-
|
|
220
|
-
### 3. 防火墙有什么限制?
|
|
221
|
-
由于 SDK 使用 UDP 协议进行音视频传输,所以对 UDP 有拦截的办公网络下无法使用,如遇到类似问题,请参考文档:[应对公司防火墙限制](https://cloud.tencent.com/document/product/647/34399)。
|
|
59
|
+
## 🔗 Links
|
|
60
|
+
- [Official Site](https://trtc.io/products/rtc)
|
|
61
|
+
- [API Document](https://web.sdk.qcloud.com/trtc/electron/doc/en-us/trtc_electron_sdk/index.html
|
|
62
|
+
)
|
|
63
|
+
- [Online Demo](https://trtc.io/demo)
|
|
64
|
+
- [Github demo]( https://github.com/Tencent-RTC/TRTC_Electron)
|
package/package.json
CHANGED
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,19 @@
|
|
|
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 path = require("path");
|
|
6
7
|
|
|
7
|
-
const { Platform } = require(
|
|
8
|
+
const { Platform } = require("./constant");
|
|
9
|
+
const { platform, arch } = require("os");
|
|
8
10
|
|
|
9
|
-
module.exports.readCliArgv = function() {
|
|
11
|
+
module.exports.readCliArgv = function () {
|
|
10
12
|
const cliArgv = process.argv;
|
|
11
13
|
const newArgv = {};
|
|
12
14
|
let tmp = [];
|
|
13
|
-
console.log(
|
|
14
|
-
for (let i = 0, len = cliArgv.length
|
|
15
|
+
console.log("readCliArgv", cliArgv);
|
|
16
|
+
for (let i = 0, len = cliArgv.length; i < len; i++) {
|
|
15
17
|
if (i === 0) {
|
|
16
18
|
newArgv.nodeDir = cliArgv[i];
|
|
17
19
|
continue;
|
|
@@ -20,21 +22,21 @@ module.exports.readCliArgv = function() {
|
|
|
20
22
|
newArgv.scriptDir = cliArgv[i];
|
|
21
23
|
continue;
|
|
22
24
|
}
|
|
23
|
-
tmp = cliArgv[i].replace(
|
|
25
|
+
tmp = cliArgv[i].replace("--", "").split("=");
|
|
24
26
|
newArgv[tmp[0]] = tmp[1];
|
|
25
27
|
tmp = [];
|
|
26
28
|
}
|
|
27
29
|
return newArgv;
|
|
28
30
|
};
|
|
29
31
|
|
|
30
|
-
module.exports.readProxyUrlFromEnv = function(downloadUrl) {
|
|
31
|
-
if (downloadUrl.indexOf(
|
|
32
|
-
return process.env.https_proxy ||
|
|
32
|
+
module.exports.readProxyUrlFromEnv = function (downloadUrl) {
|
|
33
|
+
if (downloadUrl.indexOf("https") === 0) {
|
|
34
|
+
return process.env.https_proxy || "";
|
|
33
35
|
}
|
|
34
|
-
return process.env.http_proxy ||
|
|
35
|
-
}
|
|
36
|
+
return process.env.http_proxy || "";
|
|
37
|
+
};
|
|
36
38
|
|
|
37
|
-
module.exports.readArgvFromNpmEnv = function() {
|
|
39
|
+
module.exports.readArgvFromNpmEnv = function () {
|
|
38
40
|
const result = {};
|
|
39
41
|
if (process.env.npm_config_trtc_electron_arch) {
|
|
40
42
|
result.arch = process.env.npm_config_trtc_electron_arch;
|
|
@@ -45,25 +47,79 @@ module.exports.readArgvFromNpmEnv = function() {
|
|
|
45
47
|
return result;
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
module.exports.
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
module.exports.readArgvFromPkgJson = function () {
|
|
51
|
+
const INIT_CWD = process.env["INIT_CWD"];
|
|
52
|
+
const PkgJsonDir = INIT_CWD && path.join(INIT_CWD, "package.json");
|
|
53
|
+
const { trtc_electron } = require(PkgJsonDir);
|
|
54
|
+
console.log(
|
|
55
|
+
"INIT_CWD",
|
|
56
|
+
INIT_CWD,
|
|
57
|
+
"PkgJsonDir",
|
|
58
|
+
PkgJsonDir,
|
|
59
|
+
"trtc_electron",
|
|
60
|
+
trtc_electron
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!trtc_electron) {
|
|
64
|
+
return {};
|
|
65
|
+
}
|
|
66
|
+
const { platform, arch } = trtc_electron;
|
|
67
|
+
const result = {};
|
|
68
|
+
if (platform) {
|
|
69
|
+
result.platform = platform;
|
|
70
|
+
}
|
|
71
|
+
if (arch) {
|
|
72
|
+
result.arch = arch;
|
|
73
|
+
}
|
|
74
|
+
return result;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
module.exports.detectConfigArgv = function (configArgv) {
|
|
78
|
+
const localArch = process.arch;
|
|
79
|
+
const localPlatform = process.platform;
|
|
80
|
+
if (Object.prototype.toString.call(configArgv) === "[object Object]") {
|
|
81
|
+
const { platform, arch } = configArgv;
|
|
82
|
+
if (platform === "darwin") {
|
|
83
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
84
|
+
configArgv.arch = localArch;
|
|
85
|
+
}
|
|
86
|
+
} else if (platform === "win32") {
|
|
87
|
+
if (arch !== "ia32" && arch !== "x64") {
|
|
88
|
+
configArgv.arch = localArch;
|
|
89
|
+
}
|
|
90
|
+
} else if (platform === "linux") {
|
|
91
|
+
if (arch !== "x64" && arch !== "arm64") {
|
|
92
|
+
configArgv.arch = localArch;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return configArgv;
|
|
96
|
+
} else {
|
|
97
|
+
return {
|
|
98
|
+
platform: localPlatform,
|
|
99
|
+
arch: localArch,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
module.exports.detectOS = (archType = "", platformType = "") => {
|
|
105
|
+
const platform = platformType !== "" ? platformType : process.platform;
|
|
106
|
+
const arch = archType !== "" ? archType : process.arch;
|
|
107
|
+
if (platform === "darwin") {
|
|
108
|
+
if (arch === "x64") {
|
|
53
109
|
return Platform.MACOS;
|
|
54
110
|
} else {
|
|
55
111
|
return Platform.MACOS_ARM;
|
|
56
112
|
}
|
|
57
|
-
} else if (platform ===
|
|
58
|
-
if (arch ===
|
|
113
|
+
} else if (platform === "win32") {
|
|
114
|
+
if (arch === "x64") {
|
|
59
115
|
return Platform.WINDOWS64;
|
|
60
116
|
} else {
|
|
61
117
|
return Platform.WINDOWS32;
|
|
62
118
|
}
|
|
63
|
-
} else if (platform ===
|
|
64
|
-
if (arch ===
|
|
119
|
+
} else if (platform === "linux") {
|
|
120
|
+
if (arch === "x64") {
|
|
65
121
|
return Platform.LINUX_X64;
|
|
66
|
-
} else if (arch ===
|
|
122
|
+
} else if (arch === "arm64") {
|
|
67
123
|
return Platform.LINUX_ARM64;
|
|
68
124
|
} else {
|
|
69
125
|
// unsupported
|
|
@@ -75,7 +131,10 @@ module.exports.detectOS = (archType = '', platformType = '') => {
|
|
|
75
131
|
module.exports.detectOwnVersion = () => {
|
|
76
132
|
const { major, minor, patch } = semver.coerce(pkg.version);
|
|
77
133
|
return {
|
|
78
|
-
major,
|
|
134
|
+
major,
|
|
135
|
+
minor,
|
|
136
|
+
patch,
|
|
137
|
+
version: pkg.version,
|
|
79
138
|
};
|
|
80
139
|
};
|
|
81
140
|
|
|
@@ -83,4 +142,3 @@ module.exports.detectOwnName = () => {
|
|
|
83
142
|
const name = pkg.name;
|
|
84
143
|
return name;
|
|
85
144
|
};
|
|
86
|
-
|