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
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/359-the-status-strip-shows-12-here-4-signed → main 2 commits fork 2 threads · 2 unresolved
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 | ||
| 618 | 618 | the red **Stop**. Stop is there whenever you drive, and for the owner. Held |
| 619 | 619 | upright (up to 600 px wide), the view is pinned to the top in a 16:9 box kept |
| 620 | 620 | 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 | |
| 622 | 626 | reconnecting moves there from over the picture (`src/ui/mobile.css`). Below |
| 623 | 627 | that is a sheet with tabs at the bottom edge: **Chat**, **Queue**, |
| 624 | 628 | **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", () => { | ||
| 523 | 523 | await waitFor(() => (alice.printed.filter((l) => /^resumed/.test(l)).length === 2 ? true : undefined), "the owner's resume on alice's terminal"); |
| 524 | 524 | }); |
| 525 | 525 | }); |
| 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 @@ | ||
| 38 | 38 | import WebSocket from "ws"; |
| 39 | 39 | import { UNPRINTABLE } from "./chat.ts"; |
| 40 | 40 | import { ID, NAME, sign } from "./identity.ts"; |
| 41 | import { presenceText } from "./ui/lobby-panel.js"; | |
| 41 | 42 | import { entryLine, jointRows, linkRows, stateRows } from "./ui/machine.js"; |
| 42 | 43 | |
| 43 | 44 | export type Env = Record<string, string | undefined>; |
| @@ -145,9 +146,11 @@ export interface Room { | ||
| 145 | 146 | seen: Map<string, Someone>; |
| 146 | 147 | /** The reports the owner or a moderator was last sent, newest first; null until the first list (the one on join). */ |
| 147 | 148 | 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; | |
| 148 | 151 | } |
| 149 | 152 | |
| 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 }); | |
| 151 | 154 | |
| 152 | 155 | const someone = (x: unknown): Someone | null => { |
| 153 | 156 | if (typeof x !== "object" || x === null) return null; |
| @@ -219,6 +222,9 @@ function cues(room: Room, driver: unknown): string[] { | ||
| 219 | 222 | /** Fold one server frame into the room; what to print for it, if anything. */ |
| 220 | 223 | export function hear(room: Room, frame: Frame): string[] { |
| 221 | 224 | switch (frame.type) { |
| 225 | case "presence": | |
| 226 | room.presence = presenceText(frame) ?? room.presence; | |
| 227 | return []; | |
| 222 | 228 | case "hello": { |
| 223 | 229 | const you = someone(frame.you); |
| 224 | 230 | 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 | ||
| 290 | 296 | |
| 291 | 297 | export function who(room: Room): string { |
| 292 | 298 | 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}` : ""}`; | |
| 294 | 300 | } |
| 295 | 301 | |
| 296 | 302 | /** 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) { | ||
| 25 | 25 | /** Only a signed-in person reports, and only what someone else said. @param {any} m a chat message @param {any} me hello.you */ |
| 26 | 26 | export const mayReport = (m, me) => Boolean(me && m.from && m.from.id !== me.id); |
| 27 | 27 | |
| 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 | ||
| 28 | 34 | /** @param {number} attempt 1 for the first retry @returns {number} ms to wait: 250, 500, 1000, then 2000 at most */ |
| 29 | 35 | export const backoff = (attempt) => Math.min(250 * 2 ** Math.max(0, attempt - 1), 2000); |
| 30 | 36 | |
| @@ -273,6 +279,7 @@ export function createRoom(page) { | ||
| 273 | 279 | if (lobby.retry) { lobby.retry = 0; $("reconnect").classList.remove("on"); } // the first message: it is back |
| 274 | 280 | const m = JSON.parse(e.data); |
| 275 | 281 | if (m.type === "ping") return say({ type: "pong" }); |
| 282 | if (m.type === "presence") { const t = presenceText(m); if (t !== null) $("presenceLine").textContent = t; return; } | |
| 276 | 283 | if (m.type === "status") { tell("pose"); lobby.statusSeen = true; return m.status ? page.applyStatus(m.status) : page.noStatus(); } |
| 277 | 284 | if (m.type === "hello") lobby.hello = m; |
| 278 | 285 | 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 @@ | ||
| 1 | 1 | 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"; | |
| 3 | 3 | |
| 4 | 4 | /** A stand-in for the page's el(): elements as plain trees, so the test needs no DOM. */ |
| 5 | 5 | const el = (tag: string, props: Record<string, unknown> = {}, ...children: unknown[]) => ({ tag, ...props, children }); |
| @@ -64,6 +64,29 @@ describe("the room over /live", () => { | ||
| 64 | 64 | } finally { Object.assign(g, saved); } |
| 65 | 65 | }); |
| 66 | 66 | |
| 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 | ||
| 67 | 90 | test("when /live closes: backoff 0.25 to 2 s, a chip until the first message, no motion, no reload", () => { |
| 68 | 91 | const sockets: any[] = [], delays: number[] = [], timers: (() => void)[] = []; |
| 69 | 92 | 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", () => { | ||
| 262 | 285 | } finally { t.restore(); } |
| 263 | 286 | }); |
| 264 | 287 | }); |
| 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 @@ | ||
| 89 | 89 | #strip .who { flex: 1; min-width: 0; } |
| 90 | 90 | #driverLine { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #driverLine.none { color: var(); font-weight: 500; } |
| 91 | 91 | #clock { color: var(); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #clock.idle { color: var(); } |
| 92 | #presenceLine { min-height: 1.2em; color: var(); font-size: 12px; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* its row is held from the first paint */ | |
| 92 | 93 | #capLine { color: var(); font-size: 12px; } #capLine:empty { display: none; } |
| 93 | 94 | #armLine { display: none; gap: 6px; align-items: center; color: var(); font-size: 12px; white-space: nowrap; } #armText { min-width: 0; overflow: hidden; text-overflow: ellipsis; } /* shown on a phone held upright (ui/mobile.css) */ |
| 94 | 95 | #reconnect { align-self: flex-start; padding: 0 8px; border-radius: 9px; font-size: 11px; line-height: 16px; background: var(); color: #000; visibility: hidden; } #reconnect.on { visibility: visible; } |
| @@ -289,7 +290,7 @@ | ||
| 289 | 290 | |
| 290 | 291 | <section id="strip" aria-label="Who drives" aria-live="polite"> |
| 291 | 292 | <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. |
||
| 293 | 294 | <div id="turnActions"></div> |
| 294 | 295 | <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button> |
| 295 | 296 | <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> |
new above
offline
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.