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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Tapping the presence line opens a list of who is here, the driver highlighted and guests with a colour dot; Escape or an outside tap closes it #429

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/398-tapping-the-presence-line-opens-a-list-o → main 3 commits fork 4 threads · 4 unresolved

  • Merged. smith/398-tapping-the-presence-line-opens-a-list-o was merged into main as ac045d7.

Review

Sign in to review this change.
4 files changed +170 −4
Software/README.md +4
@@ -376,6 +376,10 @@ read-only for everyone: nothing in it can move the arm. Opened on a bare
376376 The terminal shows the same panel with `/machine` (see **The terminal door**
377377 below).
378378
379 Tap the presence line in the status strip ("12 here · 4 signed in · 8 watching") for the list of who is here: the driver
380 highlighted, a guest with a dot in their colour, and whether each is driving, queued or watching. Tap it again, press Escape or tap
381 anywhere else to close it. The terminal's `who` command gives the same list.
382
379383 Names appear in the feed in two places: whose turn it is, and the `by` on each
380384 logged request (the name of whoever sent it). Both are already public to
381385 anyone watching: the lobby shows every viewer, guests included, who drives,
Software/so101/src/ui/lobby-panel.js +38 −1
@@ -44,6 +44,21 @@ export function presenceText(m) {
4444 return m && ok(m.here) && ok(m.signedIn) && ok(m.watching) ? `${m.here} here · ${m.signedIn} signed in · ${m.watching} watching` : null;
4545 }
4646
47 const HEX = /^#[0-9a-fA-F]{6}$/;
48 /**
49 * The who list: one line per person, the driver marked, a guest with a dot in their colour. Names go in as text; the
50 * colour only as a validated #rrggbb, so a bad one gets no dot.
51 * @param {(tag: string, props?: Record<string, unknown>, ...children: any[]) => any} el
52 * @param {any} m a who frame
53 */
54 export function whoList(el, m) {
55 const people = Array.isArray(m?.people) ? m.people : [];
56 return el("ul", { className: "wholist" }, ...people.map((/** @type {any} */ p) => {
57 const dot = p.guest && typeof p.colour === "string" && HEX.test(p.colour) ? el("span", { className: "dot", style: `background:${p.colour}` }) : null;
58 return el("li", { className: p.role === "driving" ? "driving" : "" }, dot, el("span", { textContent: String(p.name) }), el("span", { className: "role", textContent: p.role === "driving" ? "driving" : p.role === "queued" ? "queued" : "watching" }));
59 }));
60 }
61
4762 /** @param {number} attempt 1 for the first retry @returns {number} ms to wait: 250, 500, 1000, then 2000 at most */
4863 export const backoff = (attempt) => Math.min(250 * 2 ** Math.max(0, attempt - 1), 2000);
4964
@@ -209,6 +224,25 @@ export function createRoom(page) {
209224 const { menu, button, off } = openMenu; openMenu = null;
210225 off(); menu.remove?.(); button.setAttribute("aria-expanded", "false");
211226 }
227 /** The who list under the presence line: asked on tap, drawn when the answer comes, closed by a second tap, Escape or an outside tap.
228 * A tap with no box open always asks again, so a throttled or lost answer never leaves it stuck. @type {{ box: any, off: () => void } | null} */
outdated

whoAsked is set true before the server has answered; if the server throttles (<1 s) or the socket is down, the state stays 'asked' with no box. Clear it when the socket closes and ask again on the next tap.

229 let openWho = null, whoAsked = false;
230 function closeWho() { whoAsked = false; if (!openWho) return; const { box, off } = openWho; openWho = null; off(); box.remove?.(); const b = $("presenceLine"); b.setAttribute("aria-expanded", "false"); b.removeAttribute("aria-controls"); }
231 function toggleWho() { if (openWho) return closeWho(); whoAsked = true; say({ type: "who" }); }
232 /** @param {any} m a who frame */
233 function showWho(m) {
234 if (!whoAsked || openWho) return;
235 whoAsked = false;
236 const btn = $("presenceLine"), box = el("div", { id: "whoBox", className: "whobox", role: "region", tabIndex: -1 }, whoList(el, m));
237 box.setAttribute("aria-label", "Who is here");
238 const onKey = (/** @type {any} */ e) => { if (e.key === "Escape") { closeWho(); btn.focus?.(); } };
239 const onOutside = (/** @type {any} */ e) => { if (!box.contains?.(e.target) && !btn.contains?.(e.target)) closeWho(); };
240 doc.addEventListener("keydown", onKey); doc.addEventListener("pointerdown", onOutside);

Give the box an id and set aria-controls on the button (and a label on the list); drop aria-haspopup='true', which announces a menu this is not. Also move focus handling so a keyboard user can reach the list.

241 openWho = { box, off: () => { doc.removeEventListener("keydown", onKey); doc.removeEventListener("pointerdown", onOutside); } };
242 btn.setAttribute("aria-expanded", "true"); btn.setAttribute("aria-controls", "whoBox");
243 btn.parentNode.append(box);
244 box.focus?.();
245 }
212246 /** @param {any} line @param {any} button @param {any} m @param {any[]} items */
213247 function toggleMenu(line, button, m, items) {
214248 const was = openMenu?.button === button;
@@ -320,7 +354,8 @@ export function createRoom(page) {
320354 if (lobby.retry) { lobby.retry = 0; $("reconnect").classList.remove("on"); } // the first message: it is back
321355 const m = JSON.parse(e.data);
322356 if (m.type === "ping") return say({ type: "pong" });
323 if (m.type === "presence") { const t = presenceText(m); if (t !== null) $("presenceLine").textContent = t; return; }
357 if (m.type === "presence") { const t = presenceText(m); if (t !== null) { const b = $("presenceLine"); b.textContent = t; b.disabled = false; } return; }
358 if (m.type === "who") return showWho(m);
324359 if (m.type === "status") { tell("pose"); lobby.statusSeen = true; return m.status ? page.applyStatus(m.status) : page.noStatus(); }
325360 if (m.type === "hello") lobby.hello = m;
326361 else if (m.type === "state") { lobby.offset = m.now - Date.now(); lobby.state = m; }
@@ -339,6 +374,7 @@ export function createRoom(page) {
339374 };
340375 ws.onclose = () => {
341376 if (lobby.ws !== ws) return;
377 closeWho(); $("presenceLine").disabled = true; // nothing to ask until the socket is back
342378 lobby.ws = null; lobby.hello = null; lobby.statusSeen = false; // polling takes over until it is back
343379 if (lobby.reopening) { // closed on purpose to hear who you are now: not an outage, so no chip
344380 lobby.reopening = false;
@@ -364,5 +400,6 @@ export function createRoom(page) {
364400 toEnd();
365401 };
366402
403 $("presenceLine").addEventListener("click", toggleWho);
367404 return { lobby, mayDrive, isOwner, say, serverNow, lobbyConnect, chatBox, renderTurn, button, tickClock };
368405 }
Software/so101/src/ui/lobby-panel.test.ts +117 −1
@@ -1,5 +1,5 @@
11 import { describe, expect, test } from "bun:test";
2 import { backoff, createRoom, mayReport, modActions, minutes, ordinal, presenceText, queueEntry, waitMinutes } from "./lobby-panel.js";
2 import { backoff, createRoom, mayReport, modActions, minutes, ordinal, presenceText, queueEntry, whoList, 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 });
@@ -367,3 +367,119 @@ describe("the long-press dialog's actions", () => {
367367 expect(modActions({ id: "u", owner: false }, false, { id: "x" })).toEqual({ delete: false, mute: false, ban: false });
368368 });
369369 });
370
371 describe("the who list", () => {
372 const li = (m: unknown) => (whoList(el, m) as any).children as any[];

Add createRoom tests for toggle open/close, Escape, outside pointerdown, and inside tap staying open; today none of the interaction is covered.

373 test("the driver is highlighted, a guest gets a dot, a bad colour gets none", () => {
374 const rows = li({ type: "who", people: [
375 { name: "ada", guest: false, role: "driving" },
376 { name: "Quiet Fox", colour: "#a1b2c3", guest: true, role: "watching" },
377 { name: "Bad Owl", colour: "red;x:y", guest: true, role: "queued" },
378 ] });
379 expect(rows[0].className).toBe("driving");
380 expect(rows[1].className).toBe("");
381 expect(rows[1].children[0].style).toBe("background:#a1b2c3");
382 expect(rows[2].children[0]).toBeNull();
383 expect(rows[2].children[1].textContent).toBe("Bad Owl");
384 });
385 test("a frame without people is an empty list", () => expect(li({ type: "who" })).toEqual([]));
386 });
387
388 describe("the who list on the page", () => {
389 /** A room with a real listener table on the document and the presence button. */
390 function setup() {
391 const g = globalThis as any, saved = { WebSocket: g.WebSocket, setInterval: g.setInterval, location: g.location, document: g.document };
392 const sockets: any[] = [];
393 g.WebSocket = class { readyState = 1; sent: string[] = []; constructor() { sockets.push(this); } send(m: string) { this.sent.push(m); } };
394 g.setInterval = () => 0;
395 g.location = { protocol: "http:", host: "x", pathname: "/", search: "" };
396 const docL: Record<string, ((e: any) => void)[]> = {};
397 g.document = { addEventListener: (t: string, f: any) => (docL[t] ??= []).push(f), removeEventListener: (t: string, f: any) => void (docL[t] = (docL[t] ?? []).filter((x) => x !== f)) };
398 const attrs: Record<string, string> = {}, appended: any[] = [], clicks: (() => void)[] = [];
399 const btn: any = { textContent: "", focused: 0, focus() { this.focused++; }, contains: (t: any) => t === btn, setAttribute: (k: string, v: string) => void (attrs[k] = v), removeAttribute: (k: string) => void delete attrs[k], addEventListener: (_: string, f: () => void) => clicks.push(f), parentNode: { append: (b: any) => appended.push(b) } };
400 const mk = (tag: string, props: object = {}, ...children: any[]): any => { const n: any = { tag, children, attrs: {}, focused: 0, removed: 0, ...props, setAttribute(k: string, v: string) { n.attrs[k] = v; }, focus() { n.focused++; }, remove() { n.removed++; }, contains: (t: any) => t === px || n.children.includes?.(t), classList: { toggle() {}, add() {}, remove() {} }, style: { setProperty() {} }, dataset: {} }; const px: any = new Proxy(n, { get: (t: any, k) => (k in t ? t[k] : () => mk("div")), set: (t: any, k, v) => ((t[k] = v), true) }); return px; };
401 const nodes = new Map<string, any>([["presenceLine", btn]]);
402 const page = { $: (id: string) => nodes.get(id) ?? (nodes.set(id, mk("div")), nodes.get(id)), el: mk, relayed: true, tab: () => "chat", showTab() {}, applyLock() {}, applyStatus() {}, noStatus() {}, words() {}, admin() {}, msg() {}, note() {} };
403 const room = createRoom(page);
404 room.lobbyConnect();
405 const ws = sockets[0], who = { type: "who", people: [{ name: "ann", guest: false, role: "driving" }] };
406 const tap = () => clicks[0]!(), answer = () => ws.onmessage({ data: JSON.stringify(who) });
407 const fire = (type: string, e: object) => (docL[type] ?? []).slice().forEach((f) => f(e));
408 return { g, saved, ws, btn, attrs, appended, tap, answer, fire, docL, restore: () => Object.assign(g, saved) };
409 }
410 const asks = (ws: any) => ws.sent.filter((m: string) => JSON.parse(m).type === "who").length;
411
412 test("a tap asks, the answer opens the box, a second tap closes it", () => {
413 const t = setup();
414 try {
415 t.tap();
416 expect(asks(t.ws)).toBe(1);
417 expect(t.appended.length).toBe(0);
418 t.answer();
419 const box = t.appended[0];
420 expect(box.id).toBe("whoBox");
421 expect(box.role).toBe("region");
422 expect(box.attrs["aria-label"]).toBe("Who is here");
423 expect(box.focused).toBe(1);
424 expect(t.attrs["aria-expanded"]).toBe("true");
425 expect(t.attrs["aria-controls"]).toBe("whoBox");
426 t.tap();
427 expect(t.attrs["aria-controls"]).toBeUndefined();
428 expect(box.removed).toBe(1);
429 expect(t.attrs["aria-expanded"]).toBe("false");
430 expect(t.docL.keydown).toEqual([]);
431 } finally { t.restore(); }
432 });
433 test("Escape closes it and puts focus back on the button", () => {
434 const t = setup();
435 try {
436 t.tap(); t.answer();
437 t.fire("keydown", { key: "a" });
438 expect(t.appended[0].removed).toBe(0);
439 t.fire("keydown", { key: "Escape" });
440 expect(t.appended[0].removed).toBe(1);
441 expect(t.btn.focused).toBe(1);
442 } finally { t.restore(); }
443 });
444 test("a tap outside closes it; a tap inside the box or on the button does not", () => {
445 const t = setup();
446 try {
447 t.tap(); t.answer();
448 const box = t.appended[0];
449 t.fire("pointerdown", { target: box });
450 t.fire("pointerdown", { target: t.btn });
451 expect(box.removed).toBe(0);
452 t.fire("pointerdown", { target: {} });
453 expect(box.removed).toBe(1);
454 } finally { t.restore(); }
455 });
456 test("a lost answer does not stick: the next tap asks again; a closed socket closes the box", () => {
457 const t = setup();
458 try {
459 t.tap(); // throttled: no answer
460 expect(t.attrs["aria-expanded"]).toBeUndefined();
461 t.tap();
462 expect(asks(t.ws)).toBe(2);
463 t.answer();
464 expect(t.appended.length).toBe(1);
465 t.ws.readyState = 3; t.ws.onclose();
466 expect(t.appended[0].removed).toBe(1);
467 expect(t.attrs["aria-expanded"]).toBe("false");
468 expect(t.btn.disabled).toBe(true);
469 } finally { t.restore(); }
470 });
471 test("an answer nobody asked for opens nothing", () => {
472 const t = setup();
473 try { t.answer(); expect(t.appended.length).toBe(0); } finally { t.restore(); }
474 });
475 });
476
477 describe("the presence button in the served page", () => {
478 const html = require("node:fs").readFileSync(new URL("../viewer.html", import.meta.url), "utf8") as string;
479 const tag = html.match(/<button id="presenceLine"[^>]*>/)![0];
480 test("it has a name that does not wait for the socket, and is disabled until a presence frame", () => {
481 expect(tag).toContain('aria-label="Who is here"');
482 expect(tag).toContain("disabled");
483 expect(tag).not.toContain("aria-haspopup");
484 });
485 });
Software/so101/src/viewer.html +11 −2
@@ -89,7 +89,8 @@
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 */
92 #strip .who { position: relative; }
93 #presenceLine { display: block; width: 100%; height: 44px; margin: -14px 0; padding: 0; border: 0; background: none; text-align: left; cursor: pointer; font-family: inherit; color: var(--dim); font-size: 12px; line-height: 44px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } /* a 44 px tap target on a 16 px row, so the strip does not grow; its row is held from the first paint */
9394 #capLine { color: var(--dim); font-size: 12px; } #capLine:empty { display: none; }
9495 #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) */
9596 #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; }
@@ -143,6 +144,14 @@
143144 #chat .rep { display: flex; align-items: center; gap: 8px; min-height: 44px; } #chat .rep span { flex: 1; min-width: 0; }
144145 #chat .report, #chat .modbtn { min-width: 44px; min-height: 44px; }
145146 #chat .line { position: relative; }
147 #presenceLine:disabled { pointer-events: none; cursor: default; }
148 #presenceLine:focus-visible { outline: 2px solid var(--blue, #4da3ff); outline-offset: -2px; }
149 .whobox { position: absolute; left: 0; top: 100%; z-index: 3; min-width: 200px; max-height: 50vh; overflow: auto; background: var(--bg2, #222); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
150 .wholist { list-style: none; margin: 0; padding: 4px 0; font-size: 13px; }
151 .wholist li { display: flex; align-items: center; gap: 8px; padding: 4px 10px; }
152 .wholist li.driving { font-weight: 600; background: rgba(255,255,255,.12); }
153 .wholist .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
154 .wholist .role { margin-left: auto; color: var(--dim); font-size: 12px; }
146155 #chat .modmenu { position: absolute; right: 0; top: 100%; z-index: 2; display: flex; flex-direction: column; background: var(--bg2, #222); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
147156 #chat .line.held { background: var(--blue-soft); }
148157 #chat.moderated .line:not(.sys) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: context-menu; }
@@ -293,7 +302,7 @@
293302
294303 <section id="strip" aria-label="Who drives" aria-live="polite">
outdated

Empty <button> with no accessible name at first paint, and for good with JS off. Add aria-label="Who is here" and disable or hide it while there is no presence text.

295304 <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div>
296 <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>
305 <div class="who"><div id="driverLine" class="none">Connecting…</div><span id="reconnect" role="status">reconnecting…</span><div id="clock" aria-live="off"></div><button id="presenceLine" type="button" aria-label="Who is here" aria-live="off" aria-expanded="false" disabled></button><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>
297306 <div id="turnActions"></div>
298307 <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button>
299308 <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