| index f40e349..0f61ab2 100644 |
| --- a/test/browser/call.mjs |
| +++ b/test/browser/call.mjs |
| @@ -340,6 +340,58 @@ const consoleLines = new Map(); // label -> string[] |
| |
| // `via` is the browser to open the context in, for the one scenario |
| // (autoplay) that needs a Chromium launched under a different policy. |
| +// downlinkCap is §15.30's thin link, for the lowbandwidth scenario: every |
| +// video receiver this page makes gets an encoded transform whose worker |
| +// passes a frame only while a token bucket of `kbit/s` (1.5 s of burst) |
| +// has room for it, and drops it otherwise — before the decoder, as a link |
| +// that cannot carry the picture loses it. window.__capDownlink(kbps) sets |
| +// the cap (0 lifts it) and answers how many receivers are behind it. The |
| +// gate's, never the page's: the worker comes from a blob, which the |
| +// page's own CSP refuses unless the context bypasses it. |
| +function downlinkCap() { |
| + if (typeof RTCRtpScriptTransform === 'undefined') return; |
| + const Native = window.RTCPeerConnection; |
| + let worker = null; |
| + let receivers = 0; |
| + const work = () => { |
| + if (!worker) { |
| + const code = [ |
| + 'let cap = 0, tokens = 0, last = 0;', |
| + 'onmessage = (m) => { cap = m.data.cap || 0; tokens = cap * 125 * 1.5; last = performance.now(); };', |
| + 'onrtctransform = (e) => {', |
| + ' e.transformer.readable.pipeThrough(new TransformStream({ transform(f, c) {', |
| + ' if (!cap) { c.enqueue(f); return; }', |
| + ' const now = performance.now();', |
| + ' tokens = Math.min(cap * 125 * 1.5, tokens + (now - last) / 1000 * cap * 125);', |
| + ' last = now;', |
| + ' if (tokens >= f.data.byteLength) { tokens -= f.data.byteLength; c.enqueue(f); }', |
| + ' } })).pipeTo(e.transformer.writable);', |
| + '};', |
| + ].join('\n'); |
| + worker = new Worker(URL.createObjectURL(new Blob([code], { type: 'text/javascript' }))); |
| + } |
| + return worker; |
| + }; |
| + window.__capDownlink = (kbps) => { |
| + work().postMessage({ cap: Number(kbps) || 0 }); |
| + return receivers; |
| + }; |
| + window.RTCPeerConnection = class extends Native { |
| + constructor(...args) { |
| + super(...args); |
| + this.addEventListener('track', (ev) => { |
| + if (!ev.receiver || ev.track.kind !== 'video') return; |
| + try { |
| + ev.receiver.transform = new RTCRtpScriptTransform(work(), {}); |
| + receivers += 1; |
| + } catch { |
| + // A receiver that has started already: not behind the cap. |
| + } |
| + }); |
| + } |
| + }; |
| +} |
| + |
| async function newContext(label, { cookie = null, javaScriptEnabled = true, via = browser, options = {} } = {}) { |
| const ctx = await via.newContext({ javaScriptEnabled, ...options }); |
| if (cookie) { |
| @@ -6562,6 +6614,217 @@ const run = { |
| await ctxB.close(); |
| }, |
| |
| + // Spec §15.30: adaptive video. B's downlink is capped — every video |
| + // frame arriving at B passes a token bucket in an encoded transform, so |
| + // what does not fit the cap is dropped before B's decoder, which is what |
| + // a thin link does to a picture — and B's watch has to ask A for less, |
| + // A has to send less, B's tile has to say so, and audio has to keep |
| + // arriving. Then the cap is lifted and B has to climb back: the first |
| + // step on the real 45 s, the rest on the gate's shortened wait. The |
| + // levels over time are printed, once a second, as the evidence. |
| + async lowbandwidth() { |
| + // What the gate's fake camera sends: about 100–300 kbit/s at normal and |
| + // reduced, 20–60 at minimal (measured 2026-10-28). The cap sits between. |
| + const CAP_KBPS = Number(process.env.CALLS_CAP_KBPS) || 60; |
| + const state = (page) => page.evaluate(() => window.meet.state()); |
| + const ctxA = await newContext('member A', { cookie: cookieA }); |
| + const ctxB = await newContext('member B', { cookie: cookieB, options: { bypassCSP: true } }); |
| + await ctxB.addInitScript(downlinkCap); |
| + const pageA = await openRoom(ctxA); |
| + const pageB = await openRoom(ctxB); |
| + const pair = await assertPair(pageA, pageB, 'member A', 'member B'); |
| + if (!pair) return; |
| + const a = pair.a.peer; |
| + const b = pair.b.peer; |
| + const t0 = Date.now(); |
| + const timeline = []; |
| + let lastBytes = null; |
| + const look = async (what) => { |
| + const sa = await pageA.evaluate(() => window.meet.state()); |
| + const sb = await pageB.evaluate(() => window.meet.state()); |
| + const x = sb.adapt[a] || {}; |
| + const y = sa.adapt[b] || {}; |
| + const row = { |
| + t: Math.round((Date.now() - t0) / 1000), what, |
| + bWatch: x.level, bAsks: x.asked, aSends: y.sent, |
| + aCamera: y.wire ? y.wire.cameraHeight + 'p@' + Math.round(y.wire.cameraFps || 0) : '-', |
| + bAudioIn: x.wire ? x.wire.audioPackets : 0, bFreezes: x.wire ? x.wire.videoFreezes : 0, |
| + notice: sa.videoNotice, aAsks: JSON.stringify(sa.videoAsks), bLast: x.last, |
| + aKbps: y.wire && lastBytes ? Math.round(((y.wire.cameraBytes - lastBytes.bytes) * 8) / (Date.now() - lastBytes.at)) : 0, |
| + }; |
| + if (y.wire) lastBytes = { bytes: y.wire.cameraBytes, at: Date.now() }; |
| + timeline.push(row); |
| + line('levels ' + JSON.stringify(row)); |
| + return { sa, sb, row }; |
| + }; |
| + // A few seconds for A's camera to ramp up past what the cap carries. |
| + for (let i = 0; i < 6; i++) { |
| + await look('open'); |
| + await sleep(1000); |
| + } |
| + const capped = await pageB.evaluate((k) => window.__capDownlink(k), CAP_KBPS); |
| + check(capped, 'B’s video receivers are behind the downlink cap (' + capped + ')'); |
| + let down = null; |
| + for (let i = 0; i < 40 && !down; i++) { |
| + const { row } = await look('capped at ' + CAP_KBPS + ' kbit/s'); |
| + if (row.bAsks === 'minimal' || row.bAsks === 'audio') down = row; |
| + else await sleep(1000); |
| + } |
| + check(down, 'B, capped, asks A for minimal video within 40 s (' + JSON.stringify(timeline[timeline.length - 1]) + ')'); |
| + const firstDown = timeline.find((r) => r.bAsks !== 'normal' && r.what.startsWith('capped')); |
| + check(firstDown && firstDown.t - timeline.find((r) => r.what.startsWith('capped')).t <= 25, |
| + 'the first step down came within 25 s of the cap (' + JSON.stringify(firstDown) + ')'); |
| + // The sender's half, over the wire. |
| + const sent = await until(async () => { |
| + const { row } = await look('capped, sender'); |
| + return row.aSends === row.bAsks && row.aSends !== 'normal' ? row : false; |
| + }, 5000); |
| + check(sent, 'A sends B what B asks for (' + JSON.stringify(timeline[timeline.length - 1]) + ')'); |
| + const small = await until(async () => { |
| + const { sa } = await look('capped, encoder'); |
| + const w = sa.adapt[b] && sa.adapt[b].wire; |
| + return w && w.cameraHeight > 0 && w.cameraHeight <= 180 ? w : false; |
| + }, 15000); |
| + check(small, 'A’s camera to B is encoded at 180 lines or fewer (' + JSON.stringify(timeline[timeline.length - 1]) + ')'); |
| + const notice = (await state(pageA)).videoNotice || ''; |
| + check(/^Sending (reduced video|only audio) to .+ \(their connection is weak\)$/.test(notice), |
| + 'A is told it is sending B less (' + notice + ')'); |
| + const badge = await pageB.evaluate((id) => { |
| + const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low'); |
| + return el && !el.hidden ? { text: el.textContent.trim(), label: el.getAttribute('aria-label') || '' } : null; |
| + }, a); |
| + check(badge && badge.text === 'Low bandwidth' && /less video/.test(badge.label), |
| + 'B’s tile for A says Low bandwidth, with words for a screen reader (' + JSON.stringify(badge) + ')'); |
| + const noBadge = await pageA.evaluate((id) => { |
| + const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low'); |
| + return !el || el.hidden; |
| + }, b); |
| + check(noBadge, 'A, asking nothing of B, shows no badge on B’s tile'); |
| + const audioBefore = (await look('capped, audio')).row.bAudioIn; |
| + await sleep(3000); |
| + const audioAfter = (await look('capped, audio')).row.bAudioIn; |
| + check(audioAfter - audioBefore >= 100, 'audio from A keeps arriving at B (' + audioBefore + ' -> ' + audioAfter + ' packets in 3 s)'); |
| + const hears = await pageB.evaluate((id) => window.meet.state().hearingList.includes(id), a); |
| + check(hears, 'B still hears A'); |
| + // Lift the cap: the first step up on the real wait. |
| + await pageB.evaluate(() => window.__capDownlink(0)); |
| + const lifted = Date.now(); |
| + const from = (await look('lifted')).row.bAsks; |
| + let up = null; |
| + while (!up && Date.now() - lifted < 65000) { |
| + await sleep(1000); |
| + const { row } = await look('lifted'); |
| + if (row.bAsks !== from) up = row; |
| + } |
| + const upAfter = (Date.now() - lifted) / 1000; |
| + check(up && upAfter >= 44 && upAfter <= 62, |
| + 'B steps A’s video up one level 45–60 s after the cap is lifted (' + from + ' -> ' + (up && up.bAsks) + ' after ' + upAfter.toFixed(1) + ' s)'); |
| + // The rest on a shortened wait, all the way back to normal. |
| + await pageB.evaluate(() => window.meet.adaptForTest({ upAfter: 4000 })); |
| + const normal = await until(async () => { |
| + const { row } = await look('lifted, short wait'); |
| + return row.bAsks === 'normal' && row.aSends === 'normal' ? row : false; |
| + }, 30000); |
| + check(normal, 'B climbs back to normal and A sends normal again (' + JSON.stringify(timeline[timeline.length - 1]) + ')'); |
| + const cleared = await pageB.evaluate((id) => { |
| + const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-low'); |
| + return !el || el.hidden; |
| + }, a); |
| + check(cleared, 'the badge goes when B asks for normal again'); |
| + check(!(await state(pageA)).videoNotice, 'A’s notice is gone once B asks for normal'); |
| + check(errorsFor('member A') === '', 'no console errors in A (' + errorsFor('member A') + ')'); |
| + check(errorsFor('member B') === '', 'no console errors in B (' + errorsFor('member B') + ')'); |
| + await leaveRoom(pageA); |
| + await leaveRoom(pageB); |
| + await ctxA.close(); |
| + await ctxB.close(); |
| + }, |
| + |
| + // Spec §15.30: the person's own Video quality. Audio only on B: B asks |
| + // A for no video and stops sending its own camera; A's camera encoding |
| + // to B goes inactive, B's tile for A says the video is paused, A sees B |
| + // as camera off, and audio keeps flowing both ways. Low bandwidth asks |
| + // for minimal, and Auto goes back. The choice is remembered. |
| + async audioonly() { |
| + const full = (page) => page.evaluate(() => window.meet.state()); |
| + const ctxA = await newContext('member A', { cookie: cookieA }); |
| + const ctxB = await newContext('member B', { cookie: cookieB }); |
| + const pageA = await openRoom(ctxA); |
| + const pageB = await openRoom(ctxB); |
| + const pair = await assertPair(pageA, pageB, 'member A', 'member B'); |
| + if (!pair) return; |
| + const a = pair.a.peer; |
| + const b = pair.b.peer; |
| + await pageB.click('#devices-toggle'); |
| + const picker = pageB.locator('#pick-video-quality'); |
| + check(await pageB.getByLabel('Video quality', { exact: true }).count() === 1, 'the Devices panel has a Video quality picker, labelled'); |
| + const options = await pageB.locator('#pick-video-quality option').allTextContents(); |
| + check(JSON.stringify(options) === JSON.stringify(['Auto', 'Low bandwidth', 'Audio only']), |
| + 'its choices are Auto, Low bandwidth and Audio only (' + options + ')'); |
| + check(await picker.inputValue() === 'auto', 'Auto is the default'); |
| + |
| + await picker.selectOption('audio'); |
| + const asked = await until(async () => { |
| + const sa = await full(pageA); |
| + const x = sa.adapt[b] || {}; |
| + return x.sent === 'audio' && x.cameraPaused ? sa : false; |
| + }, 8000); |
| + check(asked, 'A pauses its camera to B when B asks for audio only (' + JSON.stringify((await full(pageA)).adapt[b]) + ')'); |
| + const idle = await until(async () => { |
| + const w1 = (await full(pageA)).adapt[b].wire; |
| + await sleep(2000); |
| + const w2 = (await full(pageA)).adapt[b].wire; |
| + return w2.cameraBytes - w1.cameraBytes < 2000 ? [w1.cameraBytes, w2.cameraBytes] : false; |
| + }, 12000); |
| + check(idle, 'A’s camera to B sends nothing (' + JSON.stringify(idle) + ')'); |
| + const cover = await pageB.evaluate((id) => { |
| + const el = document.querySelector('#tiles figure[data-tile="' + id + '"] .calls-tile-video-paused-cover'); |
| + return el && !el.hidden ? el.innerText.trim().replace(/\s+/g, ' ') : ''; |
| + }, a); |
| + check(cover === 'Video paused to keep audio clear', 'B’s tile for A says the video is paused, and nothing about an old app (' + cover + ')'); |
| + const bOff = await until(async () => { |
| + const m = (await full(pageA)).remoteMedia[b]; |
| + return m && m.cameraOff ? m : false; |
| + }, 5000); |
| + check(bOff, 'A sees B’s camera as off: B sends no camera to anyone'); |
| + const bSendsNothing = await until(async () => { |
| + const sb = await full(pageB); |
| + return sb.adapt[a] && sb.adapt[a].cameraPaused ? true : false; |
| + }, 5000); |
| + check(bSendsNothing, 'B’s own camera to A is paused'); |
| + const aIn1 = (await full(pageA)).adapt[b].wire.audioPackets; |
| + const bIn1 = (await full(pageB)).adapt[a].wire.audioPackets; |
| + await sleep(3000); |
| + const aIn2 = (await full(pageA)).adapt[b].wire.audioPackets; |
| + const bIn2 = (await full(pageB)).adapt[a].wire.audioPackets; |
| + check(aIn2 - aIn1 >= 100 && bIn2 - bIn1 >= 100, 'audio flows both ways (' + [aIn1, aIn2, bIn1, bIn2] + ')'); |
| + check(!(await state(pageA)).terminal && (await state(pageA)).connection[b] === 'connected', 'the connection was not rebuilt for it'); |
| + |
| + await picker.selectOption('low'); |
| + const low = await until(async () => { |
| + const x = (await full(pageA)).adapt[b] || {}; |
| + return x.sent === 'minimal' && !x.cameraPaused ? x : false; |
| + }, 8000); |
| + check(low, 'Low bandwidth asks A for minimal, and A’s camera to B is on again (' + JSON.stringify((await full(pageA)).adapt[b]) + ')'); |
| + const back = await until(async () => { |
| + const m = (await full(pageA)).remoteMedia[b]; |
| + return m && !m.cameraOff ? m : false; |
| + }, 5000); |
| + check(back, 'B’s camera goes to A again once B is no longer on Audio only'); |
| + check(await pageB.evaluate(() => JSON.parse(localStorage.getItem('meet.devices') || '{}').videoQuality) === 'low', |
| + 'the choice is remembered in this browser'); |
| + |
| + await picker.selectOption('auto'); |
| + const auto = await until(async () => ((await full(pageA)).adapt[b] || {}).sent === 'normal', 8000); |
| + check(auto, 'Auto asks A for normal again'); |
| + check(errorsFor('member A') === '', 'no console errors in A (' + errorsFor('member A') + ')'); |
| + check(errorsFor('member B') === '', 'no console errors in B (' + errorsFor('member B') + ')'); |
| + await leaveRoom(pageA); |
| + await leaveRoom(pageB); |
| + await ctxA.close(); |
| + await ctxB.close(); |
| + }, |
| + |
| // The self view, in Chromium and in WebKit (2026-10-21: on an iPhone |
| // in Safari the floating self view was black for a whole call while |
| // the camera was being sent perfectly well). Every way the local |