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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

Mobile queue and turns: Join in one tap, "you're next" alert, a ring countdown on your turn, a Ready check so idle phones don't hold the arm #57

Merged opened this in answer to

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

Merged

smith/arm:smith/52-mobile-queue-and-turns-join-in-one-tap-y → main 3 commits fork 2 threads · 2 unresolved

  • Merged. smith/52-mobile-queue-and-turns-join-in-one-tap-y was merged into main as 16caaba.

Review

Sign in to review this change.
8 files changed +267 −23
Software/README.md +10
@@ -315,6 +315,14 @@ its live pose and the cameras. Driving needs a name and a turn.
315315 agent is kept with each ban to read, not to block on: too many people
316316 share one browser for it to tell them apart.
317317
318 **The page's turn cues.** The status strip shows who drives and your place.
319 When you are first in line it turns amber and the phone buzzes and plays a
320 short tone (a checkbox under the queue mutes the tone). When your turn is
321 called, **Ready** appears and must be tapped within 15 s or the turn passes
322 on. While you drive, a ring around the seconds counts the time left, and
323 **+30 s** adds time while nobody waits. The countdown text is not read out
324 by screen readers; the call is announced once.
325
318326 **The terminal.** The room also has a terminal door (`src/tty.ts`, the
319327 `tty` in `forge.json`). Connect with the exact command the forge gives in
320328 `FORGE_APP_SSH`; when the forge has
@@ -324,6 +332,8 @@ is the owner, any other account is a signed-in person, and an unknown key
324332 watches. A line you type is said in the chat; commands start with `/`:
325333
326334 - `/join`, `/leave`: ask to drive (the owner takes over at once), hand back.
335 - `/ready`, `/extend`: confirm you are there when your turn is called (15 s,
336 or it passes on), add 30 s to your turn while nobody waits.
327337 - `/end [name]`, owner: end that turn (no name: whoever drives), or take
328338 them out of the line.
329339 - `/mute <name>`, `/unmute <name>`, owner.
Software/so101/src/lobby.test.ts +43
@@ -23,6 +23,7 @@ const as = (id: string, name: string, role = "user") => {
2323 return { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
2424 };
2525 const ALICE = as("u-alice", "alice");
26 const CAROL = as("u-carol", "carol");
2627 const BOB = as("u-bob", "bob");
2728 const OWNER = as("u-owner", "trevato", "admin");
2829
@@ -137,6 +138,48 @@ describe("lobby", () => {
137138 expect(bob.heard.some((m) => m.type === "said" && m.message.from === null && /alice's turn ended \(handed back\); bob has control/.test(m.message.text))).toBe(true);
138139 });
139140
141 test("two clients: the turn passes to the one in line, who confirms Ready; one who does not loses it", async () => {
142 const port = await start(new Turns({ readyMs: 150 }));
143 const alice = await join(port, ALICE);
144 const bob = await join(port, BOB);
145 alice.send({ type: "join" });
146 await bob.next(drivingIs("alice"));
147 bob.send({ type: "join" });
148 await alice.next((m) => m.type === "state" && m.queue.length === 1);
149 alice.send({ type: "extend" });
150 expect((await alice.next((m) => m.type === "error")).error).toContain("no more time");
151 alice.send({ type: "leave" });
152 const called = await bob.next(drivingIs("bob"));
153 expect(called.driver.readyBy).toBeGreaterThan(called.now);
154 bob.send({ type: "ready" });
155 const ready = await bob.next((m) => m.type === "state" && m.driver?.readyBy === null);
156 expect(ready.driver.name).toBe("bob");
157 await sleep(250);
158 expect(lobby!.turns.driver?.name).toBe("bob");
159 bob.send({ type: "extend" });
160 await bob.next((m) => m.type === "state" && m.driver?.endsAt > ready.driver.endsAt);
161
162 bob.send({ type: "leave" });
163 await alice.next(drivingIs(null));
164 alice.send({ type: "join" });
165 await alice.next(drivingIs("alice"));
166 bob.send({ type: "join" });
167 alice.send({ type: "leave" });
168 await bob.next(drivingIs("bob"));
169 await bob.next(drivingIs(null)); // never confirmed: the turn passes on (to nobody)
170
171 // with a second person in line, the unconfirmed turn passes to them
172 const carol = await join(port, CAROL);
173 alice.send({ type: "join" });
174 await alice.next(drivingIs("alice"));
175 bob.send({ type: "join" });
176 carol.send({ type: "join" });
177 await alice.next((m) => m.type === "state" && m.queue.length === 2);
178 alice.send({ type: "leave" });
179 await carol.next(drivingIs("bob"));
180 await carol.next(drivingIs("carol"));
181 });
182
140183 test("an idle driver loses the turn to the next in line, and their stream is closed", async () => {
141184 const port = await start(new Turns({ idleMs: 300 }));
142185 const alice = await join(port, ALICE);
Software/so101/src/lobby.ts +7 −2
@@ -6,6 +6,8 @@
66 *
77 * Client → server, one JSON object per frame:
88 * {"type": "join"} ask to drive (the owner takes over at once)
9 * {"type": "ready"} confirm you are there when your turn comes (15 s)
10 * {"type": "extend"} +30 s on your turn, while nobody waits
911 * {"type": "leave"} hand back the turn, or leave the line
1012 * {"type": "post", "text": "…"} say something
1113 * {"type": "end", "id": "<user id>"} owner: end that turn, or take them out of the line
@@ -277,8 +279,11 @@ export class Lobby {
277279 case "join":
278280 if (this.takeControl(who) === "full") this.send(seat, { type: "error", error: `the line is full (${this.turns.maxQueue}); try again in a little while` });
279281 return;
280 case "leave":
281 this.turns.leave(who.id);
282 case "ready":

The case "leave": this.turns.leave(who.id) branch was replaced instead of kept, so leave now falls through and nothing hands back the turn or leaves the line. Restore it.

283 this.turns.ready(who.id);
284 return;
285 case "extend":
286 if (!this.turns.extend(who.id)) this.send(seat, { type: "error", error: "no more time: someone is waiting, or you have had the most allowed" });
282287 return;
283288 case "post": {
284289 if (!who.owner && typeof m.text === "string" && this.filter.blocks(m.text)) throw new ChatError("that word is not allowed here");
Software/so101/src/terminal.test.ts +37 −2
@@ -73,6 +73,8 @@ describe("terminal lines", () => {
7373 const room = emptyRoom();
7474 hear(room, { type: "state", driver: { id: "u-alice", name: "alice" }, queue: [{ id: "u-bob", name: "bob" }], paused: false });
7575 expect(typed(room, "hello <b>there</b>")).toEqual({ send: { type: "post", text: "hello <b>there</b>" } });
76 expect(typed(room, "/ready")).toEqual({ send: { type: "ready" } });
77 expect(typed(room, "/extend")).toEqual({ send: { type: "extend" } });
7678 expect(typed(room, "/end")).toEqual({ send: { type: "end", id: "u-alice" } });
7779 expect(typed(room, "/end Bob")).toEqual({ send: { type: "end", id: "u-bob" } });
7880 expect(typed(room, "/mute alice")).toEqual({ send: { type: "mute", id: "u-alice", on: true } });
@@ -103,8 +105,8 @@ describe("terminal door", () => {
103105 relay = lobby = undefined;
104106 });
105107
106 const start = async () => {
107 lobby = new Lobby({ identityKey: KEY, turns: new Turns(), chat: new Chat({ rateMs: 0 }), admin: new Admin(), accounts: new Accounts() });
108 const start = async (turns = new Turns()) => {
109 lobby = new Lobby({ identityKey: KEY, turns, chat: new Chat({ rateMs: 0 }), admin: new Admin(), accounts: new Accounts() });
108110 relay = await startRelay({ port: 0, simulation: `http://127.0.0.1:${simulation.port}`, lobby });
109111 return relay.port;
110112 };
@@ -167,6 +169,39 @@ describe("terminal door", () => {
167169 await page.heardOne((m) => m.type === "said" && /alice's turn ended \(handed back\)/.test(m.message.text), "the hand-back on the page");
168170 });
169171
172 test("a terminal is told once when it is next and once when it is called", () => {
173 const room = emptyRoom();
174 hear(room, { type: "hello", you: { id: "u-bob", name: "bob" }, signin: true });
175 const alice = { id: "u-alice", name: "alice" }, bob = { id: "u-bob", name: "bob" };
176 const state = (driver: unknown, queue: unknown[]) => hear(room, { type: "state", driver, queue, paused: false });
177 expect(state(alice, [{ id: "u-carol", name: "carol" }, bob])).toEqual([]);
178 expect(state(alice, [bob])).toEqual(["you are next"]);
179 expect(state(alice, [bob])).toEqual([]);
180 expect(state({ ...bob, readyBy: 123 }, [])).toEqual(["your turn: type /ready within 15 s or it passes on"]);
181 expect(state({ ...bob, readyBy: 123 }, [])).toEqual([]);
182 expect(state({ ...bob, readyBy: null }, [])).toEqual([]);
183 });
184
185 test("a terminal driver called from the line confirms /ready and keeps the turn", async () => {
186 const port = await start(new Turns({ readyMs: 300 }));
187 const alice = await terminal(port, ttyEnv("u-alice", "alice", "user"));
188 const bob = await terminal(port, ttyEnv("u-bob", "bob", "user"));
189 const page = await viewer(port);
190 alice.door.input("/join");
191 await page.heardOne((m) => m.type === "state" && m.driver?.id === "u-alice", "alice driving");
192 bob.door.input("/join");
193 await page.heardOne((m) => m.type === "state" && m.queue.length === 1, "bob in line");
194 alice.door.input("/leave");
195 await page.heardOne((m) => m.type === "state" && m.driver?.id === "u-bob" && m.driver.readyBy > 0, "bob called");
196 bob.door.input("/ready");
197 await page.heardOne((m) => m.type === "state" && m.driver?.id === "u-bob" && m.driver.readyBy === null, "bob ready");
198 await new Promise((r) => setTimeout(r, 450));
199 expect(lobby!.turns.driver?.name).toBe("bob");
200 const before = lobby!.turns.driver!.endsAt;
201 bob.door.input("/extend");
202 await page.heardOne((m) => m.type === "state" && m.driver?.id === "u-bob" && m.driver.endsAt > before, "bob has more time");
203 });
204
170205 test("mute: only the owner's terminal may; the muted person's page hears it, and their terminal cannot chat", async () => {
171206 const port = await start();
172207 const alicePage = await viewer(port, web("u-alice", "alice"));
Software/so101/src/terminal.ts +22 −3
@@ -11,6 +11,7 @@
1111 * Typed lines:
1212 * <text> say it
1313 * /join /leave ask to drive (the owner takes over), or hand back / leave the line
14 * /ready /extend confirm you are there when called (15 s), or add 30 s to your turn
1415 * /end [who] owner: end that turn (none: whoever drives), or take them out of the line
1516 * /mute <who> /unmute <who> owner
1617 * /who /help /quit
@@ -63,11 +64,13 @@ export interface Room {
6364 driver: Someone | null;
6465 queue: Someone[];
6566 paused: boolean;
67 /** Whether the call to confirm, and the "you are next" cue, were already printed (each is said once). */
68 told: { called: boolean; next: boolean };
6669 /** Everyone seen by name, most recent last: to turn a typed name into an id. */
6770 seen: Map<string, Someone>;
6871 }
6972
70 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, seen: new Map() });
73 export const emptyRoom = (): Room => ({ you: null, muted: false, banned: false, driver: null, queue: [], paused: false, told: { called: false, next: false }, seen: new Map() });
7174
7275 const someone = (x: unknown): Someone | null => {
7376 if (typeof x !== "object" || x === null) return null;
@@ -87,7 +90,21 @@ const said = (m: unknown): string => {
8790 return from ? `${plain(from.name)}: ${plain(message?.text)}` : `· ${plain(message?.text)}`;
8891 };
8992
90 export const HELP = "type to chat · /join /leave · /end [who] /mute <who> /unmute <who> (owner) · /who · /quit";
93 export const HELP = "type to chat · /join /leave /ready /extend · /end [who] /mute <who> /unmute <who> (owner) · /who · /quit";
94
95 /** Once each: "you are called, confirm" and "you are next", so a terminal driver gets what the page's strip shows. */
96 function cues(room: Room, driver: unknown): string[] {
97 const out: string[] = [];
98 const me = room.you?.id;
99 const readyBy = (driver as { readyBy?: unknown } | null)?.readyBy;
100 const called = Boolean(me && room.driver?.id === me && typeof readyBy === "number");
101 if (called && !room.told.called) out.push("your turn: type /ready within 15 s or it passes on");
102 room.told.called = called;
103 const next = Boolean(me && !room.paused && room.queue[0]?.id === me);
104 if (next && !room.told.next) out.push("you are next");
105 room.told.next = next;
106 return out;
107 }
91108
92109 /** Fold one server frame into the room; what to print for it, if anything. */
93110 export function hear(room: Room, frame: Frame): string[] {
@@ -112,7 +129,7 @@ export function hear(room: Room, frame: Frame): string[] {
112129 room.paused = frame.paused === true;
113130 see(room, room.driver);
114131 for (const p of room.queue) see(room, p);
115 return [];
132 return cues(room, frame.driver);
116133 }
117134 case "chat": {
118135 const messages = Array.isArray(frame.messages) ? frame.messages : [];
@@ -155,6 +172,8 @@ export function typed(room: Room, input: string): Typed {
155172 switch (verb.toLowerCase()) {
156173 case "join":
157174 case "leave":
175 case "ready":
176 case "extend":
158177 return { send: { type: verb.toLowerCase() } };
159178 case "end": {
160179 if (!arg && !room.driver) return { print: "nobody has control" };
Software/so101/src/turns.test.ts +49
@@ -190,3 +190,52 @@ describe("turns", () => {
190190 expect(turns.driver).toBeNull();
191191 });
192192 });
193
194 describe("ready check and extra time", () => {
195 test("someone called from the line who does not confirm in 15 s loses the turn to the next", () => {
196 const events = make();
197 turns.join(alice);
198 turns.join(bob);
199 turns.join(carol);
200 advance(5_000);
201 turns.leave("a");
202 expect(turns.snapshot().driver).toMatchObject({ id: "b", readyBy: clock + 15_000 });
203 advance(14_000);
204 expect(turns.driver?.id).toBe("b");
205 advance(1_100);
206 expect(turns.driver?.id).toBe("c");
207 expect(events.find((e) => e.kind === "turn" && e.ended?.reason === "not ready")).toBeTruthy();
208 advance(16_000);
209 expect(turns.driver).toBeNull(); // nobody left to pass it to
210 });
211
212 test("ready, or any command, keeps the turn; asking for an idle arm needs no check", () => {
213 make();
214 expect(turns.join(alice)).toBe("driving");
215 expect(turns.snapshot().driver?.readyBy).toBeNull();
216 turns.join(bob);
217 turns.join(carol);
218 turns.leave("a");
219 expect(turns.ready("b")).toBe(true);
220 advance(16_000);
221 turns.activity("b");
222 expect(turns.driver?.id).toBe("b");
223 turns.leave("b");
224 turns.activity("c");
225 advance(16_000);
226 expect(turns.driver?.id).toBe("c");
227 });
228
229 test("+30 s only while nobody waits, and not without limit", () => {
230 make();
231 turns.join(alice);
232 expect(turns.extend("a")).toBe(true);
233 expect(turns.driver?.endsAt).toBe(1_000_000 + 210_000);
234 turns.join(bob);
235 expect(turns.extend("a")).toBe(false);
236 expect(turns.extend("b")).toBe(false);
237 turns.leave("b");
238 for (let i = 0; i < 10; i++) turns.extend("a");
239 expect(turns.driver!.endsAt - turns.driver!.startedAt).toBe(360_000);
240 });
241 });
Software/so101/src/turns.ts +45 −10
@@ -15,9 +15,13 @@ export interface Turn extends Person {
1515 startedAt: number;
1616 endsAt: number;
1717 lastActive: number;
18 /** Until this, someone taken from the line must confirm they are there; null once they have (or never needed to). */
19 readyBy: number | null;
20 /** Time added on request when nobody waits. */
21 bonusMs: number;
1822 }
1923
20 export type EndReason = "handed back" | "time is up" | "idle" | "disconnected" | "ended by the owner" | "taken over by the owner" | "paused for maintenance";
24 export type EndReason = "handed back" | "time is up" | "idle" | "not ready" | "disconnected" | "ended by the owner" | "taken over by the owner" | "paused for maintenance";
2125
2226 export type TurnEvent = { kind: "turn"; ended: { who: Person; reason: EndReason } | null; started: Person | null } | { kind: "queue" };
2327
@@ -27,13 +31,14 @@ export interface Snapshot {
2731 idleMs: number;
2832 paused: boolean;
2933 maxQueue: number;
30 driver: { id: string; name: string; owner: boolean; endsAt: number; idleEndsAt: number } | null;
34 driver: { id: string; name: string; owner: boolean; endsAt: number; idleEndsAt: number; readyBy: number | null } | null;
3135 queue: Array<{ id: string; name: string; place: number; waitMs: number }>;
3236 }
3337
3438 export interface TurnsOptions {
3539 turnMs?: number;
3640 idleMs?: number;
41 readyMs?: number;
3742 graceMs?: number;
3843 maxQueue?: number;
3944 paused?: boolean;
@@ -44,6 +49,8 @@ export class Turns {
4449 turnMs: number;
4550 idleMs: number;
4651 readonly graceMs: number;
52 /** How long someone called from the line has to say they are there. */
53 readyMs: number;
4754 maxQueue: number;
4855 paused: boolean;
4956 private readonly now: () => number;
@@ -59,6 +66,7 @@ export class Turns {
5966 this.turnMs = options.turnMs ?? 180_000;
6067 this.idleMs = options.idleMs ?? 30_000;
6168 this.graceMs = options.graceMs ?? 10_000;
69 this.readyMs = options.readyMs ?? 15_000;
6270 this.maxQueue = options.maxQueue ?? Infinity;
6371 this.paused = options.paused ?? false;
6472 this.now = options.now ?? Date.now;
@@ -85,7 +93,7 @@ export class Turns {
8593 if ((this.driver || this.paused) && this.queue.length >= this.maxQueue) return "full";
8694 this.queue.push({ ...who });
8795 }
88 if (!this.driver && !this.paused) this.handOver(null);
96 if (!this.driver && !this.paused) this.handOver(null, undefined, false);
8997 else this.emit({ kind: "queue" });
9098 return this.isDriver(who.id) ? "driving" : "queued";
9199 }
@@ -111,7 +119,7 @@ export class Turns {
111119 if (limits.turnMs !== undefined) this.turnMs = limits.turnMs;
112120 if (limits.idleMs !== undefined) this.idleMs = limits.idleMs;
113121 if (limits.maxQueue !== undefined) this.maxQueue = limits.maxQueue;
114 if (this.driver) this.driver.endsAt = this.driver.startedAt + this.turnMs;
122 if (this.driver) this.driver.endsAt = this.driver.startedAt + this.turnMs + this.driver.bonusMs;
115123 this.check();
116124 this.emit({ kind: "queue" });
117125 }
@@ -128,9 +136,32 @@ export class Turns {
128136 if (this.remove(id)) this.emit({ kind: "queue" });
129137 }
130138
131 /** The driver did something: the idle clock starts over. */
139 /** The driver did something: the idle clock starts over, and they are plainly there. */
132140 activity(id: string): void {
133 if (this.driver?.id === id) this.driver.lastActive = this.now();
141 if (this.driver?.id === id) {
142 this.driver.lastActive = this.now();
143 this.driver.readyBy = null;
144 }
145 }
146
147 /** The driver says they are there. */
148 ready(id: string): boolean {
149 if (!this.driver || this.driver.id !== id) return false;
150 this.driver.readyBy = null;
151 this.driver.lastActive = this.now();
152 this.emit({ kind: "queue" });
153 return true;
154 }
155
156 /** The driver asks for more time: allowed only while nobody waits, and at most one more turn's worth. */
157 extend(id: string, ms = 30_000): boolean {
158 const d = this.driver;
159 if (!d || d.id !== id || this.queue.length || d.bonusMs + ms > this.turnMs) return false;
160 d.bonusMs += ms;
161 d.endsAt = d.startedAt + this.turnMs + d.bonusMs;
162 this.schedule();
163 this.emit({ kind: "queue" });
164 return true;
134165 }
135166
136167 connect(id: string): void {
@@ -159,6 +190,7 @@ export class Turns {
159190 }
160191 const d = this.driver;
161192 if (d && now >= d.endsAt) this.handOver("time is up");
193 else if (d && d.readyBy !== null && now >= d.readyBy) this.handOver("not ready");
162194 else if (d && now - d.lastActive >= this.idleMs) this.handOver("idle");
163195 if (queueChanged) this.emit({ kind: "queue" });
164196 this.schedule();
@@ -174,7 +206,7 @@ export class Turns {
174206 idleMs: this.idleMs,
175207 paused: this.paused,
176208 maxQueue: Number.isFinite(this.maxQueue) ? this.maxQueue : -1,
177 driver: d ? { id: d.id, name: d.name, owner: d.owner, endsAt: d.endsAt, idleEndsAt: Math.min(d.endsAt, d.lastActive + this.idleMs) } : null,
209 driver: d ? { id: d.id, name: d.name, owner: d.owner, endsAt: d.endsAt, idleEndsAt: Math.min(d.endsAt, d.lastActive + this.idleMs), readyBy: d.readyBy } : null,
178210 // At most: a turn can end early, never late.
179211 queue: this.queue.map((p, i) => ({ id: p.id, name: p.name, place: i + 1, waitMs: left + i * this.turnMs })),
180212 };
@@ -193,13 +225,15 @@ export class Turns {
193225 }
194226
195227 /** End the current turn (if a reason is given) and start the next: `next`, or the head of the line. */
196 private handOver(reason: EndReason | null, next?: Person): void {
228 private handOver(reason: EndReason | null, next?: Person, confirm = true): void {
197229 const ended = this.driver && reason ? { who: { id: this.driver.id, name: this.driver.name, owner: this.driver.owner }, reason } : null;
198230 if (reason) this.driver = null;
199231 if (this.driver) return;
200 const who = next ?? (this.paused ? undefined : this.queue.shift());
232 const called = next ? undefined : this.paused ? undefined : this.queue.shift();
233 const who = next ?? called;
201234 const now = this.now();
202 this.driver = who ? { ...who, startedAt: now, endsAt: now + this.turnMs, lastActive: now } : null;
235 // Only someone called out of the line has to confirm; a person who asked for an idle arm is looking at it.
236 this.driver = who ? { ...who, startedAt: now, endsAt: now + this.turnMs, lastActive: now, readyBy: called && confirm ? now + this.readyMs : null, bonusMs: 0 } : null;
203237 this.emit({ kind: "turn", ended, started: who ?? null });
204238 this.schedule();
205239 }
@@ -212,6 +246,7 @@ export class Turns {
212246 clearTimeout(this.timer);
213247 const deadlines = [...this.gone.values()].map((since) => since + this.graceMs);
214248 if (this.driver) deadlines.push(this.driver.endsAt, this.driver.lastActive + this.idleMs);
249 if (this.driver?.readyBy != null) deadlines.push(this.driver.readyBy);
215250 if (!deadlines.length) return;
216251 // The idle deadline moves with every command; waking early just reschedules.
217252 const wait = Math.max(0, Math.min(...deadlines) - this.now());
Software/so101/src/viewer.html +54 −6
@@ -90,6 +90,14 @@
9090 .estop { flex: none; min-width: 72px; min-height: 52px; border: 0; border-radius: 12px; background: #d1242f; color: #fff; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; box-shadow: 0 0 0 3px rgba(209,36,47,.25), 0 2px 8px rgba(0,0,0,.35); }
9191 .estop:hover { background: #e5323d; } .estop:active { transform: scale(.97); }
9292 #sheetToggle { flex: none; }
93 /* the turn ring: time left as a sweep around the seconds; the driver's name over the video for everyone */
94 #ring { flex: none; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--blue) var(--p, 0%), var(--line) 0); font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; position: relative; }
95 #ring::before { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--surface); } #ring span { position: relative; }
96 #ring.low { background: conic-gradient(var(--warn) var(--p, 0%), var(--line) 0); color: var(--warn); }
97 #strip.next { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); box-shadow: inset 0 0 0 2px var(--warn); }
98 #strip.ready { box-shadow: inset 0 0 0 2px var(--blue); } #turnActions .ready { min-height: 48px; padding: 0 20px; font-weight: 800; }
99 @media (prefers-reduced-motion: no-preference) { #turnActions .ready { animation: pulse 1s ease-in-out infinite; } @keyframes pulse { 50% { opacity: .65; } } }
outdated

This hides the plain Stop on phones. Keep it unless the issue asked for it. Also wrap the pulse animation in @media (prefers-reduced-motion: no-preference).

100 #driverTag { position: absolute; z-index: 2; left: calc(10px + var(--safe-l)); bottom: 10px; max-width: 70%; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.6); color: #fff; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; } #driverTag:empty { display: none; }
93101
94102 /* the sheet: one panel at a time, the tabs under the thumb */
95103 #sheet { grid-area: sheet; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
@@ -240,12 +248,14 @@
240248 <span class="info"><span id="link" hidden></span><span id="live" class="label"></span><span class="dot" id="dot"></span><span id="state">…</span></span>
241249 <button id="fs" title="F">Fullscreen</button>
242250 </div>
251 <div id="driverTag" aria-hidden="true"></div>
243252 <div id="banner" role="alert"></div>
244253 <div id="msg" role="status"></div>
245254 </div>
246255
247256 <section id="strip" aria-label="Who drives" aria-live="polite">
248 <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock"></div><div id="capLine"></div></div>
257 <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div>
258 <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="capLine"></div></div>
249259 <div id="turnActions"></div>
250260 <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button>
251261 <button id="stop" class="danger" hidden title="End what the arm is doing and hold (space)">Stop</button>
@@ -262,6 +272,7 @@
262272 <div class="tab" id="tab-queue" role="tabpanel" aria-labelledby="t-queue" hidden>
263273 <h2>Driving</h2>
264274 <div class="row" id="queueActions"></div>
275 <label class="row" style="font-size:13px"><input type="checkbox" id="quiet"> Mute the "you're next" tone</label>
265276 <form id="joinForm" hidden><input id="joinName" type="text" required minlength="3" maxlength="20" pattern="[A-Za-z0-9_\-]{3,20}" autocomplete="nickname" autocapitalize="off" spellcheck="false" enterkeyhint="go" placeholder="Pick a name" aria-label="Your name" title="3-20 letters, digits, _ or -"><button class="go">Join</button></form>
266277 <p id="joinErr" role="alert"></p>
267278 <a id="forgeSignin" hidden>Have a forge account? Sign in instead</a>
@@ -1299,13 +1310,41 @@
12991310 if (!lobby.state || !lobby.hello?.signin) return void (c.textContent = lobby.hello && !lobby.hello.signin ? "Local: no sign-in, every visitor drives." : "");
13001311 const mine = me ? lobby.state.queue.find((x) => x.id === me.id) : null;
13011312 const place = mine ? ` · you're ${ordinal(mine.place)} in line, ≤ ${Math.max(1, Math.ceil(mine.waitMs / 60000))} min` : "";
1313 if (!d) $("ring").hidden = true;
13021314 if (!d) { c.className = ""; c.textContent = lobby.state.paused ? `No new turns until the owner resumes${place || "; you can still join the line"}.` : "Free: take control to drive."; return; }
13031315 const now = serverNow(), idle = d.idleEndsAt - now;
13041316 const idleSoon = idle < 15000 && d.idleEndsAt < d.endsAt;
1305 c.className = idleSoon ? "idle" : "";
1317 c.className = idleSoon || d.readyBy ? "idle" : "";
1318 tickRing(d, me, now);
1319 if (d.readyBy && me && d.id === me.id) return void (c.textContent = `Tap Ready within ${Math.max(0, Math.ceil((d.readyBy - now) / 1000))} s or the turn passes on`);
13061320 c.textContent = idleSoon ? `Idle: the turn ends in ${Math.max(0, Math.ceil(idle / 1000))} s unless the arm moves` : `${minutes(d.endsAt - now)} left${place}`;
13071321 }
1322 /** The ring is the driver's own: time left on the turn, in the seconds around it. */
1323 function tickRing(d, me, now) {
1324 const ring = $("ring"), mine = Boolean(me && d.id === me.id), st = lobby.state;
1325 ring.hidden = !mine;
1326 if (!mine) return;
1327 const left = Math.max(0, d.endsAt - now);
1328 ring.style.setProperty("--p", `${Math.min(100, (left / Math.max(st.turnMs, 1)) * 100)}%`);
1329 ring.classList.toggle("low", left < 15000);
1330 $("ringN").textContent = left >= 60000 ? `${Math.ceil(left / 60000)}m` : `${Math.ceil(left / 1000)}`;
1331 }
13081332 setInterval(tickClock, 250);
1333 $("quiet").onchange = (e) => { try { localStorage.setItem("so101.quiet", e.target.checked ? "1" : "0"); } catch {} };
1334 /** "You're next": a tone and a buzz (Android) and an amber strip; no web push, so only while the page is open. */
1335 let wasNext = false;
1336 const quiet = () => { try { return localStorage.getItem("so101.quiet") === "1"; } catch { return false; } };
1337 function alertNext(next) {
1338 $("strip").classList.toggle("next", next);
1339 if (next && !wasNext) {
1340 navigator.vibrate?.([200, 100, 200]);
1341 if (!quiet()) try {
1342 const ctx = new (window.AudioContext || window.webkitAudioContext)(), o = ctx.createOscillator(), g = ctx.createGain();
1343 o.frequency.value = 880; g.gain.value = 0.08; o.connect(g); g.connect(ctx.destination); o.start(); o.stop(ctx.currentTime + 0.25); o.onended = () => ctx.close();
1344 } catch { /* autoplay refused: the amber strip is the alert */ }
1345 }
1346 wasNext = next;
1347 }
13091348 const button = (textContent, className, onclick) => el("button", { textContent, className, type: "button", onclick });
13101349 /** The one thing to do about the turn, short enough for the strip. */
13111350 function turnButtons() {
@@ -1313,20 +1352,29 @@
13131352 if (!st || !lobby.hello?.signin) return []; // a run on one's own machine: everyone drives, nobody queues
13141353 if (!me) return [button("Join to drive", "go", () => { showTab("queue"); $("joinName").focus(); })];
13151354 if (lobby.hello.banned) return []; // banned: watching only
1316 if (d?.id === me.id) return [button("Hand back", "", () => say({ type: "leave" }))];
1317 if (st.queue.some((x) => x.id === me.id)) return [button("Leave line", "", () => say({ type: "leave" }))];
1318 return [button(me.owner && d ? "Take over" : d || (st.paused && !me.owner) ? "Join line" : "Take control", "go", () => say({ type: "join" }))];
1355 if (d?.id === me.id) return [...(d.readyBy ? [button("Ready", "go ready", () => say({ type: "ready" }))] : []), ...(!st.queue.length && !d.readyBy ? [button("+30 s", "", () => say({ type: "extend" }))] : []), button("Hand back", "", () => say({ type: "leave" }))];
1356 if (st.queue.some((x) => x.id === me.id)) return [button("Leave", "", () => say({ type: "leave" }))];
1357 return [button(me.owner && d ? "Take over" : d || (st.paused && !me.owner) ? "Join queue" : "Take control", "go", () => say({ type: "join" }))];
13191358 }
13201359 function renderTurn() {
13211360 const st = lobby.state, me = lobby.hello?.you ?? null;
13221361 if (!st || !lobby.hello) return;
13231362 const d = st.driver;
13241363 $("driverLine").className = st.paused ? "paused" : d ? "" : "none";
1325 $("driverLine").textContent = (st.paused ? "Paused for maintenance" + (d ? " · " : "") : "") + (d ? (me && d.id === me.id ? "You have control" : `${d.name} has control`) : st.paused ? "" : "Nobody has control");
1364 const mine = me ? st.queue.find((x) => x.id === me.id) : null, driving = Boolean(me && d?.id === me.id);
1365 // The strip in words: watching, queued, next, your turn.
1366 const wait = Math.max(1, Math.ceil((st.queue.length ? st.queue.at(-1).waitMs + st.turnMs : d ? Math.max(0, d.endsAt - st.now) : 0) / 60000));
1367 $("driverLine").textContent = (st.paused ? "Paused for maintenance" + (d ? " · " : "") : "") +
1368 (driving ? (d.readyBy ? "Your turn · confirm you're here" : "Your turn") : mine ? (mine.place === 1 ? "You're next" : `#${mine.place} · ~${Math.max(1, Math.ceil(mine.waitMs / 60000))} min`) :
1369 d ? (lobby.hello.signin && !lobby.hello.banned ? `Join queue · ${st.queue.length} waiting · ~${wait} min` : `${d.name} has control`) : st.paused ? "" : "Nobody has control");
1370 $("driverTag").textContent = d ? `🎮 ${d.name}${driving ? " (you)" : ""}` : "";
1371 $("strip").classList.toggle("ready", Boolean(driving && d.readyBy));
1372 alertNext(Boolean(mine && mine.place === 1 && !st.paused));
13261373 $("notice").hidden = !st.announcement;
13271374 $("notice").textContent = st.announcement ?? "";
13281375 $("capLine").textContent = st.maxSpeedPercent < 100 ? `Speed limited to ${st.maxSpeedPercent}% of full` : "";
13291376 $("turnActions").replaceChildren(...turnButtons());
1377 $("quiet").checked = quiet();
13301378 $("queueActions").replaceChildren(el("span", { textContent: d ? (me && d.id === me.id ? "You" : d.name) : "Nobody", style: "flex:1;font-weight:600" }), ...turnButtons());
13311379 const joining = lobby.hello.signin && !me;
13321380 $("joinForm").hidden = $("forgeSignin").hidden = !joining;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs