Files
client/scripts/smoke-voice.mjs
T
omar 3d623329b3
ci / linux-x64 (push) Failing after 33s
ci / linux-arm64-cross (push) Successful in 3m8s
Transmit mode: only the latest set_transmit answer counts; forwarding terminology; 0.1.4
An older answer (same settings or a restarted core) could re-enable forwarding while a newer mode
change was pending. Requests and core restarts now start a new epoch. Renderer stats count frames
forwarded to the core. v0.1.3 was tagged but never released.
2026-10-24 09:45:49 +03:00

203 lines
11 KiB
JavaScript

// Two real TeamsPeach instances (separate disposable profiles) on a live server:
// A transmits Chromium's synthetic microphone (open mic, then push-to-talk), B must receive
// talking events and decoded audio frames from the core; plus channel and private chat both ways.
//
// node scripts/smoke-voice.mjs --server 10.10.10.160:9987 --out docs/evidence/runtime/<name>
//
// The synthetic microphone (--use-fake-device-for-media-stream) replaces only the capture device;
// everything after getUserMedia (worklet, IPC, core Opus, server, decode, mix, playback) is the real path.
import { launchApp } from './lib/electron-app.mjs';
import { mkdirSync, writeFileSync, mkdtempSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const argv = process.argv.slice(2);
const opt = (name, fallback) => {
const i = argv.indexOf(`--${name}`);
return i >= 0 ? argv[i + 1] : fallback;
};
const server = opt('server');
if (!server) {
console.error('--server is required');
process.exit(2);
}
const out = path.resolve(root, opt('out', 'smoke-voice-out'));
mkdirSync(out, { recursive: true });
const result = { startedAt: new Date().toISOString(), server, steps: [], console: [] };
const step = (name, data = {}) => {
result.steps.push({ name, at: new Date().toISOString(), ...data });
console.log(`[voice] ${name}`, JSON.stringify(data));
};
async function launch(label, nickname) {
const profile = mkdtempSync(path.join(tmpdir(), `teamspeach-${label}-`));
const app = await launchApp({ profile, args: ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] });
const page = await app.firstWindow();
page.on('console', (m) => result.console.push(`${label} ${m.type()}: ${m.text()}`));
page.on('pageerror', (e) => result.console.push(`${label} pageerror: ${e.message}`));
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 });
await page.fill('#onboarding-nick', nickname);
await page.click('#onboarding-submit');
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
return { app, page, profile };
}
const diag = (page) => page.evaluate(() => window.teamspeachDiagnostics.snapshot());
const waitDiag = (page, fn, arg, timeout = 20000) => page.waitForFunction(fn, arg, { timeout });
async function setRange(page, selector, value) {
await page.$eval(selector, (el, v) => {
el.value = String(v);
el.dispatchEvent(new Event('input', { bubbles: true }));
el.dispatchEvent(new Event('change', { bubbles: true }));
}, value);
}
/** Transmit mode lives in Settings → Audio. */
async function setTransmit(page, mode) {
await page.click('#btn-settings');
await page.click('#settings-nav .nav-item[data-panel="audio"]');
await page.check('input[name="transmit"][value="' + mode + '"]');
await page.click('#settings-back');
}
async function connect(page) {
await page.fill('#connect-address', server);
await page.click('#connect-submit');
await waitDiag(page, () => window.teamspeachDiagnostics.snapshot().conn === 'connected', null, 60000);
}
let a;
let b;
let failed = null;
try {
a = await launch('A', 'PeachVoiceA');
b = await launch('B', 'PeachVoiceB');
step('profiles created', { a: (await diag(a.page)).profile, b: (await diag(b.page)).profile });
// B listens at zero playback gain so the test does not play tones on the speakers; frames still flow.
await b.page.click('#btn-settings');
await b.page.click('#settings-nav .nav-item[data-panel="audio"]');
await setRange(b.page, '#voice-volume', 0);
await b.page.click('#settings-back');
// Both connect in push-to-talk mode (nothing is sent until a key is held).
await connect(b.page);
await connect(a.page);
await a.page.waitForTimeout(1500);
const da = await diag(a.page);
const db = await diag(b.page);
step('both connected', { aClid: da.ownClientId, aChannel: da.ownChannel, bClid: db.ownClientId, bChannel: db.ownChannel });
if (da.ownChannel !== db.ownChannel) throw new Error('clients landed in different channels');
const ownCid = (s) => s.clients.find((c) => c.id === s.ownClientId)?.channel;
const others = db.clients.filter((c) => c.type !== 'query' && c.channel === ownCid(db) && c.id !== da.ownClientId && c.id !== db.ownClientId);
if (others.length > 0) throw new Error(`refusing to transmit test tones: channel occupied by ${others.map((c) => c.nickname).join(', ')}`);
// A: open microphone.
await setTransmit(a.page, 'open');
// Open mic: B must see A talking and receive audio frames.
await waitDiag(b.page, (clid) => window.teamspeachDiagnostics.snapshot().talking.includes(clid), da.ownClientId, 20000);
await b.page.waitForTimeout(3000);
let sa = await diag(a.page);
let sb = await diag(b.page);
const playback = await b.page.evaluate(() => window.teamspeachDiagnostics.playback());
step('open mic received', { aFramesForwarded: sa.voice.framesForwarded, aTransmitting: sa.audio.transmitting, bTalking: sb.talking, bFramesPlayed: sb.voice.framesPlayed, bPlayback: playback });
if (sb.voice.framesPlayed < 50) throw new Error('B received too few audio frames');
await b.page.screenshot({ path: path.join(out, '10-b-sees-a-talking.png') });
await a.page.screenshot({ path: path.join(out, '11-a-open-mic.png') });
// Mute A: talking must stop on B and the mute flag must be visible.
await a.page.click('#btn-mute');
await waitDiag(b.page, (clid) => !window.teamspeachDiagnostics.snapshot().talking.includes(clid), da.ownClientId, 10000);
await b.page.waitForTimeout(800);
step('A muted, talking stopped on B');
await b.page.screenshot({ path: path.join(out, '12-b-sees-a-muted.png') });
await a.page.click('#btn-mute');
// Push-to-talk: switch A to PTT (default key F8), hold the key, release.
await setTransmit(a.page, 'ptt');
await a.page.waitForTimeout(1500);
sb = await diag(b.page);
step('PTT idle', { bTalkingIncludesA: sb.talking.includes(da.ownClientId) });
const before = (await diag(b.page)).voice.framesPlayed;
await a.page.keyboard.down('F8');
await waitDiag(b.page, (clid) => window.teamspeachDiagnostics.snapshot().talking.includes(clid), da.ownClientId, 10000);
await a.page.waitForTimeout(1500);
await a.page.screenshot({ path: path.join(out, '13-a-ptt-held.png') });
await a.page.keyboard.up('F8');
await waitDiag(b.page, (clid) => !window.teamspeachDiagnostics.snapshot().talking.includes(clid), da.ownClientId, 10000);
step('PTT burst received', { bFramesDuringBurst: (await diag(b.page)).voice.framesPlayed - before });
// Reverse direction: B talks to A.
await setTransmit(b.page, 'open');
await waitDiag(a.page, (clid) => window.teamspeachDiagnostics.snapshot().talking.includes(clid), db.ownClientId, 20000);
await a.page.waitForTimeout(2000);
sa = await diag(a.page);
step('reverse direction received', { aFramesPlayed: sa.voice.framesPlayed, aTalking: sa.talking });
// Deafen B while both have open mics: B must stop receiving (RX) and stop sending (TX); undeafen resumes both.
await setTransmit(a.page, 'open');
await waitDiag(b.page, (clid) => window.teamspeachDiagnostics.snapshot().talking.includes(clid), da.ownClientId, 10000);
await b.page.click('#btn-deafen');
await waitDiag(b.page, () => window.teamspeachDiagnostics.snapshot().audio.output_muted === true, null, 10000);
await waitDiag(a.page, (clid) => !window.teamspeachDiagnostics.snapshot().talking.includes(clid), db.ownClientId, 10000);
await b.page.waitForTimeout(1000);
const rx0 = (await diag(b.page)).voice.framesPlayed;
const txA0 = (await diag(a.page)).voice.framesPlayed;
await b.page.waitForTimeout(2500);
const deaf = { bRxDelta: (await diag(b.page)).voice.framesPlayed - rx0, aRxFromBDelta: (await diag(a.page)).voice.framesPlayed - txA0, aSeesBTalking: (await diag(a.page)).talking.includes(db.ownClientId) };
await b.page.screenshot({ path: path.join(out, '17-b-deafened.png') });
step('B deafened', deaf);
if (deaf.bRxDelta !== 0 || deaf.aRxFromBDelta !== 0 || deaf.aSeesBTalking) throw new Error('deafen did not stop RX/TX');
await b.page.click('#btn-deafen');
await waitDiag(a.page, (clid) => window.teamspeachDiagnostics.snapshot().talking.includes(clid), db.ownClientId, 10000);
const rx1 = (await diag(b.page)).voice.framesPlayed;
await b.page.waitForTimeout(2000);
step('B undeafened', { bRxDelta: (await diag(b.page)).voice.framesPlayed - rx1, aSeesBTalking: (await diag(a.page)).talking.includes(db.ownClientId) });
for (const p of [a.page, b.page]) {
await setTransmit(p, 'ptt');
}
// Chat: channel message A → B (the server may deny guests channel text: that error must be shown),
// private message B → A.
await a.page.fill('#chat-input', 'TeamsPeach smoke: channel message');
await a.page.press('#chat-input', 'Enter');
const channelOutcome = await Promise.race([
b.page.waitForSelector('text=TeamsPeach smoke: channel message', { timeout: 10000 }).then(() => ({ delivered: true })),
a.page.waitForSelector('.toast[data-kind="error"]', { timeout: 10000 }).then(async (el) => ({ delivered: false, error: await el.textContent() })),
]);
step('channel chat', channelOutcome);
await a.page.screenshot({ path: path.join(out, '14-a-channel-chat-result.png') });
await b.page.click(`#tree [data-key="u:${da.ownClientId}"] .row-btn`);
await b.page.fill('#chat-input', 'TeamsPeach smoke: private message');
await b.page.press('#chat-input', 'Enter');
await a.page.waitForSelector('#chat-tabs .chat-tab:has-text("PeachVoiceB")', { timeout: 10000 });
await a.page.click('#chat-tabs .chat-tab:has-text("PeachVoiceB")');
await a.page.waitForSelector('text=TeamsPeach smoke: private message', { timeout: 10000 });
step('private chat delivered');
await a.page.screenshot({ path: path.join(out, '15-a-private-chat.png') });
await b.page.screenshot({ path: path.join(out, '16-b-private-chat.png') });
} catch (err) {
failed = err;
step('FAILED', { error: String(err.stack || err) });
if (a) await a.page.screenshot({ path: path.join(out, 'fail-a.png') }).catch(() => {});
if (b) await b.page.screenshot({ path: path.join(out, 'fail-b.png') }).catch(() => {});
} finally {
for (const inst of [a, b]) {
if (!inst) continue;
await inst.page.click('#btn-disconnect').catch(() => {});
await inst.page.waitForTimeout(500);
await inst.app.close().catch(() => {});
}
}
result.finishedAt = new Date().toISOString();
result.ok = !failed;
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
console.log(`[voice] ${result.ok ? 'OK' : 'FAILED'} → ${out}`);
process.exit(result.ok ? 0 : 1);