Audio devices: fix permission origin (app://teamspeach/), real device lists, right-click device menus, voice TX diagnostics; version 0.1.2
This commit is contained in:
1 parent
8153e9b88b
commit
a3185229ee
25 files changed
+767
-50
No files matched your search
@@ -0,0 +1,116 @@
|
||||
// Real-device context menus (NO fake-media flags, no server, no capture): right-click and Shift+F10 on the
|
||||
// footer microphone/headphones buttons open the device menu without toggling mute/deafen; choosing an
|
||||
// entry updates Settings and persists; Escape restores focus.
|
||||
// node scripts/smoke-devices-menu.mjs --out docs/evidence/runtime/<name> [--exe packaged.exe]
|
||||
import { _electron as electron } from 'playwright-core';
|
||||
import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const electronPath = createRequire(import.meta.url)('electron');
|
||||
const argv = process.argv.slice(2);
|
||||
const opt = (n, d) => (argv.indexOf(`--${n}`) >= 0 ? argv[argv.indexOf(`--${n}`) + 1] : d);
|
||||
const out = path.resolve(root, opt('out', 'smoke-out'));
|
||||
const exe = opt('exe');
|
||||
mkdirSync(out, { recursive: true });
|
||||
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-menu-'));
|
||||
const result = { steps: [], console: [] };
|
||||
const step = (name, data = {}) => {
|
||||
result.steps.push({ name, ...data });
|
||||
console.log(`[menu] ${name}`, JSON.stringify(data));
|
||||
};
|
||||
|
||||
async function launch(label) {
|
||||
const app = await electron.launch({ executablePath: exe ? path.resolve(exe) : electronPath, args: exe ? [] : [root], env: { ...process.env, TEAMSPEACH_PROFILE_DIR: profile }, colorScheme: null });
|
||||
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.setViewportSize({ width: 1280, height: 800 }).catch(() => {});
|
||||
return { app, page };
|
||||
}
|
||||
const state = (page) => page.evaluate(() => ({
|
||||
audio: window.teamspeachDiagnostics.snapshot().audio,
|
||||
menu: Boolean(document.querySelector('.device-menu')),
|
||||
items: Array.from(document.querySelectorAll('.device-menu [role="menuitemradio"]')).map((i) => ({ label: i.textContent, checked: i.getAttribute('aria-checked') })),
|
||||
focused: document.activeElement?.id || document.activeElement?.className || '',
|
||||
inside: (() => { const m = document.querySelector('.device-menu'); if (!m) return null; const r = m.getBoundingClientRect(); return r.left >= 0 && r.top >= 0 && r.right <= innerWidth && r.bottom <= innerHeight; })(),
|
||||
}));
|
||||
|
||||
let app;
|
||||
let page;
|
||||
let failed = null;
|
||||
try {
|
||||
({ app, page } = await launch('run1'));
|
||||
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 });
|
||||
await page.fill('#onboarding-nick', 'MenuSmoke');
|
||||
await page.click('#onboarding-submit');
|
||||
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
|
||||
|
||||
await page.click('#btn-mute', { button: 'right' });
|
||||
await page.waitForSelector('.device-menu');
|
||||
let s = await state(page);
|
||||
step('mic right-click', { menu: s.menu, inputMuted: s.audio.input_muted, items: s.items, insideViewport: s.inside, focused: s.focused });
|
||||
if (s.audio.input_muted) throw new Error('right-click toggled mute');
|
||||
await page.screenshot({ path: path.join(out, '62-mic-device-menu.png') });
|
||||
const pick = s.items[Math.min(2, s.items.length - 1)].label;
|
||||
await page.click(`.device-menu [role="menuitemradio"]:has-text("${pick.replace(/"/g, '\\"')}")`);
|
||||
await page.waitForTimeout(700);
|
||||
await page.click('#btn-settings');
|
||||
await page.click('#settings-nav .nav-item[data-panel="audio"]');
|
||||
const settingsInput = await page.$eval('#input-device', (el) => el.selectedOptions[0].textContent);
|
||||
step('menu choice reflected in settings', { pick, settingsInput, same: pick === settingsInput });
|
||||
if (pick !== settingsInput) throw new Error('settings not updated from menu');
|
||||
await page.click('#settings-back');
|
||||
|
||||
// Keyboard: Shift+F10 on the headphones button, arrows, Escape restores focus; deafen untouched.
|
||||
await page.focus('#btn-deafen');
|
||||
await page.keyboard.press('Shift+F10');
|
||||
await page.waitForSelector('.device-menu');
|
||||
await page.keyboard.press('ArrowDown');
|
||||
s = await state(page);
|
||||
step('headphones Shift+F10', { menu: s.menu, outputMuted: s.audio.output_muted, items: s.items.map((i) => i.label), insideViewport: s.inside });
|
||||
await page.screenshot({ path: path.join(out, '63-output-device-menu.png') });
|
||||
await page.keyboard.press('Escape');
|
||||
s = await state(page);
|
||||
step('escape', { menuClosed: !s.menu, focusRestored: s.focused === 'btn-deafen', outputMuted: s.audio.output_muted });
|
||||
if (s.menu || s.focused !== 'btn-deafen' || s.audio.output_muted) throw new Error('escape/focus/deafen behaviour wrong');
|
||||
await page.click('#btn-deafen', { button: 'right' });
|
||||
await page.waitForSelector('.device-menu');
|
||||
const outPick = (await state(page)).items[Math.min(2, (await state(page)).items.length - 1)].label;
|
||||
await page.keyboard.press('Escape');
|
||||
await page.click('#btn-deafen', { button: 'right' });
|
||||
await page.click(`.device-menu [role="menuitemradio"]:has-text("${outPick.replace(/"/g, '\\"')}")`);
|
||||
await page.waitForTimeout(700);
|
||||
// Left click still toggles as before.
|
||||
await page.click('#btn-mute');
|
||||
s = await state(page);
|
||||
step('left click still toggles mute', { inputMuted: s.audio.input_muted });
|
||||
await page.click('#btn-mute');
|
||||
await app.close();
|
||||
|
||||
({ app, page } = await launch('run2'));
|
||||
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
|
||||
await page.click('#btn-mute', { button: 'right' });
|
||||
await page.waitForSelector('.device-menu');
|
||||
const checkedIn = (await state(page)).items.find((i) => i.checked === 'true')?.label;
|
||||
await page.keyboard.press('Escape');
|
||||
await page.click('#btn-deafen', { button: 'right' });
|
||||
await page.waitForSelector('.device-menu');
|
||||
const checkedOut = (await state(page)).items.find((i) => i.checked === 'true')?.label;
|
||||
step('after restart', { checkedIn, checkedOut, persisted: checkedIn === pick && checkedOut === outPick });
|
||||
if (checkedIn !== pick || checkedOut !== outPick) throw new Error('menu choices not persisted');
|
||||
} catch (err) {
|
||||
failed = err;
|
||||
step('FAILED', { error: String(err.stack || err) });
|
||||
if (page) await page.screenshot({ path: path.join(out, 'fail.png') }).catch(() => {});
|
||||
} finally {
|
||||
if (app) await app.close().catch(() => {});
|
||||
rmSync(profile, { recursive: true, force: true });
|
||||
}
|
||||
result.ok = !failed;
|
||||
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
|
||||
console.log(`[menu] ${result.ok ? 'OK' : 'FAILED'} → ${out}`);
|
||||
process.exit(result.ok ? 0 : 1);
|
||||
@@ -0,0 +1,105 @@
|
||||
// Real audio devices in Settings → Звук (NO fake-media flags): lists what the engine exposes without any
|
||||
// capture, selects a non-default microphone and output, restarts and checks the choice persisted.
|
||||
// Never connects to a server, never starts the microphone, plays nothing.
|
||||
// node scripts/smoke-devices.mjs --out docs/evidence/runtime/<name> [--exe packaged.exe]
|
||||
import { _electron as electron } from 'playwright-core';
|
||||
import { mkdirSync, writeFileSync, mkdtempSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const electronPath = createRequire(import.meta.url)('electron');
|
||||
const argv = process.argv.slice(2);
|
||||
const opt = (n, d) => (argv.indexOf(`--${n}`) >= 0 ? argv[argv.indexOf(`--${n}`) + 1] : d);
|
||||
const out = path.resolve(root, opt('out', 'smoke-out'));
|
||||
const exe = opt('exe');
|
||||
mkdirSync(out, { recursive: true });
|
||||
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-devices-'));
|
||||
const result = { steps: [], console: [] };
|
||||
const step = (name, data = {}) => {
|
||||
result.steps.push({ name, ...data });
|
||||
console.log(`[devices] ${name}`, JSON.stringify(data));
|
||||
};
|
||||
|
||||
async function launch(label) {
|
||||
const app = await electron.launch({
|
||||
executablePath: exe ? path.resolve(exe) : electronPath,
|
||||
args: exe ? [] : [root],
|
||||
env: { ...process.env, TEAMSPEACH_PROFILE_DIR: profile },
|
||||
colorScheme: null,
|
||||
});
|
||||
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.setViewportSize({ width: 1280, height: 800 }).catch(() => {});
|
||||
return { app, page };
|
||||
}
|
||||
|
||||
const readSelects = (page) => page.evaluate(() => {
|
||||
const read = (id) => Array.from(document.querySelector(id).options).map((o) => ({ value: o.value ? 'id' : '', label: o.textContent }));
|
||||
return {
|
||||
inputs: read('#input-device'),
|
||||
outputs: read('#output-device'),
|
||||
inputValueIsDevice: Boolean(document.querySelector('#input-device').value),
|
||||
outputValueIsDevice: Boolean(document.querySelector('#output-device').value),
|
||||
status: document.querySelector('#device-status').textContent,
|
||||
capturing: window.teamspeachDiagnostics.snapshot().voice.framesSent,
|
||||
conn: window.teamspeachDiagnostics.snapshot().conn,
|
||||
toasts: Array.from(document.querySelectorAll('.toast[data-kind="error"]')).map((t) => t.textContent),
|
||||
};
|
||||
});
|
||||
|
||||
let app;
|
||||
let page;
|
||||
let failed = null;
|
||||
try {
|
||||
({ app, page } = await launch('run1'));
|
||||
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 });
|
||||
await page.fill('#onboarding-nick', 'DeviceSmoke');
|
||||
await page.click('#onboarding-submit');
|
||||
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
|
||||
await page.click('#btn-settings');
|
||||
await page.click('#settings-nav .nav-item[data-panel="audio"]');
|
||||
await page.waitForFunction(() => document.querySelector('#device-status').textContent.length > 0, null, { timeout: 10000 });
|
||||
let s = await readSelects(page);
|
||||
step('listed without capture', { inputs: s.inputs.length - 1, outputs: s.outputs.length - 1, inputLabels: s.inputs.map((o) => o.label), outputLabels: s.outputs.map((o) => o.label), status: s.status, conn: s.conn, framesSent: s.capturing });
|
||||
await page.screenshot({ path: path.join(out, '60-audio-devices-listed.png') });
|
||||
if (s.inputs.length < 2 || s.outputs.length < 2) throw new Error('no physical devices listed');
|
||||
|
||||
// Choose the second physical device of each kind (first non-default entry after index 0).
|
||||
const inputChoice = await page.$eval('#input-device', (el) => el.options[Math.min(2, el.options.length - 1)].textContent);
|
||||
const outputChoice = await page.$eval('#output-device', (el) => el.options[Math.min(2, el.options.length - 1)].textContent);
|
||||
await page.selectOption('#input-device', { label: inputChoice });
|
||||
await page.selectOption('#output-device', { label: outputChoice });
|
||||
await page.waitForTimeout(1000);
|
||||
s = await readSelects(page);
|
||||
step('selected', { inputChoice, outputChoice, toasts: s.toasts, framesSent: s.capturing });
|
||||
await app.close();
|
||||
|
||||
({ app, page } = await launch('run2'));
|
||||
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
|
||||
await page.click('#btn-settings');
|
||||
await page.click('#settings-nav .nav-item[data-panel="audio"]');
|
||||
await page.waitForFunction(() => document.querySelector('#device-status').textContent.length > 0, null, { timeout: 10000 });
|
||||
s = await readSelects(page);
|
||||
const inputNow = await page.$eval('#input-device', (el) => el.selectedOptions[0].textContent);
|
||||
const outputNow = await page.$eval('#output-device', (el) => el.selectedOptions[0].textContent);
|
||||
step('after restart', { inputNow, outputNow, persisted: inputNow === inputChoice && outputNow === outputChoice, toasts: s.toasts, conn: s.conn });
|
||||
await page.screenshot({ path: path.join(out, '61-audio-devices-after-restart.png') });
|
||||
if (inputNow !== inputChoice || outputNow !== outputChoice) throw new Error('selection not persisted');
|
||||
// Leave the profile as found: back to system defaults (profile is deleted anyway).
|
||||
await page.selectOption('#input-device', '');
|
||||
await page.selectOption('#output-device', '');
|
||||
} catch (err) {
|
||||
failed = err;
|
||||
step('FAILED', { error: String(err.stack || err) });
|
||||
} finally {
|
||||
if (app) await app.close().catch(() => {});
|
||||
rmSync(profile, { recursive: true, force: true });
|
||||
}
|
||||
result.ok = !failed;
|
||||
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
|
||||
console.log(`[devices] ${result.ok ? 'OK' : 'FAILED'} → ${out}`);
|
||||
process.exit(result.ok ? 0 : 1);
|
||||
Reference in new issue
Block a user