@cloudroom/electron-meeting-sdk
Version:
基于C++,一款含UI的在线会议快速集成插件
182 lines (171 loc) • 5.52 kB
JavaScript
const { EventEmitter } = require('events');
const path = require('path')
let RTCElectronSDK = "";
let meetingPath = "";
let os = require("os");
if (os.platform() === "win32") {
if (process.arch === "x64") {
RTCElectronSDK = "./win/x86_64/Electron_MeetingSDK";
meetingPath = require.resolve('./win/x86_64/meeting/NCONFMeeting.exe').replace('app.asar', 'app.asar.unpacked');
} else {
RTCElectronSDK = "./win/x86/Electron_MeetingSDK";
meetingPath = require.resolve('./win/x86/meeting/NCONFMeeting.exe').replace('app.asar', 'app.asar.unpacked');
}
} else if (os.platform() === "darwin") {
RTCElectronSDK = "./mac/x86_64/Electron_MeetingSDK";
meetingPath = path.resolve(__dirname,'./mac/x86_64/NCONFMeeting.app').replace('app.asar', 'app.asar.unpacked');
} else if (os.platform() == "linux") {
if (process.arch == "x64") {
RTCElectronSDK = "./linux/x86_64/Electron_MeetingSDK";
meetingPath = require.resolve('./linux/x86_64/meeting/NCONFMeeting.sh').replace('app.asar', 'app.asar.unpacked');
} else if (process.arch == "arm64" || process.arch == "aarch64") {
RTCElectronSDK = "./linux/aarch64/Electron_MeetingSDK";
meetingPath = require.resolve('./linux/aarch64/meeting/NCONFMeeting.sh').replace('app.asar', 'app.asar.unpacked');
} else if (process.arch == "armv7l" || process.arch == "arm") {
RTCElectronSDK = "./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;
}
//初始化
init({
server,
sdkLogPath,
} = {}) {
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 || 'crlab.cloudroom.com';
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')
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();
}
//启用自定义组织结构
enableCustomOrgInfo(enable) {
console.log('enableCustomOrgInfo:', enable);
this.sdk_engine.enableCustomOrgInfo(enable);
}
//在notifyQueryOrgInfo后,将自定义组织结构设置给sdk
setCustomOrgInfo(orgInfo) {
console.log('setCustomOrgInfo:', orgInfo);
this.sdk_engine.setCustomOrgInfo(orgInfo);
}
//获取会议SDK版本
getMeetingSDKVer() {
console.log('getMeetingSDKVer');
return this.sdk_engine.getMeetingSDKVer();
}
/**
* init event handler
* @private
*/
_initEventHandler() {
[
"onLoginRslt",
//登录结果
"onLoginRslt",
//掉线通知
"notifyLineOff",
//呼入通知
"notifyCallIn",
"notifyCallInCanceled",
//参会状态通知
"onJoinMeetingState",
//请求自定义组织结构
"notifyQueryOrgInfo",
//通知邀请的人员信息[{"id":xxx}]
"notifyInviteUsers",
].forEach(item => {
this.sdk_engine.onEvent(item, (...arg) => {
if (['notifyMicEnergy'].indexOf(item) === -1) {
console.log(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;
}
};
})();
module.exports = NativeCRVideoSDK;
// export default NativeCRVideoSDK;