oficina / meet Public

Calls web: the self view is played, watched and never silently black

On an iPhone in Safari (21 Oct, Farshad, iOS beta, Low Power Mode) the
floating self view was black for a whole call while the camera was
being sent fine. The self tile relied on `autoplay` alone: nothing ever
called play() on it, comeBack resumed every tile but ours, and no watch
looked at it. An element the system paused (iOS pauses page media in
the background and leaves the camera running) or never let start (Low
Power Mode declines autoplay) stayed black with nothing said.
Reproduced in Chromium and WebKit: pause the media, bring the tab back,
and the remote tiles resume while the self view stays paused.

- tile() asks the self view to play on every binding (playSelf), and
  comeBack and the page-wide sound gesture ask it again.
- A self-view watch (judgeSelf, once a second from pollFrames): a live,
  enabled camera whose element has not moved for 2 s is re-bound and
  played once; still stuck, or play() refused, and the tile is covered
  by a button, "Your camera preview is paused. Show it", never black.
  It is not a sound refusal and puts up no banner.
- Gate: selfview and selfviewwebkit scenarios (1:1 floating at phone
  size, a call of three, camera toggle, tab back with media paused and
  with tracks ended, a silent pause, a refused play, a camera chosen
  late), plus room-self.test.mjs for the watch, playSelf and comeBack.
  make browser now installs WebKit too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev c29636005e8ee207d774061df355c43cf7b5f65c parent 882eab8
6 files changed, +664 −3
  • Makefile +3 −0
  • internal/calls/static/calls.css +32 −0
  • internal/calls/static/room.js +159 −2
  • internal/callstest/browser_test.go +2 −0
  • test/browser/call.mjs +281 −1
  • test/browser/room-self.test.mjs +187 −0

CI failed — run details

diff --git a/Makefile b/Makefile
index 976b7e1..720324e 100644
--- a/Makefile
+++ b/Makefile
@@ -159,11 +159,14 @@ browser:
node --test test/browser/room-lane.test.mjs
node --test test/browser/room-quality.test.mjs
node --test test/browser/room-wake.test.mjs
+ node --test test/browser/room-self.test.mjs
node --test test/browser/media.test.mjs
node --test test/browser/audio.test.mjs
node --test test/browser/devices.test.mjs
npm install --no-save playwright@1.62.1
npx playwright install chromium
+ # selfviewwebkit (2026-10-21) holds the self view in WebKit too.
+ npx playwright install webkit
go test -tags browser -count=1 -timeout 20m -run TestCallInARealBrowser -v ./internal/callstest/
# Native builds isolate gomobile's cgo bridge from the cgo-free server.
diff --git a/internal/calls/static/calls.css b/internal/calls/static/calls.css
index d22ccfc..b2fbac0 100644
--- a/internal/calls/static/calls.css
+++ b/internal/calls/static/calls.css
@@ -869,6 +869,38 @@ body:has(> .calls-window) { background: var(--rst-bg); }
.calls-tile-off .icon { inline-size: 2rem; block-size: 2rem; }
.calls-tile-camera-off .calls-tile-name { z-index: 1; }
+/* Our own preview, when the browser will not play it (room.js's
+ self-view watch, 2026-10-21): never a black box with nothing said.
+ The whole tile is the button, because the floating self view on a
+ phone is too small for a sentence and a control in its caption. */
+.calls-tile-paused {
+ position: absolute;
+ inset: 0;
+ z-index: 1;
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ justify-content: center;
+ gap: 4px;
+ margin: 0;
+ padding: 8px 8px 2rem;
+ border: 0;
+ border-radius: inherit;
+ background: #212121;
+ color: rgb(255 255 255 / 0.85);
+ font: inherit;
+ font-size: var(--rst-fs-sm);
+ line-height: 1.25;
+ text-align: center;
+ cursor: pointer;
+}
+.calls-tile-paused[hidden] { display: none; }
+.calls-tile-paused-show { font-weight: 600; color: #fff; text-decoration: underline; }
+.calls-tile-self:has(.calls-tile-paused:not([hidden])) .calls-tile-name { z-index: 2; }
+@container (max-width: 15rem) {
+ .calls-tile-paused { font-size: var(--rst-fs-xs); padding-block-end: 1.75rem; }
+}
+
/* What a tile says about its audio when the rim cannot: no sound,
sound blocked, a microphone picking nothing up. Words, with the
weight as a second cue, in the caption's own pill. The ⓘ is a native
diff --git a/internal/calls/static/room.js b/internal/calls/static/room.js
index 4fd5382..2bd79ba 100644
--- a/internal/calls/static/room.js
+++ b/internal/calls/static/room.js
@@ -224,6 +224,14 @@
// Reading any advance at all as health let such a tile reset the
// budget below for ever and never earn its reset.
const RENDER_MOVED = 0.25;
+ // The self view's own watch (2026-10-21: an iPhone in Safari showed
+ // its own picture black for a whole call while sending it perfectly).
+ // How long a live, enabled camera may sit in the self view without
+ // its element's clock moving before the element is handed the stream
+ // again and asked to play, and — that once — before the tile says so.
+ const SELF_STUCK_MS = 2000;
+ const SELF_PAUSED = 'Your camera preview is paused.';
+ const SELF_SHOW = 'Show it';
// The ceiling studio audio asks for, in bits per second. Opus is
// transparent for speech well below it; the number is picked so a
// microphone someone turned the processing off for is not then
@@ -6528,6 +6536,9 @@
if (t.play) t.play.hidden = true;
startPlaying(key, t);
}
+ // The same gesture is the one a refused preview was waiting for.
+ const me = tiles.get('self');
+ if (me && me.stream && me.video.paused) playSelf(me);
drawBanner();
}
@@ -6837,9 +6848,28 @@
// §15.20's hearing parts go with them, on the same tiles and for
// the same reason: a screen carries no audio to meter.
const hear = marks ? hearingMarks() : null;
+ // Ours has one more cover, over the camera-off one: the words for
+ // a preview the browser will not play, as a button the size of
+ // the tile, since a floating self view on a phone is too small
+ // for a caption with a sentence and a control in it.
+ let paused = null;
+ if (isSelf) {
+ paused = document.createElement('button');
+ paused.type = 'button';
+ paused.className = 'calls-tile-paused';
+ paused.hidden = true;
+ const said = document.createElement('span');
+ said.textContent = SELF_PAUSED;
+ const show = document.createElement('span');
+ show.className = 'calls-tile-paused-show';
+ show.textContent = SELF_SHOW;
+ paused.append(said, show);
+ paused.addEventListener('click', () => playSelf(t));
+ }
if (marks) {
nameEl.after(marks.muted);
figure.append(marks.off);
+ if (paused) figure.append(paused);
// After Play, so the caption's buttons keep their order.
label.append(hear.box, hear.notice);
}
@@ -6856,6 +6886,9 @@
// clock, the decoder's count, and how long the two have
// disagreed.
renderTime: -1, renderDecoded: -1, renderStalls: 0, renderReplays: 0,
+ // judgeSelf's memory, on the self tile only.
+ selfWatch: isSelf ? { time: -1, since: -1, tries: 0, said: false } : null,
+ pausedCover: paused,
};
tiles.set(key, t);
if (!isSelf) applySink(video);
@@ -6893,7 +6926,15 @@
t.video.srcObject = stream || null;
t.stream = stream || null;
t.track = shown;
- if (shouldPlay(t, isSelf)) startPlaying(key, t);
+ // Ours is asked to play on every binding, not left to `autoplay`:
+ // the attribute is a request a browser may decline (Safari in Low
+ // Power Mode does), and a declined one is a black tile with
+ // nothing said.
+ if (isSelf) {
+ if (stream) playSelf(t);
+ } else if (shouldPlay(t, isSelf)) {
+ startPlaying(key, t);
+ }
}
// The frame counter follows the stream, not the element: a tile
// whose track arrives after it was drawn must still be counted, and
@@ -6905,12 +6946,80 @@
// One note element and one Retry beside it, whichever sentence the
// tile is carrying: `restartIce` is the handler for both, and it
// decides whether a retry means a bare ICE restart or a renewal.
+ // Ours has no connection to retry, and its one sentence is the
+ // self-view watch's cover, which a render must not take down.
+ if (isSelf) {
+ drawSelfNote(t);
+ return;
+ }
const show = !!noteText;
t.note.hidden = !show;
t.retry.hidden = !show;
t.note.textContent = noteText || '';
}
+ // playSelf asks our own element to play. Never startPlaying: a
+ // refusal here is about the preview, not about sound, so it is not
+ // §15.20's audioBlocked and puts up no banner — it puts the words on
+ // our own tile instead, as a button that asks again, at once.
+ function playSelf(t) {
+ let attempt;
+ try {
+ attempt = t.video.play();
+ } catch {
+ return;
+ }
+ if (!attempt || typeof attempt.then !== 'function') return;
+ attempt.then(() => {
+ if (tiles.get('self') === t && t.selfWatch.said) {
+ t.selfWatch.said = false;
+ drawSelfNote(t);
+ }
+ }, (err) => {
+ if (!err || err.name !== 'NotAllowedError' || tiles.get('self') !== t) return;
+ t.selfWatch.said = true;
+ drawSelfNote(t);
+ });
+ }
+
+ // replaySelf is the watch's one repair: the stream handed over again,
+ // which rebuilds the element's pipeline, and play asked for.
+ function replaySelf(t) {
+ if (!t.stream) return;
+ try {
+ t.video.srcObject = null;
+ t.video.srcObject = t.stream;
+ } catch {
+ return;
+ }
+ playSelf(t);
+ }
+
+ function drawSelfNote(t) {
+ const said = !!(t.selfWatch && t.selfWatch.said);
+ t.note.hidden = true;
+ t.note.textContent = '';
+ t.retry.hidden = true;
+ t.play.hidden = true;
+ if (t.pausedCover) t.pausedCover.hidden = !said;
+ }
+
+ // watchSelf runs judgeSelf over our tile, once a second.
+ function watchSelf() {
+ const t = tiles.get('self');
+ if (!t || !t.selfWatch) return;
+ const track = (t.stream && t.stream.getVideoTracks && t.stream.getVideoTracks()[0]) || null;
+ const verdict = judgeSelf(t.selfWatch, {
+ live: !!(track && track.readyState === 'live' && track.enabled && !track.muted),
+ visible: document.visibilityState === 'visible',
+ paused: t.video.paused,
+ time: t.video.currentTime || 0,
+ now: Date.now(),
+ });
+ if (verdict === 'replay') replaySelf(t);
+ else if (verdict === 'say' || verdict === 'clear') drawSelfNote(t);
+ }
+
// startPlaying asks the element to play and, if the browser refuses
// (an autoplay policy that wants a gesture first), offers the gesture
// rather than leaving a still frame nobody can explain. A refusal by
@@ -7366,7 +7475,13 @@
});
}
for (const [key, t] of tiles) {
- if (key !== 'self' && t.video && t.video.paused && shouldPlay(t, false)) startPlaying(key, t);
+ if (key === 'self') {
+ // Ours too (2026-10-21): the system pauses it along with the
+ // rest, and it was the one tile nothing asked again.
+ if (t.video && t.video.paused && t.stream) playSelf(t);
+ continue;
+ }
+ if (t.video && t.video.paused && shouldPlay(t, false)) startPlaying(key, t);
}
}
@@ -7732,6 +7847,47 @@
return !isSelf && !!t.stream && (!t.play || t.play.hidden);
}
+ // judgeSelf is the self view's watch, asked once a second. The self
+ // tile is outside every remote watch above — no decoder, no
+ // connection, nothing to reset — and until 2026-10-21 that left it
+ // outside every recovery too: autoplay was the only thing that ever
+ // started it, so an element the system paused (iOS does, with the
+ // page's media in the background, and leaves the camera running) or
+ // never let start (Low Power Mode refuses autoplay) stayed black for
+ // the rest of the call while the camera went on being sent.
+ //
+ // `w` is the tile's memory between polls; `s` is now: whether the
+ // camera is live, enabled and unmuted, whether the tab is visible,
+ // and the element's paused flag and clock. The answer is '' (nothing
+ // to do), 'replay' (hand the element the stream again and play — once
+ // per stall), 'say' (still stuck after that: put the words up, as a
+ // button that asks again) or 'clear' (playing again, or nothing to show: take them
+ // down). A camera that is off or muted is the off cover's business,
+ // and a hidden tab is comeBack's. Pure, and lifted by name in the
+ // node test.
+ function judgeSelf(w, s) {
+ const moving = !s.paused && s.time > w.time;
+ w.time = s.time;
+ if (!s.live || !s.visible || moving) {
+ w.since = -1;
+ w.tries = 0;
+ if (!w.said) return '';
+ w.said = false;
+ return 'clear';
+ }
+ if (w.since < 0) {
+ w.since = s.now;
+ return '';
+ }
+ if (s.now - w.since < SELF_STUCK_MS) return '';
+ w.since = s.now;
+ w.tries += 1;
+ if (w.tries === 1) return 'replay';
+ if (w.said) return '';
+ w.said = true;
+ return 'say';
+ }
+
// freshStream gives a role a *new* MediaStream over the tracks it
// holds, and puts it back where the role keeps it — which is the half
// the first draft of the replay missed (Codex S4-13). A fresh object
@@ -7788,6 +7944,7 @@
// callback was dropped is put back on the books (Codex S4-6's gate
// found one, and the counter is what every frames assertion reads).
rearmFrames();
+ watchSelf();
// §15.21: every screen's decoded count, for the receiver's watch, and
// (§15.22) the rest of what its statistics say.
const screens = new Map();
diff --git a/internal/callstest/browser_test.go b/internal/callstest/browser_test.go
index 8851e48..252e10d 100644
--- a/internal/callstest/browser_test.go
+++ b/internal/callstest/browser_test.go
@@ -128,6 +128,8 @@ var scenarios = []string{
"autoplay",
"connecting",
"quality",
+ "selfview",
+ "selfviewwebkit",
"scriptless",
}
diff --git a/test/browser/call.mjs b/test/browser/call.mjs
index 05a98ac..0423c2a 100644
--- a/test/browser/call.mjs
+++ b/test/browser/call.mjs
@@ -35,7 +35,7 @@ import { syntheticMedia } from './synthetic-media.mjs';
import { writeSync, mkdirSync, writeFileSync } from 'node:fs';
import { inflateSync } from 'node:zlib';
import { createInterface } from 'node:readline';
-import { chromium } from 'playwright';
+import { chromium, webkit } from 'playwright';
const [origin, sqid, scenario] = process.argv.slice(2);
const cookieName = process.env.CALLS_COOKIE_NAME;
@@ -1273,6 +1273,127 @@ const refuseFirstPlay = () => {
};
};
+// ── the self view (2026-10-21) ───────────────────────────────────────
+//
+// selfTile reads this tab's own tile: whether its <video> has the local
+// stream, whether that stream's camera is live, and whether the element
+// is actually playing it — its clock, its paused flag, its size — plus
+// what the tile says when it is not, and where the tile is (the floating
+// picture-in-picture, the stage or the filmstrip).
+function selfTile(page) {
+ return page.evaluate(() => {
+ const f = document.querySelector('#tiles figure.calls-tile-self');
+ if (!f) return null;
+ const v = f.querySelector('video');
+ const s = v && v.srcObject;
+ const track = s && s.getVideoTracks ? s.getVideoTracks()[0] : null;
+ const cover = f.querySelector('.calls-tile-paused');
+ return {
+ pip: f.classList.contains('calls-tile-pip'),
+ stage: f.hasAttribute('data-stage'),
+ hasStream: !!s,
+ track: track ? track.readyState + (track.enabled ? '' : '/disabled') : 'none',
+ paused: v.paused,
+ time: Math.round(v.currentTime * 100) / 100,
+ width: v.videoWidth,
+ ready: v.readyState,
+ cover: cover && !cover.hidden ? cover.textContent : '',
+ };
+ });
+}
+
+// selfAdvancing waits for the self view to be playing a live camera:
+// not paused, a picture with a size, and its clock moving between two
+// reads. Paused and a still clock is the black tile of 2026-10-21.
+async function selfAdvancing(page, ms = 12000) {
+ return until(async () => {
+ const one = await selfTile(page);
+ if (!one || one.paused || !one.width || !one.track.startsWith('live')) return false;
+ await sleep(600);
+ const two = await selfTile(page);
+ return two && !two.paused && two.time > one.time ? two : false;
+ }, ms);
+}
+
+// selfPainted is whether the self view is a picture on screen and not a
+// black box: a screenshot of the middle of its <video>, and how much of
+// it is neither black nor the tile's own #212121. This is the half the
+// element's clock cannot answer — a compositor that draws a playing
+// video as black (WebKit and a backdrop-filter or a transform, say).
+async function selfPainted(page, which = '#tiles figure.calls-tile-self video') {
+ const box = await page.locator(which).boundingBox();
+ if (!box || box.width < 20 || box.height < 20) return { lit: 0, box };
+ const clip = { x: box.x + box.width * 0.2, y: box.y + box.height * 0.15, width: box.width * 0.6, height: box.height * 0.5 };
+ const img = decodePNG(await shoot(page, { clip }));
+ let lit = 0;
+ for (let j = 0; j < img.height; j++) {
+ for (let i = 0; i < img.width; i++) {
+ const c = img.rgb(i, j);
+ const far = (v) => Math.max(Math.abs(c[0] - v), Math.abs(c[1] - v), Math.abs(c[2] - v)) > 24;
+ if (far(0) && far(33)) lit++;
+ }
+ }
+ return { lit: Math.round((lit / (img.width * img.height)) * 100) / 100 };
+}
+
+// shoot is page.screenshot for a page whose CSP the gate is watching. In
+// WebKit, Playwright's screenshot puts a stylesheet of its own into the
+// page, and WebKit holds that to the page's CSP and reports it — a
+// violation by the instrument, not by the page. Only those reports, and
+// only the ones that arrive while the screenshot is being taken, are
+// taken back off the books.
+const PLAYWRIGHT_STYLE = /^Refused to apply a stylesheet because its hash, its nonce, or 'unsafe-inline' does not appear in the style-src directive/;
+async function shoot(page, opts) {
+ const csp = cspViolations.length;
+ const errs = new Map(Array.from(consoleErrors, ([label, list]) => [label, list.length]));
+ const img = await page.screenshot({ caret: 'initial', ...opts });
+ await sleep(200);
+ const keep = (list, from, text) => {
+ const tail = list.splice(from);
+ list.push(...tail.filter((line) => !PLAYWRIGHT_STYLE.test(text(line))));
+ };
+ keep(cspViolations, csp, (line) => line.replace(/^[^:]*: /, ''));
+ for (const [label, from] of errs) keep(consoleErrors.get(label), from, (line) => line);
+ return img;
+}
+
+// gumTap keeps every stream the room opened, so a scenario can end its
+// tracks as the system would.
+const gumTap = () => {
+ window.__gum = [];
+ const md = navigator.mediaDevices;
+ if (!md || !md.getUserMedia) return;
+ const gum = md.getUserMedia.bind(md);
+ md.getUserMedia = async (c) => {
+ if (window.__noCamera && c && c.video) throw new DOMException('camera busy', 'NotReadableError');
+ const s = await gum(c);
+ window.__gum.push(s);
+ return s;
+ };
+ window.__noCamera = !!sessionStorage.getItem('calls.test.noCamera');
+};
+
+// hideAndShow is the tab going to the background and coming back, the
+// way native-webkit.mjs plays it: visibilityState is the page's to
+// believe, and the event is what room.js listens for. `during` is what
+// the system does meanwhile.
+async function hideAndShow(page, during) {
+ await page.evaluate((what) => {
+ if (what.pauseAll) for (const v of document.querySelectorAll('video')) v.pause();
+ if (what.endTracks) for (const s of window.__gum) for (const t of s.getTracks()) t.stop();
+ let shown = 'hidden';
+ Object.defineProperty(document, 'visibilityState', { configurable: true, get: () => shown });
+ Object.defineProperty(document, 'hidden', { configurable: true, get: () => shown === 'hidden' });
+ document.dispatchEvent(new Event('visibilitychange'));
+ window.__show = () => {
+ shown = 'visible';
+ document.dispatchEvent(new Event('visibilitychange'));
+ };
+ }, during);
+ await sleep(1000);
+ await page.evaluate(() => window.__show());
+}
+
// glowOf is the warm rim on a tile's name label as it is drawn (0.4.3):
// whether it is lit, its --lvl and --on, the shadow the browser computed
// for the label's ::after from them, and the most opaque of that shadow's
@@ -6134,6 +6255,15 @@ const run = {
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
+ // picture can be handed to its element, or taken from it, followed by
+ // the one thing that matters: the element is playing a live camera.
+ // A in a phone-sized window, so a call of two floats the self view.
+ async selfview() { await selfView('chromium'); },
+ async selfviewwebkit() { await selfView('webkit'); },
+
async scriptless() {
const ctx = await newContext('scriptless', { cookie: cookieA, javaScriptEnabled: false });
const sentence = 'The call needs JavaScript to reach your camera and the other participants; everything else on this page works without it.';
@@ -6172,6 +6302,156 @@ const run = {
},
};
+// selfView is both engines' scenario. B and the guest are Chromium
+// whichever engine A is in: only A's own tile is under test.
+async function selfView(engine) {
+ const wk = engine === 'webkit' ? await webkit.launch({ headless: true }) : null;
+ const options = { viewport: { width: 390, height: 844 } };
+ if (wk) options.permissions = ['camera', 'microphone'];
+ try {
+ const ctxA = await newContext('self A', { cookie: cookieA, via: wk || browser, options });
+ await ctxA.addInitScript(gumTap);
+ const ctxB = await newContext('self B', { cookie: cookieB });
+ const ctxG = await newContext('self guest');
+ const pageA = await openRoom(ctxA);
+ const pageB = await openRoom(ctxB);
+ const pair = await assertPair(pageA, pageB, engine + ' A', 'B');
+ if (!pair) return;
+ const say = async (what) => engine + ': ' + what + ' (' + JSON.stringify(await selfTile(pageA)) + ')';
+
+ const first = await selfAdvancing(pageA);
+ check(first, await say('the self view plays in a call of two'));
+ check(first && first.pip, await say('and floats, in a phone-sized window'));
+ const painted = await until(async () => {
+ const p = await selfPainted(pageA);
+ return p.lit > 0.01 ? p : false;
+ }, 5000);
+ check(painted, engine + ': and is a picture on screen, not a black box (' + JSON.stringify(painted || (await selfPainted(pageA))) +
+ '; the stage beside it: ' + JSON.stringify(await selfPainted(pageA, '#tiles > [data-stage] video')) + ')');
+ const shots = process.env.CALLS_SELF_SNAPSHOTS;
+ if (shots) mkdirSync(shots, { recursive: true });
+ const shot = async (name) => { if (shots) await shoot(pageA, { path: shots + '/' + engine + '-' + name + '.png' }); };
+ await shot('pip');
+
+ // The camera off and on again: the track is disabled, not replaced,
+ // and the picture has to come back with it.
+ await pageA.evaluate(() => document.getElementById('camera').click());
+ await until(async () => (await selfTile(pageA)).track.endsWith('/disabled'), 5000);
+ await pageA.evaluate(() => document.getElementById('camera').click());
+ check(await selfAdvancing(pageA), await say('the self view plays after the camera is turned off and on'));
+
+ // The system pausing the page's media in the background and leaving
+ // the tracks alone (iOS does this; Low Power Mode more readily).
+ await hideAndShow(pageA, { pauseAll: true });
+ check(await selfAdvancing(pageA), await say('the self view plays again when the tab is back after its media was paused'));
+
+ // The system ending the camera and microphone outright: comeBack
+ // opens them again, and the new camera must reach the self view.
+ await hideAndShow(pageA, { pauseAll: true, endTracks: true });
+ check(await selfAdvancing(pageA, 15000), await say('the self view plays the reopened camera when the tab is back'));
+
+ // The element stopping with no event to say so: the self-view watch
+ // has to notice by itself.
+ await pageA.evaluate(() => document.querySelector('#tiles figure.calls-tile-self video').pause());
+ check(await selfAdvancing(pageA, 10000), await say('a self view paused behind the page’s back plays again by itself'));
+
+ // A browser that will not play it at all (Low Power Mode refusing
+ // autoplay): never a black box with nothing said. The tile says the
+ // preview is paused, as a button, and the button brings it back.
+ await pageA.evaluate(() => {
+ const real = HTMLMediaElement.prototype.play;
+ window.__realPlay = real;
+ HTMLMediaElement.prototype.play = function play() {
+ if (this.closest && this.closest('.calls-tile-self')) {
+ this.pause();
+ return Promise.reject(new DOMException('preview refused', 'NotAllowedError'));
+ }
+ return real.apply(this, arguments);
+ };
+ const v = document.querySelector('#tiles figure.calls-tile-self video');
+ v.autoplay = false;
+ v.pause();
+ });
+ const said = await until(async () => {
+ const t = await selfTile(pageA);
+ return t && t.paused && t.cover ? t : false;
+ }, 10000);
+ check(said && said.cover === 'Your camera preview is paused.Show it', await say('a self view that will not play says so, as a button'));
+ const cover = await pageA.locator('#tiles figure.calls-tile-self .calls-tile-paused').boundingBox();
+ const tileBox = await pageA.locator('#tiles figure.calls-tile-self').boundingBox();
+ check(cover && tileBox && Math.abs(cover.width - tileBox.width) < 1 && Math.abs(cover.height - tileBox.height) < 1,
+ engine + ': the button covers the whole floating tile (' + JSON.stringify({ cover, tileBox }) + ')');
+ await shot('paused');
+ const s = await state(pageA);
+ check(!s.audioBlocked && !s.soundBanner, 'and that is not mistaken for sound being blocked (' + JSON.stringify({ blocked: s.audioBlocked, banner: s.soundBanner }) + ')');
+ await pageA.evaluate(() => { HTMLMediaElement.prototype.play = window.__realPlay; });
+ await pageA.locator('#tiles figure.calls-tile-self .calls-tile-paused').click();
+ const back = await selfAdvancing(pageA);
+ check(back && !back.cover, await say('the button brings the self view back and the words go'));
+
+ // A third person: the self view leaves the corner for the filmstrip
+ // and still plays.
+ await signInAsGuest(ctxG);
+ await openRoom(ctxG);
+ check(await until(async () => (await pageA.locator('#knocks li').count()) >= 1 && await admitKnock(pageA, 'guest'), 20000),
+ 'A lets the guest in (' + JSON.stringify(await queueNames(pageA)) + ')');
+ const three = await until(async () => ((await state(pageA)).peers.length === 2 ? true : false), 30000);
+ check(three, engine + ': A is in a call of three');
+ const strip = await until(async () => {
+ const t = await selfTile(pageA);
+ return t && !t.pip ? t : false;
+ }, 10000);
+ check(strip, await say('in a call of three the self view is in the filmstrip, not floating'));
+ check(await selfAdvancing(pageA), await say('and plays there'));
+ check((await selfPainted(pageA)).lit > 0.01, engine + ': and is a picture there too (' + JSON.stringify(await selfPainted(pageA)) + ')');
+ await pageA.evaluate(() => document.getElementById('camera').click());
+ await until(async () => (await selfTile(pageA)).track.endsWith('/disabled'), 5000);
+ await pageA.evaluate(() => document.getElementById('camera').click());
+ check(await selfAdvancing(pageA), await say('and after the camera is turned off and on there'));
+ await hideAndShow(pageA, { pauseAll: true, endTracks: true });
+ check(await selfAdvancing(pageA, 15000), await say('and after the tab comes back with its camera reopened'));
+
+ for (const page of ctxG.pages()) await leaveRoom(page);
+ await leaveRoom(pageB);
+
+ // Joining with no camera, which arrives later from the device panel:
+ // the self view was drawn for a stream with no picture in it, and
+ // the camera that comes later has to reach it.
+ await leaveRoom(pageA);
+ await pageA.evaluate(() => sessionStorage.setItem('calls.test.noCamera', '1'));
+ await pageA.goto(origin + '/m/' + sqid, { waitUntil: 'domcontentloaded' });
+ await pageA.waitForFunction(() => !!window.meet, null, { timeout: 20000 });
+ const alone = await until(async () => {
+ const t = await selfTile(pageA);
+ return t && t.track === 'none' ? t : false;
+ }, 15000);
+ check(alone, await say('A joins with no camera'));
+ await pageA.evaluate(() => { window.__noCamera = false; sessionStorage.removeItem('calls.test.noCamera'); });
+ // Through the picker's own change event: on a phone the Devices
+ // panel is behind the controls sheet, and which button opens it is
+ // not what this is about.
+ const camera = await until(async () => await pageA.evaluate(() => {
+ const pick = document.getElementById('pick-camera');
+ return pick && pick.options.length ? pick.options[0].value || ' ' : false;
+ }), 10000);
+ check(camera, 'the room lists a camera to choose');
+ await pageA.evaluate(() => {
+ const pick = document.getElementById('pick-camera');
+ pick.value = pick.options[0].value;
+ pick.dispatchEvent(new Event('change', { bubbles: true }));
+ });
+ check(await selfAdvancing(pageA, 15000), await say('the camera chosen later plays in the self view'));
+
+ check(errorsFor('self A') === '', 'no console errors in A (' + errorsFor('self A') + ')');
+ await leaveRoom(pageA);
+ await ctxA.close();
+ await ctxB.close();
+ await ctxG.close();
+ } finally {
+ if (wk) await wk.close();
+ }
+}
+
// ── run it ───────────────────────────────────────────────────────────
const watchdog = setTimeout(() => {
diff --git a/test/browser/room-self.test.mjs b/test/browser/room-self.test.mjs
new file mode 100644
index 0000000..03181d7
--- /dev/null
+++ b/test/browser/room-self.test.mjs
@@ -0,0 +1,187 @@
+// room-self.test.mjs — the self view is played, watched and, when the
+// browser will not play it, explained (2026-10-21: an iPhone in Safari
+// showed its own picture black for a whole call while sending it).
+//
+// node --test test/browser/room-self.test.mjs
+//
+// judgeSelf, playSelf and comeBack lifted out of the shipped room.js by
+// name, with the constants they read, as room-reconnect.test.mjs does.
+// The browser half is call.mjs's `selfview` and `selfviewwebkit`.
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import { fileURLToPath } from 'node:url';
+
+const src = readFileSync(fileURLToPath(new URL('../../internal/calls/static/room.js', import.meta.url)), 'utf8');
+
+function lift(name) {
+ const start = src.indexOf('function ' + name + '(');
+ assert.notEqual(start, -1, name + ' is not in room.js any more — this test is stale, not passing');
+ let depth = 0;
+ for (let i = src.indexOf('{', start); i < src.length; i++) {
+ if (src[i] === '{') depth += 1;
+ else if (src[i] === '}') {
+ depth -= 1;
+ if (depth === 0) return src.slice(start, i + 1);
+ }
+ }
+ assert.fail('unbalanced braces reading ' + name);
+}
+function liftConst(name) {
+ const m = src.match(new RegExp('const ' + name + ' = ([0-9.]+);'));
+ assert.ok(m, name + ' is not a numeric const in room.js any more');
+ return 'const ' + name + ' = ' + m[1] + ';';
+}
+
+// eslint-disable-next-line no-new-func
+const judgeSelf = new Function(liftConst('SELF_STUCK_MS') + '\n' + lift('judgeSelf') + '; return judgeSelf;')();
+const STUCK = Number(liftConst('SELF_STUCK_MS').match(/= ([0-9.]+)/)[1]);
+
+const fresh = () => ({ time: -1, since: -1, tries: 0, said: false });
+const live = (now, time, paused = false) => ({ live: true, visible: true, paused, time, now });
+
+// Once a second from `from` for `n` polls, the element's clock and paused
+// flag from `at(now)`; the verdicts that were not empty, with their times.
+function poll(w, from, n, at) {
+ const out = [];
+ for (let i = 0; i < n; i++) {
+ const now = from + i * 1000;
+ const v = judgeSelf(w, { live: true, visible: true, now, ...at(now) });
+ if (v) out.push([now, v]);
+ }
+ return out;
+}
+
+test('a self view that is playing is left alone', () => {
+ const w = fresh();
+ assert.deepEqual(poll(w, 0, 10, (now) => ({ paused: false, time: now / 1000 })), []);
+});
+
+test('a paused self view is replayed once, then said, two seconds apart', () => {
+ const w = fresh();
+ const got = poll(w, 0, 8, () => ({ paused: true, time: 3 }));
+ assert.deepEqual(got, [[STUCK, 'replay'], [2 * STUCK, 'say']]);
+ assert.equal(w.said, true);
+});
+
+test('a self view that is not paused but whose clock stands still counts as stuck', () => {
+ const w = fresh();
+ const got = poll(w, 0, 6, () => ({ paused: false, time: 1.5 }));
+ assert.deepEqual(got.map(([, v]) => v), ['replay', 'say']);
+});
+
+test('the words come down as soon as the picture moves again, and the watch starts over', () => {
+ const w = fresh();
+ poll(w, 0, 6, () => ({ paused: true, time: 3 }));
+ assert.equal(w.said, true);
+ assert.equal(judgeSelf(w, live(6000, 3.2)), 'clear');
+ assert.equal(w.said, false);
+ assert.equal(w.tries, 0);
+ // A second stall gets its own replay before anything is said.
+ const again = poll(w, 7000, 6, () => ({ paused: true, time: 3.2 }));
+ assert.deepEqual(again.map(([, v]) => v), ['replay', 'say']);
+});
+
+test('a replay that works is never said', () => {
+ const w = fresh();
+ let t = 2;
+ const got = poll(w, 0, 10, (now) => (now <= STUCK ? { paused: true, time: t } : { paused: false, time: (t += 1) }));
+ assert.deepEqual(got.map(([, v]) => v), ['replay']);
+ assert.equal(w.said, false);
+});
+
+test('a camera that is off, muted or ended, or a hidden tab, is not the watch’s business', () => {
+ for (const s of [{ live: false, visible: true }, { live: true, visible: false }]) {
+ const w = fresh();
+ for (let now = 0; now < 10000; now += 1000) {
+ assert.equal(judgeSelf(w, { ...s, paused: true, time: 0, now }), '');
+ }
+ assert.equal(w.tries, 0);
+ }
+ // And one that goes off while the words are up takes them down: the
+ // camera-off cover says what there is to say.
+ const w = fresh();
+ poll(w, 0, 6, () => ({ paused: true, time: 0 }));
+ assert.equal(w.said, true);
+ assert.equal(judgeSelf(w, { live: false, visible: true, paused: true, time: 0, now: 7000 }), 'clear');
+});
+
+test('a clock that went backwards (a new binding) is a start, not a stall cleared', () => {
+ const w = fresh();
+ judgeSelf(w, live(0, 9));
+ // Rebinding resets the element's clock: not moving, so the watch starts
+ // its two seconds rather than calling it playing.
+ assert.equal(judgeSelf(w, live(1000, 0)), '');
+ assert.equal(judgeSelf(w, live(2000, 0.6)), '');
+ assert.equal(w.since, -1);
+});
+
+// playSelf over a fake element: what a refusal and a success do to the
+// tile, and that neither is ever §15.20's sound refusal.
+function playHarness(result) {
+ const drawn = [];
+ const t = {
+ video: { play: () => result },
+ selfWatch: { time: -1, since: -1, tries: 0, said: false },
+ };
+ const tiles = new Map([['self', t]]);
+ // eslint-disable-next-line no-new-func
+ const playSelf = new Function('tiles', 'drawSelfNote', 'soundRefused', 'startPlaying',
+ lift('playSelf') + '; return playSelf;')(tiles, (x) => drawn.push(x.selfWatch.said),
+ () => assert.fail('a self view is never a sound refusal'),
+ () => assert.fail('a self view never goes through startPlaying'));
+ return { t, drawn, playSelf };
+}
+
+test('a refused preview is said at once, on the tile', async () => {
+ const h = playHarness(Promise.reject(new DOMException('no', 'NotAllowedError')));
+ h.playSelf(h.t);
+ await new Promise((r) => setTimeout(r, 0));
+ assert.equal(h.t.selfWatch.said, true);
+ assert.deepEqual(h.drawn, [true]);
+});
+
+test('a play that was only interrupted (AbortError) says nothing', async () => {
+ const h = playHarness(Promise.reject(new DOMException('new load', 'AbortError')));
+ h.playSelf(h.t);
+ await new Promise((r) => setTimeout(r, 0));
+ assert.equal(h.t.selfWatch.said, false);
+ assert.deepEqual(h.drawn, []);
+});
+
+test('a play that works takes the words down', async () => {
+ const h = playHarness(Promise.resolve());
+ h.t.selfWatch.said = true;
+ h.playSelf(h.t);
+ await new Promise((r) => setTimeout(r, 0));
+ assert.equal(h.t.selfWatch.said, false);
+ assert.deepEqual(h.drawn, [false]);
+});
+
+// comeBack over fakes: the self tile is asked to play again along with
+// the remote ones — the line whose absence left it black.
+test('the tab coming back plays a paused self view, through playSelf', () => {
+ const played = [];
+ const started = [];
+ const selfT = { video: { paused: true }, stream: {} };
+ const remote = { video: { paused: true }, stream: {}, play: { hidden: true } };
+ const tiles = new Map([['self', selfT], ['peer1', remote]]);
+ const local = { getAudioTracks: () => [], getVideoTracks: () => [] };
+ // eslint-disable-next-line no-new-func
+ const comeBack = new Function('state', 'local', 'lostKinds', 'prefs', 'switchDevice', 'tiles', 'shouldPlay',
+ 'startPlaying', 'playSelf', lift('comeBack') + '; return comeBack;')(
+ { stopped: false, leaveSent: false }, local, () => [], {}, () => Promise.resolve(), tiles,
+ (t, isSelf) => !isSelf && !!t.stream, (key) => started.push(key), (t) => played.push(t));
+ comeBack();
+ assert.deepEqual(played, [selfT]);
+ assert.deepEqual(started, ['peer1']);
+});
+
+// The binding: tile() hands ours to playSelf whenever it binds a stream,
+// rather than trusting `autoplay`. tile() builds DOM and is not lifted;
+// this holds the one line in place.
+test('tile() asks the self view to play on every binding', () => {
+ const body = lift('tile');
+ assert.match(body, /if \(isSelf\) \{\s*if \(stream\) playSelf\(t\);/);
+ assert.match(lift('pollFrames'), /watchSelf\(\);/);
+});