UNPKG

@cloudroom/electron-meeting-sdk

Version:

基于C++,一款含UI的在线会议快速集成插件

182 lines (173 loc) 5.75 kB
const { EventEmitter } = require('events'); const path = require('path') let RTCElectronSDK = ""; let meetingPath = ""; const VERSION = require('./package.json').version; let os = require("os"); if (os.platform() === "win32") { if (process.arch === "x64") { RTCElectronSDK = "./plugin/win_x64/Electron_MeetingSDK"; meetingPath = require.resolve('./plugin/win_x64/meeting/NCONFMeeting.exe').replace('app.asar', 'app.asar.unpacked'); } else { RTCElectronSDK = "./plugin/win_ia32/Electron_MeetingSDK"; meetingPath = require.resolve('./plugin/win_ia32/meeting/NCONFMeeting.exe').replace('app.asar', 'app.asar.unpacked'); } } else if (os.platform() === "darwin") { RTCElectronSDK = `./plugin/mac_${process.arch}/Electron_MeetingSDK`; meetingPath = path.resolve(__dirname, `./plugin/mac_${process.arch}/NCONFMeeting.app`).replace('app.asar', 'app.asar.unpacked'); } else if (os.platform() == "linux") { if (process.arch == "x64") { RTCElectronSDK = "./plugin/linux_x64/Electron_MeetingSDK"; meetingPath = require.resolve('./plugin/linux_x64/meeting/NCONFMeeting.sh').replace('app.asar', 'app.asar.unpacked'); } else if (process.arch == "arm64" || process.arch == "aarch64") { RTCElectronSDK = "./plugin/linux_arm64/Electron_MeetingSDK"; meetingPath = require.resolve('./plugin/linux_arm64/meeting/NCONFMeeting.sh').replace('app.asar', 'app.asar.unpacked'); } else if (process.arch == "armv7l" || process.arch == "arm") { RTCElectronSDK = "./plugin/linux_armv7l/Electron_MeetingSDK"; //meetingPath = require.resolve('./linux/aarch64/meeting/NCONFMeeting.sh').replace('app.asar', 'app.asar.unpacked'); } else { console.log("arch: " + process.arch); throw "Platform not supported"; } } else { throw "Platform not supported"; } const RTCSDK = require(RTCElectronSDK); class CRVideoSDK extends EventEmitter { constructor() { super(); this.sdk_engine = null; this.version = VERSION; } //初始化 init({ server, sdkLogPath, } = {}) { if (this.sdk_engine) { return 0; } try { const sdk_engine = new RTCSDK.CRMeetingSDK_Node('', ''); this.sdk_engine = sdk_engine; let initDat = {}; initDat.meetingAppPathName = meetingPath; initDat.sdkLogPath = sdkLogPath || path.resolve(meetingPath, '../log'); initDat.server = server; console.log('init', initDat); var rslt = sdk_engine.init(initDat); console.log('init rslt:', rslt); sdk_engine.onDispatch(function (msgSN) { sdk_engine.dealCRMsg(msgSN); }); this._initEventHandler(); return rslt; } catch (error) { console.error(error) return 1; } } uninit() { console.log('uninit') if (!this.sdk_engine) { return; } this.sdk_engine.uninit(); this.sdk_engine = null; } //参数配置 setParams(jsonStr) { console.log('setParams:', jsonStr); return this.sdk_engine.setParams(jsonStr); } //登录 login(account, pswd) { console.log('login:', account, pswd); this.sdk_engine.login(account, pswd); } //登出 logout() { console.log('logout'); this.sdk_engine.logout(); } //接受呼叫 acceptCall(callID) { console.log('acceptCall:', callID); this.sdk_engine.acceptCall(callID); } //拒接呼叫 declineCall(callID) { console.log('declineCall:', callID); this.sdk_engine.declineCall(callID); } //入会 joinMeeting(meetID, pswd) { console.log('joinMeeting:', meetID, pswd); this.sdk_engine.joinMeeting(meetID, pswd); } //免登录入会 joinMeetingWithoutLogin(meetID, pswd, userID, userName, asHost) { console.log('joinMeetingWithoutLogin:', meetID, pswd, userID, userName, asHost); this.sdk_engine.joinMeetingWithoutLogin(meetID, pswd, userID, userName, asHost); } //无界面提示,立即离开会议, 要结束会议请调用WEB API leaveMeeting() { console.log('leaveMeeting'); this.sdk_engine.leaveMeeting(); } //设置自定义邀请模式 setCustomInviteType(mode) { console.log('setCustomInviteType:', mode); this.sdk_engine.setCustomInviteType(mode); } //在notifyQueryOrgInfo后,将自定义组织结构设置给sdk setCustomOrgInfo(orgInfo) { console.log('setCustomOrgInfo:', orgInfo); this.sdk_engine.setCustomOrgInfo(orgInfo); } /** * init event handler * @private */ _initEventHandler() { [ "onLoginRslt",// 登录结果 "notifyLineOff",// 掉线通知 "onJoinMeetingState",// 参会状态通知 "notifyCallIn",// 会议邀请通知 "notifyCallInCanceled",// 会议邀请取消通知 "notifyInvite",// 通知用户在会议中点击了邀请按钮 "notifyQueryOrgInfo",// 请求自定义组织结构 "notifyInviteUsers",// 通知邀请的人员 "notifyUserJoined",// 通知有人入会 "notifyUserLeft",// 通知有人离会 ].forEach(item => { this.sdk_engine.onEvent(item, (...arg) => { this.emit(item, ...arg); }) }) } } // 透明单例设计模式 let NativeCRVideoSDK = (function () { let instance = null; return class SDK { constructor() { return SDK.getInstance(); } static getInstance() { if (!instance) { instance = new CRVideoSDK(); } return instance; } //返回版本号对象 static getSDKVer() { return { plugin: VERSION, native: RTCSDK.getCRMeetingSDKVer() }; } }; })(); module.exports = NativeCRVideoSDK;