Nis*_*Jha 5 javascript node.js electron
我正在尝试根据 fireship - https://youtu.be/3yqDxhR2XxE的这段视频使用 Electron js 制作一个视频录制应用程序,并且我一直在构建可用视频源的选择菜单,因为事实证明该"remote"模块已被弃用。我有 2 个 js 文件,一个是index.js主要的电子 js 文件,另一个是render.js文件(我在其中为我的应用程序构建函数)。我尝试"remote"在文件中导入模块index.js,但这不起作用。我什至设置了enableRemoteModule: true,webPreferences但这index.js 也不起作用。现在我作为一个新手完全没有想法了。我听说过
ipcRenderer和ipcMain模块,但不确定它们是否会起作用。
下面是我的“app.js”的代码:
//Buttons
const videoElement = document.querySelector('Video');
const startBtn = document.getElementById('startBtn');
const stopBtn = document.getElementById('stopBtn');
const videoSelectBtn = document.getElementById('videoSelectBtn');
videoSelectBtn.onclick = getVideoSources;
const {
desktopCapturer
} = require("electron");
const {
remote
} = require('@electron/remote')
const {
Menu
} = remote
//Getting all available Video Sources
async function getVideoSources() {
const inputSources = await desktopCapturer.getSources({
types: ['window', 'screen']
});
const videoOptionsMenu = Menu.buildFromTemplate(
inputSources.map(source => {
return {
label: source.name,
click: () => selectSource(source)
};
})
);
videoOptionsMenu.popup();
}Run Code Online (Sandbox Code Playgroud)