Public: anyone can read this; the crew can change it.

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Phone watchers see the last 3 chat lines faintly over the bottom of the video, never while driving #378

Merged opened this

Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.

Merged

smith/arm:smith/288-phone-watchers-see-the-last-3-chat-lines → main 1 commit fork 1 thread · 1 unresolved

  • Merged. smith/288-phone-watchers-see-the-last-3-chat-lines was merged into main as 07ff7bf.

Review

Sign in to review this change.
5 files changed +123 −1
Software/so101/src/ui/chat-glass.js added +68
@@ -0,0 +1,68 @@
1 // @ts-check
2 /**
3 * The last chat lines faintly over the bottom of the camera, for someone who is watching on a phone held upright
4 * (ui/mobile.css draws #chatGlass in the camera's row only, so it never covers the model). The driver never sees it.
5 * Lines fade after a few seconds, and a tap hides what is showing. Text only: the page uses textContent.
6 */
7
8 const SHOWN = 3;
9 const MAX = 160;
10
11 /** @param {{ now?: () => number, ttl?: number }} [o] */
12 export function createGlass({ now = Date.now, ttl = 6000 } = {}) {
13 /** @type {Array<{ name: string, text: string, at: number }>} */ let lines = [];
14 let hiddenAt = -Infinity;
15 return {
16 push(/** @type {string} */ name, /** @type {string} */ text) {
17 // eslint-disable-next-line no-control-regex
18 const t = String(text).replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, MAX);
19 if (t) lines = [...lines, { name: String(name).slice(0, 40), text: t, at: now() }].slice(-SHOWN);
20 },
21 /** A tap on the video hides the lines showing now; a line that arrives later shows again. */
22 tap() { hiddenAt = now(); },
23 /** The lines to draw: the last 3 that are still fresh and not tapped away; none while driving. */
24 show(/** @type {boolean} */ driving) {
25 if (driving) return [];
26 const t = now();
27 return lines.filter((l) => t - l.at < ttl && l.at > hiddenAt);
28 },
29 /** Milliseconds until the oldest showing line fades, or 0 when none shows. */
30 nextFade(/** @type {boolean} */ driving) {
31 const s = this.show(driving);
32 return s.length ? Math.max(1, ttl - (now() - s[0].at)) : 0;
33 },
34 };
35 }
36
37 /**
38 * @param {HTMLElement} box the overlay
39 * @param {(tag: string, props?: object) => HTMLElement} el
40 * @param {() => boolean} mayDrive
41 */
42 export function mountGlass(box, el, mayDrive) {
43 const glass = createGlass();
44 /** @type {any} */ let timer = 0;
45 function render() {
46 clearTimeout(timer);
47 const lines = glass.show(mayDrive());
48 box.replaceChildren(...lines.map((l) => line(el, l)));
49 const wait = glass.nextFade(mayDrive());
50 if (wait) timer = setTimeout(render, wait);
51 }
52 box.addEventListener("click", () => { glass.tap(); render(); });
53 return {
54 said(/** @type {Array<{ from?: { name: string }, text: string }>} */ messages) {
55 for (const m of messages) if (m.from) glass.push(m.from.name, m.text);
56 render();
57 },
58 /** The turn changed hands: a driver's lines go at once. */
59 refresh: render,
60 };
61 }
62
63 /** @param {(tag: string, props?: object) => HTMLElement} el @param {{ name: string, text: string }} l */
64 function line(el, l) {
65 const d = el("div", { className: "gl" });
66 d.append(el("b", { textContent: l.name }), el("span", { textContent: l.text }));
67 return d;
68 }
Software/so101/src/ui/chat-glass.test.ts added +39
@@ -0,0 +1,39 @@
1 import { describe, expect, test } from "bun:test";
2 import { createGlass } from "./chat-glass.js";
3
4 function room() {
5 let t = 1000;
6 const g = createGlass({ now: () => t, ttl: 6000 });
7 for (const n of ["a", "b", "c", "d"]) { g.push(n, `hi from ${n}`); t += 100; }
8 return { g, at: (ms: number) => { t = ms; } };
9 }
10
11 describe("chat over the camera", () => {
12 test("a watcher sees the last 3 lines, a driver sees 0", () => {
13 const { g } = room();
14 expect(g.show(false).map((l) => l.name)).toEqual(["b", "c", "d"]);
15 expect(g.show(true)).toEqual([]);
16 });
17 test("lines fade after a few seconds", () => {
18 const { g, at } = room();
19 at(1000 + 6150);
20 expect(g.show(false).map((l) => l.name)).toEqual(["c", "d"]);
21 at(1000 + 7000);
22 expect(g.show(false)).toEqual([]);
23 expect(g.nextFade(false)).toBe(0);
24 });
25 test("a tap hides them, and a later line shows again", () => {
26 const { g, at } = room();
27 at(1500); g.tap();
28 expect(g.show(false)).toEqual([]);
29 at(1600); g.push("e", "back");
30 expect(g.show(false).map((l) => l.name)).toEqual(["e"]);
31 });
32 test("text is kept as text: control characters go and the length is bounded", () => {
33 const g = createGlass();
34 g.push("x", "<img src=x onerror=1>\n" + "z".repeat(500));
35 const [l] = g.show(false);
36 expect(l!.text).not.toContain("\n");
37 expect(l!.text.length).toBe(160);
38 });
39 });
Software/so101/src/ui/lobby-panel.js +2 −1
@@ -32,7 +32,7 @@ export const backoff = (attempt) => Math.min(250 * 2 ** Math.max(0, attempt - 1)
3232 const tell = (what) => /** @type {any} */ (globalThis).dispatchEvent?.(new Event(what));
3333
3434 /**
35 * @param {any} page what the page owns: $, el, relayed, tab(), showTab, msg, applyLock, applyStatus, noStatus, words, admin, note
35 * @param {any} page what the page owns: said(lines) for new chat lines, $, el, relayed, tab(), showTab, msg, applyLock, applyStatus, noStatus, words, admin, note
3636 */
3737 export function createRoom(page) {
3838 const { $, el, relayed, msg } = page;
@@ -225,6 +225,7 @@ export function createRoom(page) {
225225 const atEnd = chatBox.scrollHeight - chatBox.scrollTop - chatBox.clientHeight < 40;
226226 if (replace) chatBox.replaceChildren();
227227 chatBox.append(...lines.map(chatLine));
228 if (!replace) page.said?.(lines);
228229 if (!replace) while (chatBox.querySelectorAll(".line").length > 200) chatBox.querySelector(".line").remove();
229230 if (atEnd || replace) toEnd();
230231 else if (lines.length) pill.hidden = false; // the reader is up in the history: keep the place, offer the way down
Software/so101/src/ui/mobile.css +5
@@ -17,6 +17,11 @@
1717 #stage { display: contents; }
1818 #stage > .pane { grid-row: 1; grid-column: 1; min-height: 0; }
1919 #stage > #pane3 { grid-row: 3; }
20 /* Chat over the camera for a watcher (ui/chat-glass.js): in the camera's row only, never over the model; text, faint, 3 lines. */
21 #chatGlass { grid-row: 1; grid-column: 1; align-self: end; z-index: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l)); min-width: 0; }
22 #chatGlass:empty { display: none; }
23 #chatGlass .gl { font-size: 13px; line-height: 1.3; color: rgba(255,255,255,.8); text-shadow: 0 1px 2px #000; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

The overlay is a click target over the camera. Add pointer-events:none, or keep it and check on a phone that it does not eat video taps.

24 #chatGlass .gl b { margin-right: 6px; font-weight: 650; }
2025 /* The strip sits over the view's middle row, so it paints above it. */
2126 #strip { position: relative; z-index: 1; }
2227 /* The model is always on here, so its view button goes; the camera buttons pick which camera is on top. */
Software/so101/src/viewer.html +9
@@ -51,6 +51,7 @@
5151 input[type=number] { width: 88px; }
5252 label.inline { display: inline-flex; gap: 8px; align-items: center; color: var(--dim); font-size: 13px; }
5353 #tableNote { min-height: 3em; }
54 #chatGlass { display: none; } /* ui/mobile.css shows it on a phone held upright */
5455 #msg { overflow-wrap: anywhere; }
5556 .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
5657 [hidden] { display: none !important; }
@@ -281,6 +282,7 @@
281282 <button id="fs" title="F">Fullscreen</button>
282283 </div>
283284 <div id="driverTag" aria-hidden="true"></div>
285 <div id="chatGlass" aria-hidden="true"></div>
284286 <div id="banner" role="alert"></div>
285287 <div id="msg" role="status"></div>
286288 <div id="refusal" role="status"></div>
@@ -1304,10 +1306,16 @@
13041306 // The page follows suit: the Controls tab appears on your turn. Everything here arrives on one socket.
13051307 let wordsSent = false;
13061308 $("wordsForm").addEventListener("submit", (e) => { e.preventDefault(); wordsSent = true; say({ type: "words", words: $("wordsForm").elements.words.value.split(",").map((w) => w.trim()).filter(Boolean) }); });
1309 /** @type {Promise<any> | undefined} */ let glass;
13071310 const fallback = {}; // the last text per key, shown on the hold line when the notes module will not load
13081311 const note = noteSink(() => import("/ui/__VERSION__/notes.js").then((m) => m.mountNotes($, el)), (k, t) => { fallback[k] = t; $("holdLine").textContent = Object.values(fallback).join(" "); });
13091312 const room = createRoom({
13101313 $, el, relayed, msg, note, tab: () => tab, showTab, applyLock: () => applyLock(), applyStatus: (s) => applyStatus(s), noStatus: () => noStatus(),
1314 said(lines) { // phone portrait, watching: the last lines faintly over the camera (ui/chat-glass.js)
1315 if (!stacked.matches) return;
1316 glass ??= import("/ui/__VERSION__/chat-glass.js").then((m) => m.mountGlass($("chatGlass"), el, () => room.mayDrive()), () => null);
1317 glass.then((g) => g?.said(lines));
1318 },
13111319 words(m) { const f = $("wordsForm"); if (document.activeElement !== f.elements.words) f.elements.words.value = m.words.join(", "); if (wordsSent) { wordsSent = false; msg(`Word filter saved: ${m.words.length} word${m.words.length === 1 ? "" : "s"}.`); } },
13121320 admin: (saved) => fillAdmin(saved),
13131321 });
@@ -1340,6 +1348,7 @@
13401348 // Your turn just came: open the controls. It just ended: back to the chat.
13411349 if (mayDrive() !== drove) {
13421350 drove = mayDrive();
1351 glass?.then((g) => g?.refresh());
13431352 if (relayed && phone.matches && dock) dock.go(drove ? "drive" : dock.panel === "drive" ? "chat" : dock.panel, true);
13441353 else if (relayed) showTab(drove ? "controls" : "chat");
13451354 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs