UNPKG

@cloudroom/electron-rtcsdk

Version:

这是一款在线音视频SDK插件,您可以从README.md中获取演示demo

88 lines (76 loc) 2.54 kB
const downloadStatic = require('@cloudroom/load-static'); const path = require('path'); const { sdkVersion } = require('./package.json'); const fs = require('fs') let platform = process.env.npm_config_platform || process.platform; let arch = process.env.npm_config_arch || process.arch; if (platform === 'win32') { platform = 'win' } else if (platform === 'darwin') { platform = 'mac' } if (arch === 'ia32') { arch = 'x86' } else if (arch === 'x64') { arch = 'x86_64' } else if (arch === 'arm64') { arch = 'aarch64' } else if (arch === 'arm') { arch = 'armv7l' } ['win', 'mac', 'linux'].forEach(item => { if (fs.existsSync(path.resolve(__dirname, `./${item}`))) { fs.rmSync(path.resolve(__dirname, `./${item}`), { recursive: true }); } }); (async () => { const url = `https://cdn1.cloudroom.com/cdn_static/electron_rtcsdk_node/${platform}_${arch}_${sdkVersion[platform]}.zip`; await downloadStatic( url, { dir: path.resolve(__dirname, `./${platform}/${arch}/`), needCompress: true } ) let plugins = []; function readRootPkg(startPath) { let currentPath = startPath; while (true) { try { return require(require.resolve(path.join(currentPath, 'package.json'))); // 如果找到,则当前路径为项目根目录 } catch (error) { // 如果当前目录下没有 package.json 文件,则向上移动一层 const parentPath = path.dirname(currentPath); if (currentPath === parentPath) { throw new Error('无法找到项目package.json文件'); } currentPath = parentPath; } } } function loadPlugins(config) { config = Object.assign({ CRVBG: [], CRBeauty: [] }, config) try { if (platform === 'win' && config.CRVBG.indexOf(platform) > -1) { plugins.push('CRVBG') } if (platform === 'win' && config.CRBeauty.indexOf(platform) > -1) { plugins.push('CRBeauty') } } catch (error) { } } const pkg = readRootPkg(path.resolve(__dirname, '..')); pkg.rtcConfig && loadPlugins(pkg.rtcConfig) //下载插件包 plugins.forEach(item => { const url = `https://cdn1.cloudroom.com/cdn_static/electron_rtcsdk_node/${platform}_${arch}_${sdkVersion[platform]}_${item}.zip`; downloadStatic( url, { dir: path.resolve(__dirname, `./${platform}/${arch}/plugins/${item}`), needCompress: true } ) }) })()