feat: Implement an Electron-based broadcasting client with screen/window and audio source selection, including Pipewire integration, and add auto-unmute to the viewer.
This commit is contained in:
83
client/main.js
Normal file
83
client/main.js
Normal file
@@ -0,0 +1,83 @@
|
||||
const { app, BrowserWindow, desktopCapturer, ipcMain } = require('electron');
|
||||
const path = require('path');
|
||||
const PipewireHelper = require('./pipewire');
|
||||
|
||||
// Ensure Chromium tries to use PipeWire for screen sharing on Linux
|
||||
app.commandLine.appendSwitch('enable-features', 'WebRTCPipeWireCapturer');
|
||||
|
||||
function createWindow() {
|
||||
const win = new BrowserWindow({
|
||||
width: 1000,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
preload: path.join(__dirname, 'preload.js'),
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
}
|
||||
});
|
||||
|
||||
win.loadFile('index.html');
|
||||
}
|
||||
|
||||
app.whenReady().then(async () => {
|
||||
// Setup the virtual microphone as soon as the app starts
|
||||
await PipewireHelper.createVirtualMic();
|
||||
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.on('will-quit', async () => {
|
||||
await PipewireHelper.destroyVirtualMic();
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
|
||||
// Handle IPC request from renderer to get screen/audio sources
|
||||
ipcMain.handle('get-sources', async () => {
|
||||
const inputSources = await desktopCapturer.getSources({
|
||||
types: ['window', 'screen'],
|
||||
fetchWindowIcons: true
|
||||
});
|
||||
|
||||
return inputSources.map(source => ({
|
||||
id: source.id,
|
||||
name: source.name,
|
||||
thumbnail: source.thumbnail.toDataURL()
|
||||
}));
|
||||
});
|
||||
|
||||
// Handle Pipewire specific audio isolation requests
|
||||
ipcMain.handle('get-audio-apps', async () => {
|
||||
return await PipewireHelper.getAudioApplications();
|
||||
});
|
||||
|
||||
ipcMain.handle('link-app-audio', async (event, appName) => {
|
||||
return await PipewireHelper.linkApplicationToMic(appName);
|
||||
});
|
||||
|
||||
// Handle saving and loading the config.json profile
|
||||
const fs = require('fs');
|
||||
const configPath = path.join(__dirname, 'config.json');
|
||||
|
||||
ipcMain.handle('get-config', () => {
|
||||
try {
|
||||
if (fs.existsSync(configPath)) {
|
||||
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
||||
}
|
||||
} catch (e) { console.error("Could not read config", e); }
|
||||
return { serverUrl: 'http://localhost:3000', serverPassword: '' };
|
||||
});
|
||||
|
||||
ipcMain.handle('save-config', (event, newConfig) => {
|
||||
fs.writeFileSync(configPath, JSON.stringify(newConfig, null, 2), 'utf8');
|
||||
});
|
||||
Reference in New Issue
Block a user