问题
错误
agora_node_ext.node is not a valid Win32 application
解决办法
先删除node_moudle
package.json
增加:
"agora_electron": {
"electron_version": "7.1.2",
"prebuilt": true,
"platform": "win32"
},
安装32位的electron
代码语言:javascript复制npm install -save-dev electron@7.1.2 --arch=ia32
安装SDK
代码语言:javascript复制npm install agora-electron-sdk --save
查看Electron所有版本
https://npm.taobao.org/mirrors/electron/
推送摄像头
代码语言:javascript复制// Code that will run only after the
// entire view has been rendered
if(global.rtcEngine) {
global.rtcEngine.release()
global.rtcEngine = null
}
if(!APPID) {
alert('Please provide APPID in App.vue')
return
}
const consoleContainer = document.querySelector('#console')
let rtcEngine = new AgoraRtcEngine()
rtcEngine.initialize(APPID)
// listen to events
rtcEngine.on('joinedChannel', (channel, uid, elapsed) => {
consoleContainer.innerHTML = `join channel success ${channel} ${uid} ${elapsed}`
let localVideoContainer = document.querySelector('#local')
//setup render area for local user
rtcEngine.setupLocalVideo(localVideoContainer)
})
rtcEngine.on('error', (err, msg) => {
consoleContainer.innerHTML = `error: code ${err} - ${msg}`
})
rtcEngine.on('userJoined', (uid) => {
//setup render area for joined user
let remoteVideoContainer = document.querySelector('#remote')
rtcEngine.setupViewContentMode(uid, 1);
rtcEngine.subscribe(uid, remoteVideoContainer)
})
// set channel profile, 0: video call, 1: live broadcasting
rtcEngine.setChannelProfile(1)
rtcEngine.setClientRole(1)
// enable video, call disableVideo() is you don't need video at all
rtcEngine.enableVideo()
const logpath = path.join(os.homedir(), 'agorasdk.log')
// set where log file should be put for problem diagnostic
rtcEngine.setLogFile(logpath)
// join channel to rock!
rtcEngine.joinChannel(null, "demoChannel", null, Math.floor(new Date().getTime() / 1000))
global.rtcEngine = rtcEngine
共享窗口
代码语言:javascript复制const AgoraRtcEngine = require('agora-electron-sdk').default
const os = require('os')
const path = require('path')
const consoleContainer = document.getElementById('agora-vs-screen-share-window-console')
const sdkLogPath = path.resolve(os.homedir(), "./agoramainsdk.log")
const localVideoContainer = document.getElementById('vs-screen-share-window-local-video')
const localScreenContainer = document.getElementById('vs-screen-share-window-local-screen')
const remoteVideoContainer = document.getElementById('vs-screen-share-window-remote-video')
const APPID = global.AGORA_APPID || ""
const channel = "demoChannel"
if(!APPID) {
alert(`AGORA_APPID not found in environment variables`)
return
}
if(global.rtcEngine) {
// if rtc engine exists already, you must call release to free it first
global.rtcEngine.release()
}
let rtcEngine = new AgoraRtcEngine()
rtcEngine.initialize(APPID)
// listen to events
rtcEngine.on('joinedChannel', (channel, uid, elapsed) => {
consoleContainer.innerHTML = `joined channel ${channel} with uid ${uid}, elapsed ${elapsed}ms`
//setup render area for local user
rtcEngine.setupLocalVideo(localVideoContainer)
//find a display
let windows = rtcEngine.getScreenWindowsInfo()
if(windows.length === 0) {
return alert('no window found')
}
//start video source
rtcEngine.videoSourceInitialize(APPID)
rtcEngine.videoSourceSetChannelProfile(1);
rtcEngine.videoSourceJoin(null, channel, "", 1)
rtcEngine.on('videosourcejoinedsuccess', () => {
// start screenshare
rtcEngine.videoSourceSetVideoProfile(43, false);
rtcEngine.videoSourceStartScreenCaptureByWindow(windows[0].windowId, {
x: 0, y: 0, width: 0, height: 0
}, {
width: 0,
height: 0,
bitrate: 0,
frameRate: 5,
captureMouseCursor: true,
windowFocus: false,
})
//setup dom where to display screenshare preview
rtcEngine.setupLocalVideoSource(localScreenContainer)
rtcEngine.startScreenCapturePreview()
})
})
rtcEngine.on('error', (err, msg) => {
consoleContainer.innerHTML = `error: code ${err} - ${msg}`
})
rtcEngine.on('userJoined', (uid) => {
//setup render area for joined user
rtcEngine.setupViewContentMode(uid, 1);
rtcEngine.subscribe(uid, remoteVideoContainer)
})
// set channel profile, 0: video call, 1: live broadcasting
rtcEngine.setChannelProfile(1)
rtcEngine.setClientRole(1)
// enable video, call disableVideo() is you don't need video at all
rtcEngine.enableVideo()
//不开启本地摄像头
rtcEngine.enableLocalVideo(false)
//不共享本地摄像头
rtcEngine.muteLocalVideoStream(true)
// set where log file should be put for problem diagnostic
rtcEngine.setLogFile(sdkLogPath)
// join channel to rock!
rtcEngine.joinChannel(null, channel, null, Math.floor(new Date().getTime() / 1000))
global.rtcEngine = rtcEngine
共享屏幕
代码语言:javascript复制const AgoraRtcEngine = require('agora-electron-sdk').default
const os = require('os')
const path = require('path')
const consoleContainer = document.getElementById('agora-vs-screen-share-display-console')
const sdkLogPath = path.resolve(os.homedir(), "./agoramainsdk.log")
const localVideoContainer = document.getElementById('vs-screen-share-display-local-video')
const localScreenContainer = document.getElementById('vs-screen-share-display-local-screen')
const remoteVideoContainer = document.getElementById('vs-screen-share-display-remote-video')
const APPID = global.AGORA_APPID || ""
const channel = "demoChannel"
if(!APPID) {
alert(`AGORA_APPID not found in environment variables`)
return
}
if(global.rtcEngine) {
// if rtc engine exists already, you must call release to free it first
global.rtcEngine.release()
}
let rtcEngine = new AgoraRtcEngine()
rtcEngine.initialize(APPID)
// listen to events
rtcEngine.on('joinedChannel', (channel, uid, elapsed) => {
consoleContainer.innerHTML = `joined channel ${channel} with uid ${uid}, elapsed ${elapsed}ms`
//setup render area for local user
rtcEngine.setupLocalVideo(localVideoContainer)
//find a display
let displays = rtcEngine.getScreenDisplaysInfo()
if(displays.length === 0) {
return alert('no display found')
}
//start video source
rtcEngine.videoSourceInitialize(APPID)
rtcEngine.videoSourceSetChannelProfile(1);
rtcEngine.videoSourceJoin(null, channel, "", 1)
rtcEngine.on('videosourcejoinedsuccess', () => {
// start screenshare
rtcEngine.videoSourceSetVideoProfile(43, false);
// let list = rtcEngine.getScreenWindowsInfo();
// let excludeListFull = list.map((item, index) => {
// return item.windowId
// });
// let excludeList = excludeListFull;
let excludeList = []
rtcEngine.videoSourceStartScreenCaptureByScreen(displays[0].displayId, {
x: 0, y: 0, width: 0, height: 0
}, {
width: 0, height: 0, bitrate: 500, frameRate: 5, captureMouseCursor: false, windowFocus: false, excludeWindowList: excludeList, excludeWindowCount: excludeList.length
})
//setup dom where to display screenshare preview
rtcEngine.setupLocalVideoSource(localScreenContainer)
rtcEngine.startScreenCapturePreview()
})
})
rtcEngine.on('error', (err, msg) => {
consoleContainer.innerHTML = `error: code ${err} - ${msg}`
})
rtcEngine.on('userJoined', (uid) => {
//setup render area for joined user
rtcEngine.setupViewContentMode(uid, 1);
rtcEngine.subscribe(uid, remoteVideoContainer)
})
// set channel profile, 0: video call, 1: live broadcasting
rtcEngine.setChannelProfile(1)
rtcEngine.setClientRole(1)
// enable video, call disableVideo() is you don't need video at all
rtcEngine.enableVideo()
// set where log file should be put for problem diagnostic
rtcEngine.setLogFile(sdkLogPath)
// join channel to rock!
rtcEngine.joinChannel(null, channel, null, Math.floor(new Date().getTime() / 1000))
global.rtcEngine = rtcEngine