trtc-electron-sdk 11.3.601-alpha.0 → 11.3.601-alpha.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "trtc-electron-sdk",
3
- "version": "11.3.601-alpha.0",
3
+ "version": "11.3.601-alpha.2",
4
4
  "description": "trtc electron sdk",
5
5
  "main": "./liteav/trtc.js",
6
6
  "types": "./liteav/trtc.d.ts",
@@ -65,6 +65,7 @@
65
65
  "build",
66
66
  "liteav",
67
67
  "types",
68
+ "scripts",
68
69
  "README.md",
69
70
  "package.json"
70
71
  ]
@@ -0,0 +1,9 @@
1
+ module.exports.Platform = {
2
+ MACOS: 'mac', // mac-x64
3
+ MACOS_ARM: 'mac-arm64',
4
+ WINDOWS32: 'win32',
5
+ WINDOWS64: 'win64',
6
+ UNSUPPORTED: 'unsupported',
7
+ LINUX_X64: 'linux-x64',
8
+ LINUX_ARM64: 'linux-arm64',
9
+ };
@@ -0,0 +1,70 @@
1
+ const path = require("path");
2
+ const { removeSync, copySync } = require("fs-extra");
3
+
4
+ // npm run copy:sdk
5
+ const SDK_ROOT = path.resolve(__dirname, "../../");
6
+ const SDK_CPP_PATH = path.join(SDK_ROOT, "trtc-electron-cpp");
7
+ const SDK_JS_PATH = path.join(SDK_ROOT, "trtc-electron-sdk");
8
+
9
+ removeSync(path.join(SDK_JS_PATH, "build"));
10
+
11
+ copySync(
12
+ path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node"),
13
+ path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.node")
14
+ );
15
+ if (process.platform === "win32") {
16
+ let dllPrefix = "";
17
+ if (process.arch === "x64") {
18
+ dllPrefix = "Win64";
19
+ } else {
20
+ dllPrefix = "Win32";
21
+ }
22
+ copySync(
23
+ path.resolve(SDK_CPP_PATH, `v2/win/${dllPrefix}/lib/`),
24
+ path.resolve(SDK_JS_PATH, "build/Release/")
25
+ );
26
+ copySync(
27
+ path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.pdb"),
28
+ path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.pdb")
29
+ );
30
+ } else if (process.platform === 'darwin') {
31
+ copySync(
32
+ path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node"),
33
+ path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/trtc_electron_sdk.node`)
34
+ );
35
+ copySync(
36
+ path.resolve(SDK_CPP_PATH, "build/Release/trtc_electron_sdk.node.dSYM"),
37
+ path.resolve(SDK_JS_PATH, "build/Release/trtc_electron_sdk.node.dSYM")
38
+ );
39
+ copySync(
40
+ path.resolve(SDK_CPP_PATH, `v2/mac/Frameworks/${process.arch}/TXFFmpeg.framework`),
41
+ path.resolve(SDK_JS_PATH, `build/mac-framework/${process.arch}/TXFFmpeg.framework`)
42
+ );
43
+ copySync(
44
+ path.resolve(SDK_CPP_PATH, `v2/mac/Frameworks/${process.arch}/TXSoundTouch.framework`),
45
+ path.resolve(SDK_JS_PATH, `build/mac-framework/${process.arch}/TXSoundTouch.framework`)
46
+ );
47
+ } else {
48
+ // linux
49
+ let soPrefix = ""
50
+ if (process.arch === 'x64') {
51
+ soPrefix = "x86_64";
52
+ } else {
53
+ soPrefix = "arm64";
54
+ }
55
+ copySync(
56
+ path.resolve(SDK_CPP_PATH, 'build/Release/trtc_electron_sdk.node'),
57
+ path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/trtc_electron_sdk.node`)
58
+ );
59
+ copySync(
60
+ path.resolve(SDK_CPP_PATH, `v2/linux/libs/${soPrefix}/`),
61
+ path.resolve(SDK_JS_PATH, 'build/Release/')
62
+ );
63
+ copySync(
64
+ path.resolve(SDK_CPP_PATH, `v2/linux/libs/${soPrefix}/`),
65
+ path.resolve(SDK_JS_PATH, `build/Release/${process.arch}/`)
66
+ );
67
+ }
68
+
69
+
70
+ console.log("CopySDKManual.doCopy: 复制结束");
@@ -0,0 +1,3 @@
1
+ const path = require('path');
2
+ const {copy} = require('fs-sync');
3
+ copy(path.resolve('./types'), path.resolve('./liteav'));
@@ -0,0 +1,206 @@
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 { exec } = require('child_process');
7
+ const { HttpsProxyAgent } = require('hpagent');
8
+
9
+ const currentPath = process.cwd();
10
+ const pathFlagValue = `packages${process.platform === "win32" ? "\\" : "/"}trtc-electron-sdk`;
11
+ if (currentPath.indexOf(pathFlagValue) !== -1) {
12
+ signale.info("trtc-electron-sdk: development mode, skip native sdk lib download");
13
+ return;
14
+ }
15
+
16
+ const {
17
+ readCliArgv,
18
+ readArgvFromNpmEnv,
19
+ detectOS,
20
+ detectOwnVersion,
21
+ detectOwnName,
22
+ readProxyUrlFromEnv,
23
+ } = require('./utils');
24
+ const { Platform } = require('./constant');
25
+
26
+ const buildDownloadInfo = () => {
27
+ const configArgv = Object.assign({
28
+ arch: process.arch,
29
+ platform: process.platform,
30
+ }, readCliArgv(), readArgvFromNpmEnv());
31
+
32
+ // build os label
33
+ const osLabel = detectOS(configArgv.arch, configArgv.platform);
34
+
35
+ // build version label
36
+ const { version } = detectOwnVersion();
37
+ signale.info('buildDownloadInfo version=', version);
38
+
39
+ const name = detectOwnName();
40
+ signale.info('buildDownloadInfo name=', name);
41
+
42
+ // generate download url
43
+ return {
44
+ platform: osLabel,
45
+ downloadUrl: `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${osLabel}-${version}.zip`,
46
+ name,
47
+ version,
48
+ archType: configArgv.arch
49
+ };
50
+ };
51
+
52
+ const main = () => {
53
+ const {
54
+ platform,
55
+ downloadUrl,
56
+ name,
57
+ version,
58
+ archType
59
+ } = buildDownloadInfo();
60
+
61
+ const outputDir = path.join(__dirname, '../temp');
62
+ const buildDir = path.join(__dirname, '../build');
63
+
64
+ rimraf.sync(outputDir);
65
+ rimraf(buildDir, err => {
66
+ if (err) {
67
+ signale.error(err);
68
+ process.exit(1);
69
+ }
70
+
71
+ // print download info
72
+ signale.info('removeDir =', buildDir);
73
+ signale.info('outputDir =', outputDir);
74
+
75
+ signale.info('Package Version =', version);
76
+ signale.info('Platform =', platform);
77
+ signale.info('Download Url =', downloadUrl, '\n');
78
+
79
+ signale.pending('Downloading C++ addon Electron SDK...\n');
80
+ const downloadOptions = {
81
+ strip: 0,
82
+ extract: true
83
+ };
84
+ const proxyUrl = readProxyUrlFromEnv(downloadUrl);
85
+ if (proxyUrl) {
86
+ downloadOptions.agent = {
87
+ https: new HttpsProxyAgent({
88
+ keepAlive: true,
89
+ keepAliveMsecs: 1000,
90
+ maxSockets: 256,
91
+ maxFreeSockets: 256,
92
+ scheduling: 'lifo',
93
+ proxy: proxyUrl
94
+ })
95
+ }
96
+ }
97
+ download(downloadUrl, outputDir, downloadOptions).then(() => {
98
+ signale.success(`Download finished - ${platform}`);
99
+
100
+ fs.copySync(
101
+ path.join(outputDir, './build/Release'),
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
+ // Mac 下完成文件下载后,执行该命令,同步文件到 Electron 目录下
153
+ exec(`rsync -a ../../node_modules/trtc-electron-sdk/build/mac-framework/${archType}/ ../../node_modules/electron/dist/Electron.app/Contents/Frameworks`);
154
+
155
+ rimraf.sync(outputDir);
156
+ })
157
+ .catch(err => {
158
+ signale.error(`download error! - mac ${anotherPlatform}`, err);
159
+ });
160
+ } else if (platform === 'linux-x64' || platform === 'linux-arm64') {
161
+ // Linux 下
162
+ const arch = process.arch;
163
+ fs.copySync(
164
+ path.join(outputDir, './build/Release'),
165
+ path.join(buildDir, 'Release', arch)
166
+ );
167
+ signale.success(`copy success! - linux ${arch}`, '\n');
168
+
169
+ let anotherPlatform, anotherArch;
170
+ if (arch === 'x64') {
171
+ // download arm64
172
+ anotherPlatform = Platform.LINUX_ARM64;
173
+ anotherArch = 'arm64';
174
+ } else {
175
+ // arch = arm64, download x64
176
+ anotherPlatform = Platform.LINUX_X64;
177
+ anotherArch = 'x64';
178
+ }
179
+ const anotherDownloadUrl = `https://web.sdk.qcloud.com/trtc/electron/download/${name}/${version}/${name}-${anotherPlatform}-${version}.zip`;
180
+ signale.info('Download Url =', anotherDownloadUrl, '\n');
181
+ signale.pending(`Downloading C++ addon Electron SDK... ${anotherArch}\n`);
182
+ download(anotherDownloadUrl, path.join(outputDir, anotherPlatform), {
183
+ strip: 0,
184
+ extract: true
185
+ }).then(() => {
186
+ signale.success(`Download finished - linux ${anotherArch}`);
187
+ fs.copySync(
188
+ path.join(outputDir, anotherPlatform, '/build/Release'),
189
+ path.join(buildDir, 'Release', anotherArch)
190
+ );
191
+ signale.success(`copy success! - linux ${anotherArch}`);
192
+
193
+ rimraf.sync(outputDir);
194
+ }).catch(err => {
195
+ signale.error(`download error! - linux ${anotherPlatform}`, err);
196
+ })
197
+ } else {
198
+ signale.warn(`Not supported platform: ${platform}`);
199
+ }
200
+ }).catch(err => {
201
+ signale.error(`Failed! Download error - ${platform}`, err);
202
+ });
203
+ });
204
+ };
205
+
206
+ main();
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+ const {copy, remove} = require('fs-sync');
3
+ const fs = require('fs');
4
+
5
+ const liteavPath = path.join(__dirname, '../liteav');
6
+ const liteavFiles = fs.readdirSync(liteavPath, {withFileTypes: true});
7
+ liteavFiles.forEach(file => {
8
+ if (file.isFile() && file.name.indexOf('_en.') !== -1) {
9
+ const filePath = path.join(liteavPath, file.name);
10
+ console.log(`Remove en files not to be published: `, filePath);
11
+ remove(filePath);
12
+ }
13
+ });
14
+
15
+ remove('./npm');
16
+ copy(path.resolve('./liteav'), path.resolve('./npm/liteav'));
17
+ copy(path.resolve('./scripts'), path.resolve('./npm/scripts'));
18
+ copy(path.resolve('./package.json'), path.resolve('./npm/package.json'));
19
+ copy(path.resolve('./README.md'), path.resolve('./npm/README.md'));
@@ -0,0 +1,91 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const COS = require('cos-nodejs-sdk-v5');
4
+
5
+ const cosConfig = {
6
+ SecretId: '',
7
+ SecretKey: ''
8
+ };
9
+
10
+ let enableWrite = false;
11
+ const myArgs = process.argv.slice(2);
12
+ myArgs.forEach(arg => {
13
+ if (arg.includes('=')) {
14
+ const [key, value] = arg.split('=');
15
+ if (key === 'SecretId' && value) {
16
+ // 注意: 确保在蓝盾运行时才打开, 真正上传文档到 cos
17
+ enableWrite = true;
18
+ cosConfig.SecretId = value;
19
+ }
20
+ if (key === 'SecretKey' && value) {
21
+ cosConfig.SecretKey = value;
22
+ }
23
+ }
24
+ });
25
+
26
+ if (!cosConfig.SecretId || !cosConfig.SecretKey) {
27
+ console.log('unable to upload doc');
28
+ }
29
+
30
+ const cos = new COS({
31
+ SecretId: cosConfig.SecretId,
32
+ SecretKey: cosConfig.SecretKey
33
+ });
34
+
35
+ const bucket = 'sdk-web-1252463788';
36
+ const region = 'ap-hongkong';
37
+ const keyPrefix = 'trtc/electron/doc/';
38
+ const docPath = path.join(__dirname, '../_doc');
39
+
40
+ function walkSync(dir, filelist) {
41
+ const files = fs.readdirSync(dir);
42
+ filelist = filelist || [];
43
+ files.forEach(function(file) {
44
+ if (fs.statSync(path.join(dir, file)).isDirectory()) {
45
+ filelist = walkSync(path.join(dir, file), filelist);
46
+ } else {
47
+ filelist.push({
48
+ path: path.join(dir, file),
49
+ name: path.relative(docPath, path.join(dir, file))
50
+ });
51
+ }
52
+ });
53
+ return filelist;
54
+ };
55
+
56
+ function getUploadFiles(docFileList) {
57
+ return docFileList.map(file => {
58
+ return {
59
+ Bucket: bucket,
60
+ Region: region,
61
+ Key: keyPrefix + file.name,
62
+ FilePath: file.path,
63
+ };
64
+ });
65
+ }
66
+
67
+ function uploadFiles() {
68
+ const docFileList = [];
69
+ walkSync(docPath, docFileList);
70
+ const fileList = getUploadFiles(docFileList);
71
+ if (enableWrite) {
72
+ cos.uploadFiles({
73
+ files: fileList,
74
+ SliceSize: 1024 * 1024,
75
+ onProgress: function (info) {
76
+ const percent = parseInt(info.percent * 10000) / 100;
77
+ const speed = parseInt((info.speed / 1024 / 1024) * 100) / 100;
78
+ console.log(`进度:${percent}%; 速度:${speed}Mb/s;`);
79
+ },
80
+ onFileFinish: function (err, data, options) {
81
+ console.log(`${options.Key}上传${err ? '失败' : '完成'}`);
82
+ },
83
+ }, function (err, data) {
84
+ if (err) {
85
+ console.log(JSON.stringify(err));
86
+ }
87
+ });
88
+ }
89
+ }
90
+
91
+ uploadFiles();
@@ -0,0 +1,26 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const os = require('os');
4
+
5
+ // trtc-electron-sdk 蓝盾地址: http://devops.oa.com/console/pipeline/ecc/p-b80c02872fad42dc9763c266593dfaed/history
6
+ // 因为需要去覆盖 ~/.npmrc 文件, 所以构建环境采用的是 macOS on DevCloud 云主机
7
+
8
+ let npmToken = '';
9
+ const myArgs = process.argv.slice(2);
10
+ myArgs.forEach(arg => {
11
+ if (arg.includes('=')) {
12
+ const [key, value] = arg.split('=');
13
+ if (key === 'npmToken' && value) {
14
+ npmToken = value;
15
+ }
16
+ }
17
+ });
18
+
19
+ if (!npmToken) {
20
+ console.log('not publish npmToken, cant publish npm');
21
+ return;
22
+ }
23
+ fs.writeFileSync(path.resolve(os.homedir(), '.npmrc'), `//registry.npmjs.org/:_authToken=${npmToken}`);
24
+
25
+ const content = fs.readFileSync(path.resolve(os.homedir(), '.npmrc'), {encoding: 'utf8'});
26
+ console.log('content: ', content);
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Utils for command line tools
3
+ */
4
+ const semver = require('semver');
5
+ const pkg = require('../package.json');
6
+
7
+ const { Platform } = require('./constant');
8
+
9
+ module.exports.readCliArgv = function() {
10
+ const cliArgv = process.argv;
11
+ const newArgv = {};
12
+ let tmp = [];
13
+ console.log('readCliArgv',cliArgv);
14
+ for (let i = 0, len = cliArgv.length ; i < len ; i++) {
15
+ if (i === 0) {
16
+ newArgv.nodeDir = cliArgv[i];
17
+ continue;
18
+ }
19
+ if (i === 1) {
20
+ newArgv.scriptDir = cliArgv[i];
21
+ continue;
22
+ }
23
+ tmp = cliArgv[i].replace('--','').split('=');
24
+ newArgv[tmp[0]] = tmp[1];
25
+ tmp = [];
26
+ }
27
+ return newArgv;
28
+ };
29
+
30
+ module.exports.readProxyUrlFromEnv = function(downloadUrl) {
31
+ if (downloadUrl.indexOf('https') === 0) {
32
+ return process.env.https_proxy || ''
33
+ }
34
+ return process.env.http_proxy || '';
35
+ }
36
+
37
+ module.exports.readArgvFromNpmEnv = function() {
38
+ const result = {};
39
+ if (process.env.npm_config_trtc_electron_arch) {
40
+ result.arch = process.env.npm_config_trtc_electron_arch;
41
+ }
42
+ if (process.env.npm_config_trtc_electron_platform) {
43
+ result.platform = process.env.npm_config_trtc_electron_platform;
44
+ }
45
+ return result;
46
+ };
47
+
48
+ module.exports.detectOS = (archType = '', platformType = '') => {
49
+ const platform = platformType !== '' ? platformType : process.platform;
50
+ const arch = archType !== '' ? archType : process.arch;
51
+ if (platform === 'darwin') {
52
+ if (arch === 'x64') {
53
+ return Platform.MACOS;
54
+ } else {
55
+ return Platform.MACOS_ARM;
56
+ }
57
+ } else if (platform === 'win32') {
58
+ if (arch === 'x64') {
59
+ return Platform.WINDOWS64;
60
+ } else {
61
+ return Platform.WINDOWS32;
62
+ }
63
+ } else if (platform === 'linux') {
64
+ if (arch === 'x64') {
65
+ return Platform.LINUX_X64;
66
+ } else if (arch === 'arm64') {
67
+ return Platform.LINUX_ARM64;
68
+ } else {
69
+ // unsupported
70
+ }
71
+ }
72
+ return Platform.UNSUPPORTED;
73
+ };
74
+
75
+ module.exports.detectOwnVersion = () => {
76
+ const { major, minor, patch } = semver.coerce(pkg.version);
77
+ return {
78
+ major, minor, patch, version: pkg.version
79
+ };
80
+ };
81
+
82
+ module.exports.detectOwnName = () => {
83
+ const name = pkg.name;
84
+ return name;
85
+ };
86
+