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.
260 lines
17 KiB
JavaScript
260 lines
17 KiB
JavaScript
// Isolated broadcaster UI: the only capturable display source is a generated QA window.
|
|
// No real server, microphone, private screen, private camera, or persistent profile is used.
|
|
// Run ONLY inside an isolated virtual display; never on the owner's Windows desktop.
|
|
import { closeSettings, launchApp } from './lib/electron-app.mjs';
|
|
import assert from 'node:assert/strict';
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
import { tmpdir } from 'node:os';
|
|
import path from 'node:path';
|
|
|
|
const args = process.argv.slice(2);
|
|
const opt = (key, fallback) => args.includes(`--${key}`) ? args[args.indexOf(`--${key}`) + 1] : fallback;
|
|
const injectedCapture = args.includes('--offscreen-fixture');
|
|
if (!injectedCapture && process.platform === 'win32') throw new Error('Native capture smoke is disabled on Windows. Use the separate injected-capture offscreen smoke.');
|
|
if (!injectedCapture && (process.env.TEAMSPEACH_ISOLATED_DISPLAY !== '1' || !process.env.DISPLAY)) throw new Error('Native capture needs an explicitly isolated virtual DISPLAY (TEAMSPEACH_ISOLATED_DISPLAY=1).');
|
|
const out = path.resolve(opt('out', 'smoke-out/broadcast-ui'));
|
|
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-broadcast-ui-'));
|
|
mkdirSync(out, { recursive: true });
|
|
const result = { scope: injectedCapture ? 'Offscreen real renderer; injected generated canvas capture and synthetic signaling. Not native capture, permissions, TS6 interoperability or platform proof.' : 'Hidden generated QA source, synthetic signaling IPC. Native capture unavailable offscreen is not a pass.', checks: [], screenshots: [], errors: [] };
|
|
let app;
|
|
let page;
|
|
const check = (name, data = {}) => result.checks.push({ name, ...data });
|
|
const snapshot = {
|
|
event: 'snapshot', rev: 1, own_client_id: 1, own_channel_id: 10,
|
|
server: { name: 'Broadcast QA', version: 'fixture', welcome_message: '' },
|
|
channels: [{ id: 10, parent_id: 0, order: 0, depth: 0, name: 'Generated media only', topic: '', codec: 'opus_voice', needed_talk_power: 0, has_password: false }],
|
|
clients: [
|
|
{ id: 1, uid: 'qa-broadcaster', nickname: 'Broadcaster', channel_id: 10, is_self: true, input_muted: true, output_muted: true, server_groups: [] },
|
|
{ id: 2, uid: 'qa-selected', nickname: 'Selected viewer', channel_id: 10, input_muted: true, output_muted: true, server_groups: [] },
|
|
{ id: 3, uid: 'qa-other', nickname: 'Other viewer', channel_id: 10, input_muted: true, output_muted: true, server_groups: [] },
|
|
], server_groups: [], channel_groups: [],
|
|
};
|
|
const commands = () => app.evaluate(() => globalThis.__broadcastUI.commands);
|
|
const send = (event) => app.evaluate(({ BrowserWindow }, value) => {
|
|
const main = BrowserWindow.getAllWindows().find(win => win.webContents.getURL().startsWith('app://'));
|
|
main.webContents.send('core:event', { ...value, connectionId: 'c1' });
|
|
}, event);
|
|
const source = () => page.locator('.broadcast-source').filter({ hasText: 'TeamsPeach Generated Broadcast QA' });
|
|
const open = async () => {
|
|
await page.locator('#broadcast-controls button').first().click();
|
|
await source().waitFor({ state: 'visible' });
|
|
};
|
|
const preview = async () => {
|
|
await source().click();
|
|
await page.getByRole('button', { name: /^(Next|Далее)$/ }).click();
|
|
await page.waitForFunction(() => {
|
|
const video = document.querySelector('.broadcast-preview video');
|
|
return video?.srcObject && video.videoWidth > 0 && !document.querySelector('.broadcast-settings').hidden;
|
|
});
|
|
};
|
|
// Wide dialogs show segmented pills; narrow ones (data-collapsed) show the same choices as a <select>.
|
|
const choose = async (setting, value) => {
|
|
const choice = page.locator(`.broadcast-settings .broadcast-choice[data-setting="${setting}"]`);
|
|
if (await page.locator('.broadcast-dialog[data-collapsed="true"]').count()) await choice.locator('select').selectOption(value);
|
|
else await choice.locator(`[role="radio"][data-value="${value}"]`).click();
|
|
};
|
|
const rememberTrack = () => page.evaluate(() => { window.__broadcastLastTrack = document.querySelector('.broadcast-preview video').srcObject.getVideoTracks()[0]; });
|
|
const assertStopped = async () => {
|
|
await page.waitForFunction(() => window.__broadcastLastTrack.readyState === 'ended');
|
|
assert.equal(await page.locator('.broadcast-local-view').count(), 0);
|
|
};
|
|
const startCount = async () => (await commands()).filter(item => item.cmd === 'stream_setup').length;
|
|
try {
|
|
app = await launchApp({ exe: opt('exe'), profile, args: ['--use-fake-device-for-media-stream'] });
|
|
page = await app.firstWindow();
|
|
page.on('pageerror', error => result.errors.push(error.message));
|
|
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 30000 });
|
|
await page.evaluate((injected) => {
|
|
window.__broadcastCaptureCalls = 0;
|
|
const getDisplayMedia = navigator.mediaDevices.getDisplayMedia.bind(navigator.mediaDevices);
|
|
navigator.mediaDevices.getDisplayMedia = (...args) => {
|
|
window.__broadcastCaptureCalls++;
|
|
if (window.__broadcastDenyCapture) return Promise.reject(new DOMException('Generated permission denial', 'NotAllowedError'));
|
|
if (!injected) return getDisplayMedia(...args);
|
|
const canvas = document.createElement('canvas');
|
|
canvas.width = 640; canvas.height = 360;
|
|
const context = canvas.getContext('2d');
|
|
const draw = () => {
|
|
context.fillStyle = '#193b4b'; context.fillRect(0, 0, 640, 360);
|
|
context.fillStyle = '#f09a6c'; context.fillRect(Date.now() / 10 % 560, 140, 80, 80);
|
|
context.fillStyle = '#fff'; context.font = '28px sans-serif'; context.fillText('Generated offscreen QA source', 20, 70);
|
|
};
|
|
draw();
|
|
const stream = canvas.captureStream(30);
|
|
const track = stream.getVideoTracks()[0];
|
|
const timer = setInterval(draw, 33);
|
|
const stop = track.stop.bind(track);
|
|
track.stop = () => { clearInterval(timer); stop(); };
|
|
track.addEventListener('ended', () => clearInterval(timer), { once: true });
|
|
return Promise.resolve(stream);
|
|
};
|
|
// Voice/microphone is never part of this test. Fake camera remains opt-in only.
|
|
navigator.mediaDevices.getUserMedia = () => { throw new Error('All physical device capture forbidden in broadcaster UI smoke'); };
|
|
if (injected) navigator.mediaDevices.enumerateDevices = async () => [];
|
|
}, injectedCapture);
|
|
await page.fill('#onboarding-nick', 'BroadcastQA');
|
|
await page.click('#onboarding-submit');
|
|
await page.waitForSelector('#view-app', { state: 'visible' });
|
|
await app.evaluate(async ({ BrowserWindow, desktopCapturer, ipcMain }, injected) => {
|
|
const main = BrowserWindow.getAllWindows()[0];
|
|
let generated;
|
|
if (!injected) {
|
|
generated = new BrowserWindow({ width: 640, height: 360, show: false, focusable: false, title: 'TeamsPeach Generated Broadcast QA', webPreferences: { offscreen: true, backgroundThrottling: false, nodeIntegration: false, contextIsolation: true } });
|
|
await generated.loadURL(`data:text/html,${encodeURIComponent('<!doctype html><title>TeamsPeach Generated Broadcast QA</title><body style="background:#193b4b;color:white;font:32px system-ui">Generated QA source — no private content</body>')}`);
|
|
}
|
|
const original = desktopCapturer.getSources.bind(desktopCapturer);
|
|
desktopCapturer.getSources = async options => {
|
|
if (options.types.includes('screen')) return [];
|
|
const sources = await original({ ...options, types: ['window'], thumbnailSize: { width: 0, height: 0 } });
|
|
return sources.filter(source => source.name === 'TeamsPeach Generated Broadcast QA');
|
|
};
|
|
globalThis.__broadcastUI = { commands: [], mainId: main.id, sourceId: generated?.id, sequence: 0 };
|
|
if (injected) {
|
|
const capabilities = { supported: true, sourceTypes: ['window', 'screen'], nativePicker: false, portal: false, audio: { system: { supported: false, reason: 'Physical audio is blocked in this offscreen fixture.' }, excludeSelf: { supported: false } }, requirements: [] };
|
|
for (const channel of ['capture:capabilities', 'capture:sources', 'capture:select', 'capture:cancel', 'appaudio:list']) ipcMain.removeHandler(channel);
|
|
ipcMain.handle('capture:capabilities', () => capabilities);
|
|
ipcMain.handle('capture:sources', (_event, options) => ({ ok: true, capabilities, sources: options.types.includes('window') ? [{ id: 'window:offscreen-fixture', name: 'TeamsPeach Generated Broadcast QA', kind: 'window', thumbnail: '' }] : [] }));
|
|
ipcMain.handle('capture:select', (_event, options) => options.sourceId === 'window:offscreen-fixture' && options.audioMode === 'none' ? { ok: true, audio: false, camera: false } : { ok: false, error: { code: 'fixture_forbidden', message: 'Only generated silent canvas capture is allowed.' } });
|
|
ipcMain.handle('capture:cancel', () => ({ ok: true }));
|
|
ipcMain.handle('appaudio:list', () => ({ ok: true, supported: false, applications: [], reason: 'Physical audio is blocked in this offscreen fixture.' }));
|
|
}
|
|
ipcMain.removeHandler('core:request');
|
|
ipcMain.handle('core:request', (_event, connectionId, cmd, args) => {
|
|
globalThis.__broadcastUI.commands.push({ cmd, args });
|
|
if (cmd === 'stream_setup') {
|
|
const id = String(++globalThis.__broadcastUI.sequence);
|
|
setTimeout(() => main.webContents.send('core:event', { ...{ event: 'stream', name: 'notifystreamstarted', items: [{ clid: '1', id }] }, connectionId: 'c1' }), 10);
|
|
return { ok: true, result: {} };
|
|
}
|
|
if (cmd === 'stream_stop' || cmd === 'stream_respond' || cmd === 'stream_remove' || cmd === 'stream_signal' || cmd === 'set_transmit') return { ok: true, result: {} };
|
|
if (cmd === 'stream_list') return { ok: true, result: { results: [] } };
|
|
return { ok: false, error: { code: 'not_connected', message: 'Isolated generated-source UI fixture' } };
|
|
});
|
|
main.setContentSize(1280, 800);
|
|
}, injectedCapture);
|
|
await send({ event: 'audio_state', input_muted: true, output_muted: true, transmitting: false });
|
|
await send({ event: 'state', state: 'connected', address: 'fixture.invalid', reason: null });
|
|
await send(snapshot);
|
|
await open();
|
|
assert.equal(await page.evaluate(() => window.__broadcastCaptureCalls), 0);
|
|
await source().click();
|
|
assert.equal(await page.evaluate(() => window.__broadcastCaptureCalls), 0);
|
|
assert.equal(await startCount(), 0);
|
|
check('Opening chooser and selecting generated window capture no pixels and send nothing');
|
|
await preview();
|
|
await rememberTrack();
|
|
assert.equal(await startCount(), 0);
|
|
assert.equal(await page.locator('.broadcast-local-view').count(), 0);
|
|
assert.equal(await page.$eval('.broadcast-preview video', video => video.muted), true);
|
|
await page.keyboard.press('Escape');
|
|
await assertStopped();
|
|
check('Private preview is muted, not network-published; Escape releases selected capture');
|
|
|
|
for (const language of ['en', 'ru']) {
|
|
await page.evaluate(async locale => (await import('./js/i18n.js')).setLanguage(locale), language);
|
|
for (const theme of ['dark', 'light']) {
|
|
await page.evaluate(value => window.teamspeach.setPrefs({ theme: value }), theme);
|
|
await page.waitForFunction(dark => matchMedia('(prefers-color-scheme: dark)').matches === dark, theme === 'dark');
|
|
for (const [width, height] of [[1280, 900], [880, 560]]) {
|
|
await app.evaluate(({ BrowserWindow }, size) => BrowserWindow.fromId(globalThis.__broadcastUI.mainId).setContentSize(...size), [width, height]);
|
|
await open();
|
|
await preview();
|
|
await rememberTrack();
|
|
await choose('preset', 'presentation');
|
|
await choose('privacy', 'contacts');
|
|
await page.locator('.broadcast-participants input').first().check();
|
|
await page.locator('.broadcast-settings .broadcast-expander').click();
|
|
assert.equal(await page.locator('.broadcast-settings [data-setting="fps"] [aria-checked="true"]').getAttribute('data-value'), '5');
|
|
const file = `broadcast-${language}-${theme}-${width}x${height}.png`;
|
|
await page.screenshot({ path: path.join(out, file) });
|
|
result.screenshots.push(file);
|
|
const dimensions = await page.$eval('.broadcast-dialog', dialog => ({ width: dialog.clientWidth, scrollWidth: dialog.scrollWidth, right: dialog.getBoundingClientRect().right, viewport: innerWidth }));
|
|
assert.ok(dimensions.scrollWidth <= dimensions.width + 1, 'dialog has no horizontal overflow');
|
|
assert.ok(dimensions.right <= dimensions.viewport, 'dialog stays on screen');
|
|
await page.keyboard.press('Escape');
|
|
await assertStopped();
|
|
check('Preview controls locale/theme/viewport', { language, theme, width, height });
|
|
}
|
|
}
|
|
}
|
|
await page.evaluate(async () => (await import('./js/i18n.js')).setLanguage('en'));
|
|
await app.evaluate(({ BrowserWindow }) => BrowserWindow.fromId(globalThis.__broadcastUI.mainId).setContentSize(1280, 800));
|
|
await open();
|
|
await preview();
|
|
await rememberTrack();
|
|
await choose('privacy', 'closed');
|
|
await page.getByRole('button', { name: 'Go Live', exact: true }).click();
|
|
await page.locator('.broadcast-local-view').waitFor({ state: 'visible' });
|
|
assert.equal(await startCount(), 1);
|
|
assert.equal(await page.$eval('.broadcast-local-view video', video => video.muted), true);
|
|
await send({ event: 'stream', name: 'notifyjoinstreamrequest', items: [{ id: '1', clid: '2', is_remove: '0' }] });
|
|
await page.getByRole('button', { name: 'Manage transmission', exact: true }).click();
|
|
await page.getByRole('button', { name: 'Allow', exact: true }).waitFor();
|
|
assert.equal((await commands()).some(item => item.cmd === 'stream_respond' && item.args.decision), false);
|
|
await page.getByRole('button', { name: 'Decline', exact: true }).click();
|
|
await page.keyboard.press('Escape');
|
|
await page.click('#btn-settings');
|
|
assert.equal(await page.evaluate(() => window.__broadcastLastTrack.readyState), 'live', 'settings navigation retains the explicitly started source');
|
|
await closeSettings(page);
|
|
assert.equal(await page.locator('#broadcast-controls .broadcast-stop').isVisible(), true);
|
|
await page.locator('#broadcast-controls .broadcast-stop').click();
|
|
await assertStopped();
|
|
assert.ok((await commands()).some(item => item.cmd === 'stream_stop'));
|
|
check('Explicit Start publishes; approval sends no early offer; returning from Settings retains reachable Stop and releases capture');
|
|
|
|
await open();
|
|
await preview();
|
|
await rememberTrack();
|
|
await choose('privacy', 'contacts');
|
|
await page.getByRole('button', { name: 'Go Live', exact: true }).click();
|
|
await page.locator('.broadcast-local-view').waitFor({ state: 'visible' });
|
|
await send({ event: 'stream', name: 'notifyjoinstreamrequest', items: [{ id: '2', clid: '2', is_remove: '0' }] });
|
|
await page.waitForTimeout(100);
|
|
assert.equal((await commands()).some(item => item.cmd === 'stream_respond' && item.args.stream_id === '2' && item.args.decision), false);
|
|
await page.getByRole('button', { name: 'Change source', exact: true }).click();
|
|
await assertStopped();
|
|
await source().waitFor({ state: 'visible' });
|
|
assert.equal(await startCount(), 2, 'switch does not restart publishing');
|
|
await page.keyboard.press('Escape');
|
|
check('Empty selected-participant list admits nobody; switching source stops old media and requires a new Start');
|
|
|
|
await open();
|
|
await page.evaluate(() => { window.__broadcastDenyCapture = true; });
|
|
await source().click();
|
|
await page.getByRole('button', { name: 'Next', exact: true }).click();
|
|
await page.locator('.broadcast-error').waitFor({ state: 'visible' });
|
|
assert.equal(await startCount(), 2);
|
|
assert.equal(await page.$eval('.broadcast-preview video', video => video.srcObject), null);
|
|
await page.screenshot({ path: path.join(out, 'broadcast-permission-error.png') });
|
|
result.screenshots.push('broadcast-permission-error.png');
|
|
await page.keyboard.press('Escape');
|
|
await page.evaluate(() => { window.__broadcastDenyCapture = false; });
|
|
check('Permission denial shows actionable error and does not publish or retain preview');
|
|
|
|
await open();
|
|
await preview();
|
|
await rememberTrack();
|
|
await page.getByRole('button', { name: 'Go Live', exact: true }).click();
|
|
await page.locator('.broadcast-local-view').waitFor({ state: 'visible' });
|
|
if (injectedCapture) await page.evaluate(() => {
|
|
window.__broadcastLastTrack.stop();
|
|
window.__broadcastLastTrack.dispatchEvent(new Event('ended'));
|
|
});
|
|
else await app.evaluate(({ BrowserWindow }) => BrowserWindow.fromId(globalThis.__broadcastUI.sourceId).destroy());
|
|
await assertStopped();
|
|
await page.waitForFunction(() => document.querySelector('#broadcast-controls').dataset.live === 'false');
|
|
check(injectedCapture ? 'Injected source-ended event stops local transmission' : 'Closing hidden generated source stops local transmission');
|
|
assert.deepEqual(result.errors, []);
|
|
result.ok = true;
|
|
} catch (error) {
|
|
result.ok = false;
|
|
result.failure = error.stack || String(error);
|
|
if (page) await page.screenshot({ path: path.join(out, 'failure.png') }).catch(() => {});
|
|
process.exitCode = 1;
|
|
} finally {
|
|
if (app) await app.close().catch(() => {});
|
|
rmSync(profile, { recursive: true, force: true });
|
|
writeFileSync(path.join(out, 'result.json'), JSON.stringify(result, null, 2));
|
|
console.log(JSON.stringify(result, null, 2));
|
|
}
|