// Real Electron smoke of channel selection, the stream area above the chat and the player's full screen, // on a disposable profile that never connects to a server. Two inputs, reported separately in result.json: // // - UI fixture: a synthetic snapshot and stream notifications are delivered through the real main → renderer // `core:event` IPC, exactly where the core's events arrive, so the production tree, header, stream list and // buttons are clicked. The core itself is running but not connected: commands the UI issues reach it and // fail with `not_connected`, which the UI must report. Issued commands are read back from the core's debug // log (TEAMSPEACH_LOG=debug), so "a click did not join" is checked at the bridge, not in the page. // - Loopback media: a throwaway RTCPeerConnection sends canvas video and a generated 440 Hz tone. // After the real-core error checks, a test-only IPC handler routes production Watch clicks to that // sender's SDP/ICE transport. This proves real Chromium media and production UI, not TS6 signaling. // // Neither input proves server discovery or TeamSpeak interoperability. No server connection or capture // device is opened: getUserMedia is explicitly denied and counted in the disposable renderer. // // node scripts/smoke-stream-view.mjs --isolated-desktop --out [--exe ] // Requires a dedicated Windows test login separate from the active user console. Offscreen rendering // cannot prove native PiP always-on-top behavior and is deliberately not substituted for this test. import { closeSettings, launchApp } from './lib/electron-app.mjs'; import assert from 'node:assert/strict'; import { execFileSync } from 'node:child_process'; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } 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) => (argv.indexOf(`--${name}`) >= 0 ? argv[argv.indexOf(`--${name}`) + 1] : undefined); const out = path.resolve(root, opt('out') ?? 'smoke-out/stream-view'); const exe = opt('exe'); if (!argv.includes('--isolated-desktop') || process.env.TEAMSPEACH_ISOLATED_DESKTOP !== '1') { throw new Error('Desktop safety: native stream smoke is disabled. Use --isolated-desktop and TEAMSPEACH_ISOLATED_DESKTOP=1 only in a verified dedicated Windows test session, never the user desktop.'); } if (process.platform !== 'win32') throw new Error('This native OS PiP evidence harness requires isolated Windows; headless results cannot establish always-on-top behavior.'); execFileSync('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', path.join(root, 'scripts/lib/stream-windows.ps1'), '-RootProcessId', String(process.pid)], { encoding: 'utf8', windowsHide: true }); mkdirSync(out, { recursive: true }); const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-stream-view-')); const result = { startedAt: new Date().toISOString(), exe: exe ?? null, steps: [], pageErrors: [] }; const step = (name, data = {}) => { result.steps.push({ name, ...data }); console.log(`[stream-view] ${name}`, JSON.stringify(data)); }; // ---------- UI fixture (synthetic server state, delivered over the real core:event IPC) ---------- const channel = (id, name, order, topic = '') => ({ id, parent_id: 0, order, name, topic, has_password: false, is_default: id === 10, max_clients: null, needed_talk_power: 0, codec: 'opus_voice', codec_quality: 6, icon_id: null, banner_url: null, banner_mode: null, depth: 0, }); const client = (id, nickname, channelId, isStreaming, extra = {}) => ({ id, uid: null, nickname, channel_id: channelId, is_self: false, client_type: 'normal', input_muted: false, output_muted: false, input_hardware: true, output_hardware: true, away: false, away_message: null, talk_power: 0, is_talker: false, is_channel_commander: false, is_priority_speaker: false, is_recording: false, is_streaming: isStreaming, description: null, country: null, server_groups: [], channel_group_id: null, channel_group_inherited_from: null, avatar_hash: null, has_myts: false, myts_avatars: [], myts_avatar_unparsed: null, icon_id: null, badges: null, ...extra, }); let rev = 0; const snapshot = (flags = {}) => ({ event: 'snapshot', rev: ++rev, server: { name: 'UI fixture (no server)', version: null, welcome_message: '', hostbanner_gfx_url: null, hostbanner_url: null }, own_client_id: 1, own_channel_id: 10, server_groups: [], channel_groups: [], channels: [channel(10, 'Lobby', 0), channel(20, 'Screens', 1, 'Design and games'), channel(30, 'Quiet', 2)], clients: [ client(1, 'StreamSmoke', 10, false, { is_self: true }), client(2, 'Ana', 10, false), client(11, 'Mira', 20, flags.mira ?? true), client(12, 'Oleg', 20, flags.oleg ?? true), client(13, 'Pavel', 20, true), client(14, 'Rita', 30, false), ], }); const streamInfo = (id, clid, name, audio) => ({ event: 'stream', name: 'notifystreaminfo', items: [{ id, clid: String(clid), name, type: '2', mode: '1', accessibility: '1', audio, bitrate: '0', viewer: '0', viewer_limit: '0', return_code: '' }] }); let app; let page; const send = (evt) => app.evaluate(({ BrowserWindow }, e) => BrowserWindow.getAllWindows()[0].webContents.send('core:event', { ...e, connectionId: 'c1' }), evt); const resize = (width, height) => app.evaluate(({ BrowserWindow }, [w, h]) => BrowserWindow.getAllWindows()[0].setContentSize(w, h), [width, height]); const windowFullScreen = () => app.evaluate(({ BrowserWindow }) => BrowserWindow.getAllWindows()[0].isFullScreen()); const diag = () => page.evaluate(() => window.teamspeachDiagnostics.snapshot()); const coreCommands = () => { let text = ''; try { text = readFileSync(path.join(profile, 'logs', 'core.log'), 'utf8'); } catch { return []; } return [...text.matchAll(/cmd="?([a-z_]+)"?\s+request|request.*?cmd="?([a-z_]+)/g)].map((m) => m[1] ?? m[2]); }; const count = (cmd) => coreCommands().filter((c) => c === cmd).length; const toasts = () => page.$$eval('.toast', (els) => els.map((e) => ({ kind: e.dataset.kind ?? '', text: e.textContent.trim() }))); const dismissToasts = () => page.evaluate(() => document.querySelectorAll('.toast .icon-btn').forEach((b) => b.click())); const offers = () => page.$$eval('#stream-offers > li', (els) => els.map((e) => e.dataset.key)); const shot = async (name) => { await page.waitForTimeout(150); await page.screenshot({ path: path.join(out, `${name}.png`) }); }; const noOverflow = () => page.evaluate(() => document.documentElement.scrollWidth <= innerWidth && document.body.scrollWidth <= innerWidth); const waitFor = (fn, arg, timeout = 15000) => page.waitForFunction(fn, arg, { timeout }); // PiP lives in the player's overflow (
"more" panel); open it the way a user does, then activate PiP. const openPip = async (pipSelector) => { const selector = pipSelector || '[data-role="stream-pip"]'; await page.$eval(selector, (pip) => { const details = pip.closest('details'); if (details && !details.open) details.querySelector('summary').click(); }); await page.click(selector); }; // ---------- loopback streamer (real WebRTC inside the page) ---------- const installStreamer = () => { const NativePC = window.RTCPeerConnection; window.RTCPeerConnection = function () { return new NativePC(); }; // Host-only fixture; no public STUN. window.RTCPeerConnection.prototype = NativePC.prototype; window.__loop = { joins: 0, transports: new Map(), sources: new Map(), async start(id, clientId) { const watch = await import('./js/watch.js'); const ctx = new AudioContext(); const osc = ctx.createOscillator(); osc.frequency.value = 440; const dest = ctx.createMediaStreamDestination(); const quiet = ctx.createGain(); quiet.gain.value = 0; osc.connect(quiet); quiet.connect(dest); osc.start(); const canvas = document.createElement('canvas'); canvas.width = 640; canvas.height = 360; const g = canvas.getContext('2d'); let n = 0; const timer = setInterval(() => { g.fillStyle = `hsl(${(n += 7) % 360} 55% 45%)`; g.fillRect(0, 0, 640, 360); g.fillStyle = '#fff'; g.font = '28px sans-serif'; g.fillText(`loopback frame ${n / 7}`, 24, 52); }, 33); const ms = new MediaStream([canvas.captureStream(30).getVideoTracks()[0], dest.stream.getAudioTracks()[0]]); const pc = new RTCPeerConnection(); for (const t of ms.getTracks()) pc.addTrack(t, ms); const emit = (name, item) => watch.onStreamEvent({ event: 'stream', name, items: [{ id, clid: String(clientId), ...item }] }); pc.onicecandidate = (e) => { if (e.candidate) emit('notifystreamsignaling', { json: JSON.stringify({ cmd: 'iceCandidate', args: { mLine: e.candidate.sdpMLineIndex, mid: e.candidate.sdpMid, sdp: e.candidate.candidate } }) }); }; const loop = this; const transport = { async join() { loop.joins += 1; await pc.setLocalDescription(await pc.createOffer()); setTimeout(() => emit('notifyrespondjoinstreamrequest', { decision: '1', offer: pc.localDescription.sdp, msg: '' }), 50); }, async send(_id, _clid, json) { if (json.cmd === 'answer') await pc.setRemoteDescription({ type: 'answer', sdp: json.args.answer }); else if (json.cmd === 'iceCandidate') await pc.addIceCandidate({ candidate: json.args.sdp, sdpMid: json.args.mid, sdpMLineIndex: json.args.mLine }); }, async leave() { clearInterval(timer); for (const track of ms.getTracks()) track.stop(); pc.close(); await ctx.close(); }, }; this.transports.set(id, transport); this.sources.set(id, { pc, media: ms }); transport.end = async () => { emit('notifystreamstopped', {}); await transport.leave(); }; }, }; }; const media = () => page.evaluate(() => { const v = document.querySelector('[data-role="stream-video"]'); const d = window.teamspeachDiagnostics.snapshot(); return { sameElementMedia: v === window.__video && v.srcObject !== null && v.srcObject === window.__src, paused: v.paused, tracks: v.srcObject ? v.srcObject.getTracks().map((t) => `${t.kind}:${t.readyState}`) : [], joins: window.__loop.joins, state: d.watches[0].state, watchingIds: d.watchingIds, framesDecoded: d.watches[0].framesDecoded, inboundAudioPackets: d.watches[0].inboundAudioPackets, fullscreen: d.fullscreen, videoWidth: Math.round(v.getBoundingClientRect().width), videoHeight: Math.round(v.getBoundingClientRect().height), viewportHeight: innerHeight, viewport: innerWidth, button: document.querySelector('[data-role="stream-fullscreen"]').getAttribute('aria-label'), }; }); const progressed = async (before, label) => { await page.waitForTimeout(2000); const after = await media(); assert.ok(after.framesDecoded > before.framesDecoded, `${label}: video frames keep decoding`); assert.ok(after.inboundAudioPackets > before.inboundAudioPackets, `${label}: audio packets keep arriving`); assert.equal(after.sameElementMedia, true, `${label}: same MediaStream on the same