@applooma/rtc-electron
v0.1.2
Published
AppLooma RTC for Electron — real-time voice, video and screen sharing in desktop apps for Windows, macOS and Linux
Maintainers
Readme
@applooma/rtc-electron
AppLooma RTC for Electron desktop apps on Windows, macOS and Linux. The renderer runs the Web SDK unchanged; this package adds what Electron needs around it: permission handling and a screen/window picker for screen sharing, wired through the main process and a preload bridge.
Install
npm install @applooma/rtc-electronElectron 30 or newer is a peer dependency. Nothing native is built.
Quick start
main.js
const { app, BrowserWindow } = require('electron');
const path = require('node:path');
const { setupAppMain } = require('@applooma/rtc-electron/main');
app.whenReady().then(() => {
setupAppMain(); // camera, microphone, screen capture and the picker IPC
new BrowserWindow({
width: 1200,
height: 800,
webPreferences: { preload: path.join(__dirname, 'preload.js'), contextIsolation: true },
}).loadFile('index.html');
});preload.js
require('@applooma/rtc-electron/preload').exposeAppBridge(); // window.apploomaWith sandbox: true (the default for new windows) a preload cannot require packages; bundle the preload script (Vite, webpack, electron-forge) or set sandbox: false for that window.
renderer.js
import AppEngine, { listScreenSources, shareScreen, stopScreenShare } from '@applooma/rtc-electron';
const engine = AppEngine.create({ appId: 'YOUR_APP_ID' });
engine.on('track-subscribed', (track) => document.querySelector('#grid').appendChild(track.attach()));
const { token, wsUrl } = await fetch('https://your.backend/api/rtc-token').then((r) => r.json());
await engine.joinChannel(token, wsUrl, { role: 'host', camera: true, microphone: true });
engine.attachLocalVideo(document.querySelector('#me'));
// Screen share with your own picker
const sources = await listScreenSources({ types: ['screen', 'window'] });
// render sources[i].thumbnail / .name, let the user choose, then:
await shareScreen(engine, sources[0].id, { withAudio: true });
// later
await stopScreenShare(engine);API
@applooma/rtc-electron (renderer): everything from the Web SDK, plus listScreenSources(options?), shareScreen(engine, sourceId, { withAudio?, bridgeKey? }), stopScreenShare(engine), getAppBridge(key?).
@applooma/rtc-electron/main: setupAppMain(options?) returns a function that undoes it. Options: session, permissions (default ['media', 'display-capture']), allowOrigin(origin), askMacMediaAccess (default true), pickSource(sources) for shares started without a renderer choice (default: the first screen), loopbackAudio (default true).
@applooma/rtc-electron/preload: exposeAppBridge(key = 'applooma'), createAppBridge().
Notes
- Keep
contextIsolation: trueandnodeIntegration: false. The SDK needs nothing from Node in the renderer. - System audio with a screen share works on Windows. On macOS it needs a virtual audio device, so the share is video only.
- Use
powerSaveBlocker.start('prevent-app-suspension')during a call so the machine does not sleep. - Mint tokens on your backend. The API secret never ships inside the app.
Remote diagnostics
The engine is the Web SDK engine, so remote diagnostics work with no extra setup (Web SDK 0.4.6 or later): recent log lines and stats, never audio, video, messages or names, are uploaded scrubbed after a call with a problem or when support turns collection on. Call engine.uploadDiagnostics(reason) to send them yourself; opt out with remoteDiagnostics: false in the engine config.
Docs: https://applooma.dev/sdk/electron
