Preserve accumulated client implementation since v0.1.4, including local identities, multi-server state, chat, administration, audio and streaming controls. Refine official-source layout, original artwork, responsive composer overflow, settings navigation and chat scroll anchoring. Current verification: Node suite passes; isolated packaged chat and responsive control smokes pass without device capture. Native core is reused, not rebuilt in this pass. Strict whole-screen visual parity remains incomplete; no 1:1 or cross-platform acceptance claim. Local checkpoint only; no release or push.
70 lines
4.7 KiB
JavaScript
70 lines
4.7 KiB
JavaScript
'use strict';
|
|
// Dedicated OFFSCREEN test main. Never used by the product or a normal profile.
|
|
const { app, BrowserWindow, ipcMain } = require('electron');
|
|
const path = require('node:path');
|
|
const { pathToFileURL } = require('node:url');
|
|
const { spawn } = require('node:child_process');
|
|
const { AppAudioController } = require('../../app/main/appaudio-main');
|
|
if (!process.env.TEAMSPEACH_APPAUDIO_SMOKE_PROFILE || !process.env.TEAMSPEACH_APPAUDIO_SMOKE_BINARY) throw new Error('Explicit disposable smoke configuration required.');
|
|
app.setPath('userData', process.env.TEAMSPEACH_APPAUDIO_SMOKE_PROFILE);
|
|
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required');
|
|
app.commandLine.appendSwitch('disable-renderer-backgrounding');
|
|
let win;
|
|
let controller;
|
|
const captures = new Set();
|
|
const diagnostic = process.env.TEAMSPEACH_APPAUDIO_PCM_DIAGNOSTIC === '1';
|
|
const counters = { nativeBytes: 0, ipcFrames: 0, ipcAcks: 0 };
|
|
const fixtureUrl = pathToFileURL(path.join(__dirname, 'appaudio-smoke.html')).href;
|
|
const ownedPids = JSON.parse(process.env.TEAMSPEACH_APPAUDIO_SMOKE_PIDS);
|
|
app.whenReady().then(async () => {
|
|
win = new BrowserWindow({ show: false, focusable: false, width: 320, height: 240, webPreferences: { offscreen: true, backgroundThrottling: false, contextIsolation: true, sandbox: true, nodeIntegration: false, preload: path.join(__dirname, 'appaudio-smoke-preload.cjs') } });
|
|
const trustedFrame = frame => frame === win.webContents.mainFrame && frame.url === fixtureUrl;
|
|
const trusted = event => event.sender === win.webContents && trustedFrame(event.senderFrame);
|
|
const send = win.webContents.send.bind(win.webContents);
|
|
win.webContents.send = (channel, packet) => { if (packet?.event === 'pcm') counters.ipcFrames++; return send(channel, packet); };
|
|
controller = new AppAudioController({ resolveBinary: () => process.env.TEAMSPEACH_APPAUDIO_SMOKE_BINARY, getWindow: () => win, trustedFrame,
|
|
spawnProcess(binary, args, options) {
|
|
const child = diagnostic
|
|
? spawn(process.execPath, [path.join(__dirname, 'appaudio-pcm-fixture.cjs'), ...args.slice(1)], { ...options, env: { ...process.env, ELECTRON_RUN_AS_NODE: '1', APPAUDIO_FIXTURE_HOST_PID: String(process.pid) } })
|
|
: spawn(binary, args, options);
|
|
child.stdout.on('data', bytes => { counters.nativeBytes += bytes.length; });
|
|
if (args[1] === 'capture') { captures.add(child.pid); child.once('close', () => captures.delete(child.pid)); }
|
|
return child;
|
|
},
|
|
});
|
|
const ack = controller.ack.bind(controller);
|
|
controller.ack = (frame, packet) => { counters.ipcAcks++; ack(frame, packet); };
|
|
controller.registerIpc(ipcMain, trusted);
|
|
ipcMain.handle('smoke:prepare', async event => {
|
|
if (!trusted(event)) throw new Error('Wrong fixture frame');
|
|
const list = await controller.list();
|
|
if (!list.ok || !list.supported) throw new Error(JSON.stringify(list));
|
|
const applications = ownedPids.map(pid => list.applications.find(item => item.pid === pid));
|
|
if (applications.some(item => !item)) throw new Error('Owned generated tone sessions not observed.');
|
|
// The explicit smoke selected source is its own generated canvas, not desktop
|
|
// pixels. Product permission and gesture handlers are deliberately unchanged.
|
|
const { appAudioSessionId } = controller.authorizeSelection(event.senderFrame, 'smoke:owned-generated-canvas');
|
|
controller.confirmSelection(event.senderFrame);
|
|
return { sessionId: appAudioSessionId, applications, scope: list.scope };
|
|
});
|
|
ipcMain.handle('smoke:state', event => {
|
|
if (!trusted(event)) throw new Error('Wrong fixture frame');
|
|
return { active: Boolean(controller.active), captureChildren: captures.size, visible: win.isVisible(), offscreen: win.webContents.isOffscreen(), diagnostic, counters: { ...counters }, inFlight: controller.active?.inFlight.size || 0 };
|
|
});
|
|
ipcMain.handle('smoke:result', (event, result) => {
|
|
if (!trusted(event)) throw new Error('Wrong fixture frame');
|
|
controller.stopAll();
|
|
process.stdout.write(`APPAUDIO_RESULT ${JSON.stringify(result)}\n`);
|
|
setTimeout(() => app.quit(), 300);
|
|
});
|
|
win.webContents.on('render-process-gone', (_event, detail) => { process.stderr.write(JSON.stringify(detail)); app.exit(1); });
|
|
await win.loadURL(fixtureUrl);
|
|
}).catch(cause => { process.stderr.write(cause.stack); app.exit(1); });
|
|
app.on('before-quit', () => controller?.stopAll());
|
|
// Windows GUI Electron does not expose a reliable stdin pipe. A private file in
|
|
// the disposable profile requests graceful shutdown without touching a window.
|
|
const shutdownTimer = setInterval(() => {
|
|
if (require('node:fs').existsSync(path.join(app.getPath('userData'), 'stop-request'))) app.quit();
|
|
}, 100);
|
|
shutdownTimer.unref();
|