Files
client/scripts/smoke-appaudio.mjs
T
omar e6464bc4ed feat: checkpoint account-free client workflows and source-matched UI
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.
2026-11-01 19:43:18 +03:00

93 lines
5.8 KiB
JavaScript

// Real native selected-app audio -> production renderer mixer -> local WebRTC.
// Always hidden/offscreen, disposable profile, own generated quiet tones only.
import { spawn } from 'node:child_process';
import { createRequire } from 'node:module';
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const require = createRequire(import.meta.url);
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const args = process.argv.slice(2);
const option = name => args.includes(`--${name}`) ? args[args.indexOf(`--${name}`) + 1] : undefined;
const diagnostic = args.includes('--synthetic-pcm');
const isolatedDevice = process.env.TEAMSPEACH_TEST_ISOLATED_WAVEOUT_DEVICE_ID;
const out = path.resolve(option('out') || path.join(root, 'smoke-out', 'appaudio'));
const binary = path.resolve(option('core') || path.join(root, 'core', 'target', 'debug', 'teamspeach-core.exe'));
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-appaudio-offscreen-'));
mkdirSync(out, { recursive: true });
const tones = [];
let electron;
let result;
let stderr = '';
async function tone(frequency) {
const child = spawn('powershell.exe', ['-NoProfile', '-NonInteractive', '-WindowStyle', 'Hidden', '-ExecutionPolicy', 'Bypass', '-File', path.join(root, 'scripts', 'lib', 'app-audio-tone.ps1'), '-Frequency', String(frequency), '-DeviceId', isolatedDevice, '-IsolatedEndpointConfirmed'], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'] });
tones.push(child);
child.stdin.on('error', () => {});
child.stderr.on('data', bytes => { stderr = (stderr + bytes.toString()).slice(-32768); });
return new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error('Owned generated audio fixture did not become ready.')), 15000);
let pending = '';
child.stdout.on('data', bytes => {
pending += bytes.toString();
const newline = pending.indexOf('\n');
if (newline < 0) return;
try {
const info = JSON.parse(pending.slice(0, newline));
if (!info.ready || info.pid !== child.pid || info.frequency !== frequency) throw new Error('Unexpected owned tone identity.');
clearTimeout(timer); resolve(info);
} catch (cause) { clearTimeout(timer); reject(cause); }
});
child.once('error', cause => { clearTimeout(timer); reject(cause); });
child.once('exit', code => { clearTimeout(timer); reject(new Error(`Owned tone fixture exited ${code}.`)); });
});
}
async function stop(child) {
if (!child || child.exitCode !== null) return;
if (child === electron) writeFileSync(path.join(profile, 'stop-request'), 'stop');
await new Promise(resolve => {
const timer = setTimeout(() => { child.kill(); }, 1000);
const deadline = setTimeout(resolve, 4000);
child.once('close', () => { clearTimeout(timer); clearTimeout(deadline); resolve(); });
child.stdin?.end();
});
}
try {
if (!diagnostic && (process.env.TEAMSPEACH_TEST_ISOLATED_AUDIO_CONFIRMED !== '1' || !/^\d+$/.test(isolatedDevice || '') || Number(isolatedDevice) > 65535)) throw new Error('Real native audio proof requires an explicitly confirmed isolated nonphysical output endpoint. Default-output tones are forbidden. Use --synthetic-pcm only for labelled transport diagnostics, not native proof.');
if (!diagnostic && process.platform !== 'win32') throw new Error('This generated waveOut fixture is Windows-only; it does not claim Linux/macOS runtime proof.');
const generated = diagnostic ? [{ pid: 44044, frequency: 440, synthetic: true }, { pid: 44045, frequency: 997, synthetic: true }] : await Promise.all([tone(440), tone(997)]);
const env = { ...process.env, TEAMSPEACH_APPAUDIO_PCM_DIAGNOSTIC: diagnostic ? '1' : '0', TEAMSPEACH_APPAUDIO_SMOKE_PROFILE: profile, TEAMSPEACH_APPAUDIO_SMOKE_BINARY: binary, TEAMSPEACH_APPAUDIO_SMOKE_PIDS: JSON.stringify(generated.map(item => item.pid)) };
delete env.ELECTRON_RUN_AS_NODE;
electron = spawn(require('electron'), [path.join(root, 'scripts', 'lib', 'appaudio-smoke-main.cjs')], { windowsHide: true, stdio: ['pipe', 'pipe', 'pipe'], env });
electron.stdin.on('error', () => {});
electron.stderr.on('data', bytes => { stderr = (stderr + bytes.toString()).slice(-32768); });
result = await new Promise((resolve, reject) => {
const timer = setTimeout(() => reject(new Error('Offscreen real audio/WebRTC proof timed out.')), 45000);
let pending = '';
let received;
electron.stdout.on('data', bytes => {
pending += bytes.toString();
let newline;
while ((newline = pending.indexOf('\n')) >= 0) {
const line = pending.slice(0, newline); pending = pending.slice(newline + 1);
if (line.startsWith('APPAUDIO_RESULT ')) {
try { received = JSON.parse(line.slice('APPAUDIO_RESULT '.length)); } catch (cause) { clearTimeout(timer); reject(cause); }
}
}
if (pending.length > 262144) { clearTimeout(timer); reject(new Error('Unexpected smoke host output size.')); }
});
electron.once('error', cause => { clearTimeout(timer); reject(cause); });
electron.once('close', code => { clearTimeout(timer); received ? resolve({ ...received, electronExitCode: code, generated }) : reject(new Error(`Offscreen smoke host exited ${code} without evidence.`)); });
});
} catch (cause) { result = { ok: false, error: cause.stack || String(cause) }; }
finally {
await stop(electron);
await Promise.all(tones.map(stop));
result.stderr = stderr;
result.safety = { offscreenOnly: true, windowsHidden: true, profileRemoved: true, generatedSourcesOnly: true, privateCapture: false, serverConnection: false };
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
rmSync(profile, { recursive: true, force: true });
}
console.log(JSON.stringify(result, null, 2));
process.exitCode = result.ok ? 0 : 1;