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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

The status strip shows '12 here · 4 signed in · 8 watching' from the /live presence frame, with its space reserved so nothing shifts #376

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/359-the-status-strip-shows-12-here-4-signed → main 2 commits fork 2 threads · 2 unresolved

  • Merged. smith/359-the-status-strip-shows-12-here-4-signed was merged into main as 70c9eec.

Review

Sign in to review this change.
6 files changed +71 −5
Software/README.md +5 −1
@@ -618,7 +618,11 @@ drives, your place in the line, the time left, the turn's one button, and
618618 the red **Stop**. Stop is there whenever you drive, and for the owner. Held
619619 upright (up to 600 px wide), the view is pinned to the top in a 16:9 box kept
620620 free before the first frame arrives, so nothing jumps when the picture
621 does. The strip under it is the one status line: the arm live or
621 does. The strip also carries a quiet line of who is in the room, "12 here ·
622 4 signed in · 8 watching", from the `/live` presence frame (its row is held
623 from the first paint, so nothing shifts when it arrives, and screen readers are
624 not told of every change); the terminal prints the same text after `/who`.
625 The strip under it is the one status line: the arm live or
622626 reconnecting moves there from over the picture (`src/ui/mobile.css`). Below
623627 that is a sheet with tabs at the bottom edge: **Chat**, **Queue**,
624628 **Controls** (only on your turn, and it opens by itself when your turn
Software/so101/src/terminal.test.ts +11
@@ -523,3 +523,14 @@ describe("terminal door", () => {
523523 await waitFor(() => (alice.printed.filter((l) => /^resumed/.test(l)).length === 2 ? true : undefined), "the owner's resume on alice's terminal");
524524 });
525525 });
526
527 describe("the terminal's presence line", () => {
528 test("/who ends with the latest good presence frame, and a bad one changes nothing", () => {
529 const room = emptyRoom();
530 expect(typed(room, "/who")).toEqual({ print: "nobody has control · nobody waiting" });
531 expect(hear(room, { type: "presence", here: 12, signedIn: 4, watching: 8 })).toEqual([]);
532 expect(typed(room, "/who")).toEqual({ print: "nobody has control · nobody waiting · 12 here · 4 signed in · 8 watching" });
533 hear(room, { type: "presence", here: 1 });
534 expect(room.presence).toBe("12 here · 4 signed in · 8 watching");
535 });
536 });
Software/so101/src/terminal.ts +8 −2
@@ -38,6 +38,7 @@
3838 import WebSocket from "ws";
3939 import { UNPRINTABLE } from "./chat.ts";
4040 import { ID, NAME, sign } from "./identity.ts";
41 import { presenceText } from "./ui/lobby-panel.js";
4142 import { entryLine, jointRows, linkRows, stateRows } from "./ui/machine.js";
4243
4344 export type Env = Record<string, string | undefined>;
@@ -145,9 +146,11 @@ export interface Room {
145146 seen: Map<string, Someone>;
146147 /** The reports the owner or a moderator was last sent, newest first; null until the first list (the one on join). */
147148 reports: Array<Record<string, unknown>> | null;
149 /** The latest presence line, "12 here · 4 signed in · 8 watching"; null until a good frame. */
150 presence: string | null;
148151 }
149152
150 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, held: undefined, told: { called: false, next: false }, seen: new Map(), latest: new Map(), reports: null });
153 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, held: undefined, told: { called: false, next: false }, seen: new Map(), latest: new Map(), reports: null, presence: null });
151154
152155 const someone = (x: unknown): Someone | null => {
153156 if (typeof x !== "object" || x === null) return null;
@@ -219,6 +222,9 @@ function cues(room: Room, driver: unknown): string[] {
219222 /** Fold one server frame into the room; what to print for it, if anything. */
220223 export function hear(room: Room, frame: Frame): string[] {
221224 switch (frame.type) {
225 case "presence":
226 room.presence = presenceText(frame) ?? room.presence;
227 return [];
222228 case "hello": {
223229 const you = someone(frame.you);
224230 const was = { you: room.you, muted: room.muted, banned: room.banned };
@@ -290,7 +296,7 @@ const reportLine = (x: Record<string, unknown>): string => `report #${plain(x.id
290296
291297 export function who(room: Room): string {
292298 const line = room.queue.length ? room.queue.map((p, i) => `${i + 1}. ${plain(p.name)}`).join(" ") : "nobody waiting";
293 return `${room.paused ? "paused · " : ""}${room.driver ? `${plain(room.driver.name)} has control` : "nobody has control"} · ${line}`;
299 return `${room.paused ? "paused · " : ""}${room.driver ? `${plain(room.driver.name)} has control` : "nobody has control"} · ${line}${room.presence ? ` · ${room.presence}` : ""}`;
294300 }
295301
296302 /** A typed <who>: a name the door has seen, else taken as an id. */
Software/so101/src/ui/lobby-panel.js +7
@@ -25,6 +25,12 @@ export function queueEntry(el, x, mine) {
2525 /** Only a signed-in person reports, and only what someone else said. @param {any} m a chat message @param {any} me hello.you */
2626 export const mayReport = (m, me) => Boolean(me && m.from && m.from.id !== me.id);
2727
28 /** @param {any} m a presence frame @returns {string | null} "12 here · 4 signed in · 8 watching", or null unless all three are counts */
29 export function presenceText(m) {
30 const ok = (/** @type {any} */ n) => Number.isSafeInteger(n) && n >= 0;
31 return m && ok(m.here) && ok(m.signedIn) && ok(m.watching) ? `${m.here} here · ${m.signedIn} signed in · ${m.watching} watching` : null;
32 }
33
2834 /** @param {number} attempt 1 for the first retry @returns {number} ms to wait: 250, 500, 1000, then 2000 at most */
2935 export const backoff = (attempt) => Math.min(250 * 2 ** Math.max(0, attempt - 1), 2000);
3036
@@ -273,6 +279,7 @@ export function createRoom(page) {
273279 if (lobby.retry) { lobby.retry = 0; $("reconnect").classList.remove("on"); } // the first message: it is back
274280 const m = JSON.parse(e.data);
275281 if (m.type === "ping") return say({ type: "pong" });
282 if (m.type === "presence") { const t = presenceText(m); if (t !== null) $("presenceLine").textContent = t; return; }

This handler branch has no test, so the wiring is unguarded. Test it through createRoom with a presence frame and a bad one. The terminal door in src/tty.ts has no presence line either.

276283 if (m.type === "status") { tell("pose"); lobby.statusSeen = true; return m.status ? page.applyStatus(m.status) : page.noStatus(); }
277284 if (m.type === "hello") lobby.hello = m;
278285 else if (m.type === "state") { lobby.offset = m.now - Date.now(); lobby.state = m; }
Software/so101/src/ui/lobby-panel.test.ts +38 −1
@@ -1,5 +1,5 @@
11 import { describe, expect, test } from "bun:test";
2 import { backoff, createRoom, mayReport, minutes, ordinal, queueEntry, waitMinutes } from "./lobby-panel.js";
2 import { backoff, createRoom, mayReport, minutes, ordinal, presenceText, queueEntry, waitMinutes } from "./lobby-panel.js";
33
44 /** A stand-in for the page's el(): elements as plain trees, so the test needs no DOM. */
55 const el = (tag: string, props: Record<string, unknown> = {}, ...children: unknown[]) => ({ tag, ...props, children });
@@ -64,6 +64,29 @@ describe("the room over /live", () => {
6464 } finally { Object.assign(g, saved); }
6565 });
6666
67 test("a presence frame writes #presenceLine through textContent and a bad frame leaves it alone", () => {
68 const sockets: any[] = [];
69 const g = globalThis as any, saved = { WebSocket: g.WebSocket, setInterval: g.setInterval, location: g.location };
70 g.WebSocket = class { readyState = 1; sent: string[] = []; constructor() { sockets.push(this); } send(m: string) { this.sent.push(m); } };
71 g.setInterval = () => 0;
72 g.location = { protocol: "http:", host: "x", pathname: "/", search: "" };
73 try {
74 const nodes = new Map<string, any>();
75 const page = {
76 $: (id: string) => nodes.get(id) ?? (nodes.set(id, node()), nodes.get(id)),
77 el: (tag: string, props: object = {}) => Object.assign(node(), { tag }, props),
78 relayed: true, tab: () => "chat", showTab() {}, applyLock() {}, applyStatus() {}, noStatus() {}, words() {}, admin() {}, msg() {},
79 };
80 createRoom(page).lobbyConnect();
81 const line = page.$("presenceLine");
82 line.textContent = "";
83 sockets[0].onmessage({ data: JSON.stringify({ type: "presence", here: 12, signedIn: 4, watching: 8 }) });
84 expect(line.textContent).toBe("12 here · 4 signed in · 8 watching");
85 sockets[0].onmessage({ data: JSON.stringify({ type: "presence", here: 99, signedIn: "x" }) });
86 expect(line.textContent).toBe("12 here · 4 signed in · 8 watching");
87 } finally { Object.assign(g, saved); }
88 });
89
6790 test("when /live closes: backoff 0.25 to 2 s, a chip until the first message, no motion, no reload", () => {
6891 const sockets: any[] = [], delays: number[] = [], timers: (() => void)[] = [];
6992 const g = globalThis as any, saved = { WebSocket: g.WebSocket, setInterval: g.setInterval, setTimeout: g.setTimeout, location: g.location };
@@ -262,3 +285,17 @@ describe("reporting a chat line", () => {
262285 } finally { t.restore(); }
263286 });
264287 });
288
289 describe("the presence line", () => {
290 test("a presence frame reads 'N here · N signed in · N watching'", () => {
291 expect(presenceText({ type: "presence", here: 12, signedIn: 4, watching: 8 })).toBe("12 here · 4 signed in · 8 watching");
292 expect(presenceText({ here: 0, signedIn: 0, watching: 0 })).toBe("0 here · 0 signed in · 0 watching");
293 });
294 test("a frame missing a number or with a non-number is ignored", () => {
295 expect(presenceText({ here: 1, signedIn: 1 })).toBeNull();
296 expect(presenceText({ here: "1", signedIn: 1, watching: 1 })).toBeNull();
297 expect(presenceText({ here: 1, signedIn: NaN, watching: 1 })).toBeNull();
298 expect(presenceText({ here: -1, signedIn: 1, watching: 1 })).toBeNull();
299 expect(presenceText(null)).toBeNull();
300 });
301 });
Software/so101/src/viewer.html +2 −1
@@ -89,6 +89,7 @@
8989 #strip .who { flex: 1; min-width: 0; }
9090 #driverLine { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #driverLine.none { color: var(--dim); font-weight: 500; }
9191 #clock { color: var(--dim); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #clock.idle { color: var(--warn); }
92 #presenceLine { min-height: 1.2em; color: var(--dim); font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* its row is held from the first paint */
9293 #capLine { color: var(--dim); font-size: 12px; } #capLine:empty { display: none; }
9394 #armLine { display: none; gap: 6px; align-items: center; color: var(--dim); font-size: 12px; white-space: nowrap; } #armText { min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* shown on a phone held upright (ui/mobile.css) */
9495 #reconnect { align-self: flex-start; padding: 0 8px; border-radius: 9px; font-size: 11px; line-height: 16px; background: var(--warn); color: #000; visibility: hidden; } #reconnect.on { visibility: visible; }
@@ -289,7 +290,7 @@
289290
290291 <section id="strip" aria-label="Who drives" aria-live="polite">
291292 <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div>
292 <div class="who"><div id="driverLine" class="none">Connecting…</div><span id="reconnect" role="status">reconnecting…</span><div id="clock" aria-live="off"></div><div id="capLine"></div><div id="holdLine"></div><div id="armLine" aria-live="off"><span class="dot" id="armDot"></span><span id="armText"></span></div></div>
293 <div class="who"><div id="driverLine" class="none">Connecting…</div><span id="reconnect" role="status">reconnecting…</span><div id="clock" aria-live="off"></div><div id="presenceLine" aria-live="off"></div><div id="capLine"></div><div id="holdLine"></div><div id="armLine" aria-live="off"><span class="dot" id="armDot"></span><span id="armText"></span></div></div>
outdated

Inside the aria-live=polite strip, so every count change is announced. Add aria-live="off" to #presenceLine.

293294 <div id="turnActions"></div>
294295 <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button>
295296 <button id="stop" class="estop" data-stop title="Stop (space or Esc): halt everything, hold with torque, until someone resumes" aria-label="Stop the arm">Stop</button>

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs