Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
Mobile portrait shell: video pinned on top with no layout shift, one status strip, a bottom tab bar Drive / Queue / Chat #111
quill/arm:quill/90-mobile-portrait-shell-video-pinned-on-to → main 1 commit fork
10 files
changed +340
−10
Software/README.md +30
| @@ -519,6 +519,36 @@ that is a sheet with tabs at the bottom edge: **Chat**, **Queue**, | ||
| 519 | 519 | starts) and **Admin** (the owner: the room, the safe zone, the trims, |
| 520 | 520 | metrics and 3D calibration). |
| 521 | 521 | |
| 522 | A phone held upright (up to 640 px wide) gets its own stylesheet, | |
| 523 | `src/ui/mobile.css`. The page links it after its own styles, for that media | |
| 524 | only, so wider screens and phones on their side are laid out as before. | |
| 525 | - The picture runs edge to edge at 16:9 across the top. Its box is reserved | |
| 526 | before the first frame arrives, so nothing moves when the video starts. | |
| 527 | It stays put while the panel under it scrolls. | |
| 528 | - There is exactly one status strip, under the picture. It shows who drives | |
| 529 | and the time left, your place in the line, and the arm's connection: | |
| 530 | **Live**, **Reconnecting…**, **Simulation**, **Offline · simulation** or | |
| 531 | **No arm** (`src/ui/link-state.js`). The connection readout and the | |
| 532 | driver's name over the picture are left out at this size, because the | |
| 533 | strip already says them. | |
| 534 | - The tab bar reads **Drive · Queue · Chat**, plus **Mod** for the owner. It | |
| 535 | is 56 px tall over `env(safe-area-inset-bottom)` (the page sets | |
| 536 | `viewport-fit=cover`), and every tab is at least 44 px. Drive is there | |
| 537 | from the first paint, before your turn, with its controls locked and the | |
| 538 | reason shown. The bar never reflows. The Machine panel is left to wider | |
| 539 | screens. | |
| 540 | - `src/phone-shell.test.ts` checks all of this in headless Chromium at | |
| 541 | 390x844 and 412x915. It measures the picture's box from the first paint | |
| 542 | on, the strip under it, the tabs, the 56 px bar, the forge pill's corner | |
| 543 | and the layout shift. It drives a turn and a place in the line through | |
| 544 | the page. Set `PHONE_SHOTS=<dir>` and it saves a screenshot of each state. | |
| 545 | It drives Chromium with | |
| 546 | [](https://playwright.dev), a dev dependency only: the test | |
| 547 | needs a real browser to measure layout, and playwright-core brings no | |
| 548 | browser download and no dependencies of its own. It uses the system's | |
| 549 | Chromium (`/usr/bin/chromium`, or `CHROME`), and the suite is skipped, | |
| 550 | with the reason, where none starts. | |
| 551 | ||
| 522 | 552 | - Controls, phone upright: a row of chips (J1 base, J2 shoulder, J3 elbow, |
| 523 | 553 | J4 wrist, J5 roll, Grip) picks one joint. One tall lever drives it: push |
| 524 | 554 | up or down, and the further you push the faster it goes. Let go and it |
Software/so101/bun.lock +3
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | "devDependencies": { |
| 14 | 14 | "@types/bun": "^1.4.2", |
| 15 | 15 | "@types/ws": "^8.18.2", |
| 16 | "playwright-core": "^1.64.1", | |
| 16 | 17 | "typescript": "^7.0.2", |
| 17 | 18 | }, |
| 18 | 19 | }, |
| @@ -102,6 +103,8 @@ | ||
| 102 | 103 | |
| 103 | 104 | "node-gyp-build": ["[email protected]", "", { "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ=="], |
| 104 | 105 | |
| 106 | "playwright-core": ["[email protected]", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="], | |
| 107 | ||
| 105 | 108 | "serialport": ["[email protected]", "", { "dependencies": { "@serialport/binding-mock": "10.2.2", "@serialport/bindings-cpp": "13.0.0", "@serialport/parser-byte-length": "13.0.0", "@serialport/parser-cctalk": "13.0.0", "@serialport/parser-delimiter": "13.0.0", "@serialport/parser-inter-byte-timeout": "13.0.0", "@serialport/parser-packet-length": "13.0.0", "@serialport/parser-readline": "13.0.0", "@serialport/parser-ready": "13.0.0", "@serialport/parser-regex": "13.0.0", "@serialport/parser-slip-encoder": "13.0.0", "@serialport/parser-spacepacket": "13.0.0", "@serialport/stream": "13.0.0", "debug": "4.4.0" } }, "sha512-PHpnTd8isMGPfFTZNCzOZp9m4mAJSNWle9Jxu6BPTcWq7YXl5qN7tp8Sgn0h+WIGcD6JFz5QDgixC2s4VW7vzg=="], |
| 106 | 109 | |
| 107 | 110 | "three": ["[email protected]", "", {}, "sha512-blFeqb49wRCSGUGj7gtpfnSGHy2lwDk94RhUmS1c/hTby70kvChbWpkJ4Pm1390LqzzvTmzgXKHPEafJwCb8jA=="], |
Software/so101/package.json +1
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | "devDependencies": { |
| 21 | 21 | "@types/bun": "^1.4.2", |
| 22 | 22 | "@types/ws": "^8.18.2", |
| 23 | "playwright-core": "^1.64.1", | |
| 23 | 24 | "typescript": "^7.0.2" |
| 24 | 25 | } |
| 25 | 26 | } |
Software/so101/src/phone-shell.test.ts added +181
| @@ -0,0 +1,181 @@ | ||
| 1 | /** | |
| 2 | * The phone held upright, measured in a real browser: the page from bench/fake-serve.ts in headless Chromium, driven by | |
| 3 | * Playwright, at 390x844 (iPhone) and 412x915 (Android). The picture is 16:9 across the top and its box never moves, | |
| 4 | * one status strip sits under it, and the tab bar is Drive · Queue · Chat (· Mod), 56 px, clear of the forge pill. | |
| 5 | * Where no Chromium starts (no binary, or a sandbox without sockets) the suite is skipped and says why. | |
| 6 | * With PHONE_SHOTS=<dir>, a screenshot of every state goes there. | |
| 7 | */ | |
| 8 | import { afterAll, describe, expect, test } from "bun:test"; | |
| 9 | import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { chromium, type Browser, type BrowserContext, type Page } from "playwright-core"; | |
| 13 | ||
| 14 | // What the callbacks below see, in the page: the type check here has no DOM library, and adding one types the whole app. | |
| 15 | declare const document: { querySelectorAll(s: string): Iterable<Element> }; | |
| 16 | declare const window: { cls: number }; | |
| 17 | declare const getComputedStyle: (e: Element) => { visibility: string }; | |
| 18 | declare const PerformanceObserver: new (cb: (list: { getEntries(): Array<{ value: number; hadRecentInput: boolean }> }) => void) => { observe(o: object): void }; | |
| 19 | type Element = { getClientRects(): ArrayLike<unknown>; getBoundingClientRect(): { x: number; y: number; width: number; height: number }; innerText: string; inert: boolean }; | |
| 20 | ||
| 21 | const SIZES = [{ width: 390, height: 844, scale: 3 }, { width: 412, height: 915, scale: 2.625 }]; | |
| 22 | /** The forge pill's corner: the tab bar's right padding (--pill) by its height. */ | |
| 23 | const PILL = { w: 68, h: 56 }; | |
| 24 | const CHROMES = [process.env.CHROME, "/usr/bin/chromium", "/usr/bin/chromium-browser", "/usr/bin/google-chrome", "/usr/bin/google-chrome-stable"].filter((p): p is string => Boolean(p)); | |
| 25 | const dir = mkdtempSync(join(tmpdir(), "so101-phone-")); | |
| 26 | const shots = process.env.PHONE_SHOTS; | |
| 27 | if (shots) mkdirSync(shots, { recursive: true }); | |
| 28 | ||
| 29 | async function launch(): Promise<Browser | string> { | |
| 30 | const bin = CHROMES.find((p) => existsSync(p)); | |
| 31 | if (!bin) return "no Chromium on this machine"; | |
| 32 | try { | |
| 33 | return await chromium.launch({ executablePath: bin, args: ["--no-sandbox", "--use-angle=swiftshader", "--enable-unsafe-swiftshader"], timeout: 20000 }); | |
| 34 | } catch (err) { | |
| 35 | return `Chromium did not start: ${String((err as Error).message).split("\n")[0]!.slice(0, 160)}`; | |
| 36 | } | |
| 37 | } | |
| 38 | ||
| 39 | /** The simulated arm behind the relay. Local: every visitor is the owner. Hosted: people join by name and queue. */ | |
| 40 | async function serve(kind: "local" | "hosted"): Promise<{ proc: ReturnType<typeof Bun.spawn>; base: string }> { | |
| 41 | const data = mkdtempSync(join(dir, `${kind}-`)); | |
| 42 | const env: Record<string, string> = { ...process.env, PORT: "0", HOST: "127.0.0.1", FORGE_APP_DATA: data } as Record<string, string>; | |
| 43 | delete env.FORGE_APP_IDENTITY_KEY; delete env.ARM_SERVER; delete env.FORGE_APP_ENV; | |
| 44 | if (kind === "hosted") env.FORGE_APP_ENV = "preview"; | |
| 45 | const proc = Bun.spawn(["bun", "run", join(import.meta.dir, "..", "bench", "fake-serve.ts")], { stdout: "pipe", stderr: "inherit", env }); | |
| 46 | const reader = proc.stdout.getReader(); | |
| 47 | let text = ""; | |
| 48 | while (!/arm on http:\/\/\S+:(\d+)/.test(text)) { | |
| 49 | const { value, done } = await reader.read(); | |
| 50 | if (done) throw new Error(`fake-serve exited: ${text}`); | |
| 51 | text += new TextDecoder().decode(value); | |
| 52 | } | |
| 53 | reader.releaseLock(); | |
| 54 | // localhost, not 127.0.0.1: the session cookie is Secure, and Chromium keeps Secure cookies over plain http only there. | |
| 55 | return { proc, base: `http://localhost:${/arm on http:\/\/\S+:(\d+)/.exec(text)![1]}` }; | |
| 56 | } | |
| 57 | ||
| 58 | const started = await launch(); | |
| 59 | const browser = typeof started === "string" ? null : started; | |
| 60 | if (typeof started === "string") console.log(`phone-shell: skipped, ${started}`); | |
| 61 | const servers = browser ? await Promise.all(SIZES.flatMap(() => [serve("local"), serve("hosted")])) : []; | |
| 62 | ||
| 63 | afterAll(async () => { | |
| 64 | await browser?.close(); | |
| 65 | for (const s of servers) s.proc.kill(); | |
| 66 | rmSync(dir, { recursive: true, force: true }); | |
| 67 | }); | |
| 68 | ||
| 69 | type Box = { x: number; y: number; w: number; h: number }; | |
| 70 | const box = (page: Page, selector: string): Promise<Box | null> => | |
| 71 | page.locator(selector).first().evaluate((e) => { const r = e.getBoundingClientRect(); return r.width || r.height ? { x: r.x, y: r.y, w: r.width, h: r.height } : null; }).catch(() => null); | |
| 72 | const visible = (page: Page, selector: string): Promise<number> => | |
| 73 | page.evaluate((s) => [...document.querySelectorAll(s)].filter((e) => e.getClientRects().length && getComputedStyle(e).visibility !== "hidden").length, selector); | |
| 74 | /** The tab bar's buttons on screen, left to right: their words and boxes. */ | |
| 75 | const tabs = (page: Page) => | |
| 76 | page.evaluate(() => [...document.querySelectorAll("#tabs [role=tab]")].filter((b) => b.getClientRects().length) | |
| 77 | .map((b) => { const r = b.getBoundingClientRect(); return { text: b.innerText.trim(), x: r.x, y: r.y, w: r.width, h: r.height }; }) | |
| 78 | .sort((a, b) => a.x - b.x)); | |
| 79 | const overlaps = (a: Box, b: Box) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h; | |
| 80 | const shot = async (page: Page, name: string) => { if (shots) await page.screenshot({ path: join(shots, `${name}.png`) }); }; | |
| 81 | ||
| 82 | async function phone(size: (typeof SIZES)[number], colorScheme: "dark" | "light" = "dark"): Promise<BrowserContext> { | |
| 83 | return browser!.newContext({ viewport: { width: size.width, height: size.height }, deviceScaleFactor: size.scale, isMobile: true, hasTouch: true, colorScheme }); | |
| 84 | } | |
| 85 | /** Opens the page and keeps every layout shift it reports. */ | |
| 86 | async function open(context: BrowserContext, base: string): Promise<Page> { | |
| 87 | const page = await context.newPage(); | |
| 88 | await page.addInitScript(() => { | |
| 89 | window.cls = 0; | |
| 90 | new PerformanceObserver((list) => { for (const e of list.getEntries()) if (!e.hadRecentInput) window.cls += e.value; }).observe({ type: "layout-shift", buffered: true }); | |
| 91 | }); | |
| 92 | await page.goto(base, { waitUntil: "domcontentloaded" }); | |
| 93 | return page; | |
| 94 | } | |
| 95 | /** The shell every phone page shares: the picture, one strip under it, the tab bar at the bottom clear of the pill. */ | |
| 96 | async function expectShell(page: Page, size: (typeof SIZES)[number]) { | |
| 97 | const app = (await box(page, "#app"))!; | |
| 98 | expect([app.x, app.y, app.w]).toEqual([0, 0, size.width]); | |
| 99 | expect(app.h).toBeCloseTo((size.width * 9) / 16, 0); | |
| 100 | expect(await visible(page, "#strip")).toBe(1); | |
| 101 | const strip = (await box(page, "#strip"))!; | |
| 102 | expect(strip.y).toBeCloseTo(app.y + app.h, 0); | |
| 103 | expect(strip.w).toBe(size.width); | |
| 104 | for (const overlay of ["#top .info", "#driverTag"]) expect(await visible(page, overlay)).toBe(0); // the strip says it, once | |
| 105 | expect(await visible(page, "[data-stop]")).toBe(1); | |
| 106 | const bar = (await box(page, "#tabs"))!; | |
| 107 | expect(bar.h).toBe(56); // headless has no home indicator: env(safe-area-inset-bottom) is 0 here | |
| 108 | expect(bar.y + bar.h).toBeCloseTo(size.height, 0); | |
| 109 | const pill = { x: size.width - PILL.w, y: size.height - PILL.h, w: PILL.w, h: PILL.h }; | |
| 110 | for (const t of await tabs(page)) { | |
| 111 | expect(t.h).toBeGreaterThanOrEqual(44); | |
| 112 | expect(t.w).toBeGreaterThanOrEqual(44); | |
| 113 | expect(overlaps(t, pill)).toBe(false); | |
| 114 | } | |
| 115 | return app; | |
| 116 | } | |
| 117 | ||
| 118 | for (const [i, size] of SIZES.entries()) { | |
| 119 | const name = `${size.width}x${size.height}`; | |
| 120 | describe.skipIf(!browser)(`a phone held upright, ${name}`, () => { | |
| 121 | test("the picture is 16:9 across the top from the first paint and never moves; one strip says the arm is the simulation", async () => { | |
| 122 | const context = await phone(size); | |
| 123 | const page = await open(context, servers[i * 2]!.base); | |
| 124 | const first = await expectShell(page, size); | |
| 125 | await page.locator("#linkWord", { hasText: "Simulation" }).waitFor(); | |
| 126 | await page.waitForTimeout(1500); // the model, the views and the strip's words have come in | |
| 127 | expect(await box(page, "#app")).toEqual(first); | |
| 128 | // the owner of their own machine: Drive · Queue · Chat · Mod, short names, the Machine panel left to wider screens | |
| 129 | expect((await tabs(page)).map((t) => t.text)).toEqual(["Drive", "Queue", "Chat", "Mod"]); | |
| 130 | await expectShell(page, size); | |
| 131 | await shot(page, `${name}-owner-dark`); | |
| 132 | await page.locator("#t-chat").click(); | |
| 133 | expect(await box(page, "#app")).toEqual(first); // a tab's panel scrolls under the picture; the picture stays | |
| 134 | await context.close(); | |
| 135 | const light = await phone(size, "light"); | |
| 136 | const lit = await open(light, servers[i * 2]!.base); | |
| 137 | await lit.locator("#linkWord", { hasText: "Simulation" }).waitFor(); | |
| 138 | await expectShell(lit, size); | |
| 139 | await shot(lit, `${name}-owner-light`); | |
| 140 | await light.close(); | |
| 141 | }, 30000); | |
| 142 | ||
| 143 | test("the strip names the driver and the time left, and your place in line; Drive is a tab before your turn", async () => { | |
| 144 | const base = servers[i * 2 + 1]!.base; | |
| 145 | const join = async (who: string) => { | |
| 146 | const context = await phone(size); | |
| 147 | const page = await open(context, base); | |
| 148 | const first = await expectShell(page, size); | |
| 149 | expect((await tabs(page)).map((t) => t.text)).toEqual(["Drive", "Queue", "Chat"]); // watching: no Mod | |
| 150 | await page.locator("#linkWord", { hasText: "Simulation" }).waitFor(); | |
| 151 | await page.waitForTimeout(1000); // the room, the model and the strip's words have come in | |
| 152 | expect(await box(page, "#app")).toEqual(first); | |
| 153 | expect(await page.evaluate(() => window.cls)).toBeLessThan(0.01); // nothing moved | |
| 154 | await page.locator("#t-queue").click(); | |
| 155 | await page.locator("#joinName").fill(who); | |
| 156 | await page.locator("#joinForm button").click(); | |
| 157 | await page.locator("#joinForm").waitFor({ state: "hidden" }); | |
| 158 | return { context, page }; | |
| 159 | }; | |
| 160 | const ann = await join(`ann${i}`); | |
| 161 | await ann.page.locator("#turnActions button", { hasText: "Take control" }).click(); | |
| 162 | await ann.page.locator("#driverLine", { hasText: "Your turn" }).waitFor(); | |
| 163 | await ann.page.locator("#clock", { hasText: /\d+:\d\d left/ }).waitFor(); | |
| 164 | await expectShell(ann.page, size); | |
| 165 | await shot(ann.page, `${name}-driving`); | |
| 166 | ||
| 167 | const bob = await join(`bob${i}`); | |
| 168 | await bob.page.locator("#turnActions button", { hasText: "Join queue" }).click(); | |
| 169 | await bob.page.locator("#driverLine", { hasText: "You're next" }).waitFor(); | |
| 170 | await bob.page.locator("#clock", { hasText: /\d+:\d\d left · you're 1st in line/ }).waitFor(); | |
| 171 | expect(await bob.page.locator("#linkWord").innerText()).toBe("Simulation"); | |
| 172 | await expectShell(bob.page, size); | |
| 173 | await bob.page.locator("#t-controls").click(); // Drive is there before the turn, its controls locked | |
| 174 | await bob.page.locator("#why", { hasText: "It's not your turn" }).waitFor(); | |
| 175 | expect(await bob.page.locator("#touch").evaluate((e) => (e as unknown as Element).inert)).toBe(true); | |
| 176 | await shot(bob.page, `${name}-queued`); | |
| 177 | await ann.context.close(); | |
| 178 | await bob.context.close(); | |
| 179 | }, 30000); | |
| 180 | }); | |
| 181 | } |
Software/so101/src/server.test.ts +21
| @@ -191,6 +191,27 @@ describe("viewer page", () => { | ||
| 191 | 191 | expect(page).toMatch(/#tabs \{[^}]*var\(--pill\)/); |
| 192 | 192 | }); |
| 193 | 193 | |
| 194 | test("a phone held upright gets its own stylesheet: the picture 16:9 on top, one strip, Drive · Queue · Chat · Mod", async () => { | |
| 195 | const page = await (await fetch(`${base}/`)).text(); | |
| 196 | const link = /<link rel="stylesheet" href="(\/ui\/[0-9a-f]{12}\/mobile\.css)" media="\(orientation: portrait\) and \(max-width: 640px\)">/.exec(page); | |
| 197 | expect(link).not.toBeNull(); | |
| 198 | expect(page.indexOf(link![0])).toBeGreaterThan(page.indexOf("</style>")); // after the page's own rules, so it wins at equal weight | |
| 199 | const r = await fetch(`${base}${link![1]}`); | |
| 200 | expect(r.status).toBe(200); | |
| 201 | expect(r.headers.get("content-type")).toBe("text/css"); | |
| 202 | expect(r.headers.get("cache-control")).toContain("immutable"); | |
| 203 | const css = await r.text(); | |
| 204 | expect(css).toMatch(/#app \{[^}]*aspect-ratio: 16 \/ 9/); | |
| 205 | expect(css).toMatch(/#top \.info, #driverTag \{ display: none; \}/); | |
| 206 | expect(css).toMatch(/#t-controls \{ order: 1; \} #t-queue \{ order: 2; \} #t-chat \{ order: 3; \} #t-admin \{ order: 4; \}/); | |
| 207 | // the strip carries the arm's connection, and the tabs their short names; a wider screen keeps both out of sight | |
| 208 | expect(page).toContain('id="linkLine"'); | |
| 209 | expect(page).toMatch(/#linkLine, #tabs \.short \{ display: none; \}/); | |
| 210 | expect(page).toContain('<span class="long">Controls</span><span class="short">Drive</span>'); | |
| 211 | expect(page).toContain('<span class="long">Admin</span><span class="short">Mod</span>'); | |
| 212 | expect(page).toMatch(/import\("\/ui\/[0-9a-f]{12}\/link-state\.js"\)/); | |
| 213 | }); | |
| 214 | ||
| 194 | 215 | test("serves the touch-driving modules, and the phone layout keeps the browser's gestures off the controls", async () => { |
| 195 | 216 | const page = await (await fetch(`${base}/`)).text(); |
| 196 | 217 | for (const name of ["drive", "frames"]) { |
Software/so101/src/server.ts +4 −4
| @@ -153,9 +153,9 @@ const JAM_WINDOW = 6; | ||
| 153 | 153 | /** Consecutive too-far frames for one joint before it is eased over to the leader instead of left behind. */ |
| 154 | 154 | const RESUME_AFTER_DROPS = 20; |
| 155 | 155 | const VENDORED = new Set(["three", "urdf-loader"]); |
| 156 | /** A module the page loads from src/ui: plain JavaScript, never its tests. */ | |
| 157 | const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.js$/.test(name); | |
| 158 | const MIME: Record<string, string> = { ".js": "text/javascript", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" }; | |
| 156 | /** A file the page loads from src/ui: plain JavaScript or a stylesheet, never its tests. */ | |
| 157 | const isUiModule = (name: string) => /^[a-z][a-z0-9-]*\.(?:js|css)$/.test(name); | |
| 158 | const MIME: Record<string, string> = { ".js": "text/javascript", ".css": "text/css", ".mjs": "text/javascript", ".json": "application/json", ".urdf": "application/xml", ".stl": "model/stl", ".dae": "model/vnd.collada+xml", ".png": "image/png", ".jpg": "image/jpeg" }; | |
| 159 | 159 | |
| 160 | 160 | export async function startServer(bus: FeetechBus, options: ServerOptions = {}): Promise<RunningServer> { |
| 161 | 161 | const ids = options.ids ?? [1, 2, 3, 4, 5, 6]; |
| @@ -685,7 +685,7 @@ export async function startServer(bus: FeetechBus, options: ServerOptions = {}): | ||
| 685 | 685 | if (!path || ![".js", ".mjs", ".json"].includes(extname(path).toLowerCase())) return json(res, 404, { error: "no such vendored file" }); |
| 686 | 686 | return file(res, path, "max-age=86400"); |
| 687 | 687 | } |
| 688 | const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.js)$/.exec(url.pathname); | |
| 688 | const ui = /^\/ui\/[0-9a-f]{12}\/([a-z][a-z0-9-]*\.(?:js|css))$/.exec(url.pathname); | |
| 689 | 689 | if (req.method === "GET" && ui) { |
| 690 | 690 | if (!isUiModule(ui[1]!) || !existsSync(join(uiDir, ui[1]!))) return json(res, 404, { error: "no such module" }); |
| 691 | 691 | return file(res, join(uiDir, ui[1]!), "public, max-age=31536000, immutable"); |
Software/so101/src/ui/link-state.js added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | /** | |
| 2 | * The arm's connection in one word for the status strip: live, reconnecting, offline, simulated or no arm. | |
| 3 | * Plain data in (what /link and /status last said), plain data out. Plain ESM, served at /ui/ and imported by the tests. | |
| 4 | * | |
| 5 | * @param {{ relayed: boolean, link: string | null, status: { reconnecting?: boolean } | null, failed: boolean }} seen | |
| 6 | * link: the relay's /link mode, null before it answers or with no relay; status: the last arm status, null before | |
| 7 | * one came; failed: the last /status poll got no answer. | |
| 8 | * @returns {{ text: string, tone: "ok" | "warn" | "bad" | "dim" }} | |
| 9 | */ | |
| 10 | export function linkState({ relayed, link, status, failed }) { | |
| 11 | if (link === "reconnecting" || (!failed && status?.reconnecting)) return { text: "Reconnecting…", tone: "warn" }; | |
| 12 | if (link === "offline") return { text: "Offline · simulation", tone: "bad" }; | |
| 13 | if (failed) return { text: "No arm", tone: "bad" }; | |
| 14 | if (!status) return { text: "Connecting…", tone: "dim" }; | |
| 15 | if (relayed && link === "simulated") return { text: "Simulation", tone: "dim" }; | |
| 16 | if (relayed && link !== "live") return { text: "Connecting…", tone: "dim" }; | |
| 17 | return { text: "Live", tone: "ok" }; | |
| 18 | } |
Software/so101/src/ui/link-state.test.ts added +28
| @@ -0,0 +1,28 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { linkState } from "./link-state.js"; | |
| 3 | ||
| 4 | const arm = { reconnecting: false }; | |
| 5 | ||
| 6 | describe("the strip's word for the arm's connection", () => { | |
| 7 | test("live when the relay's arm answers, or straight to an arm server that does", () => { | |
| 8 | expect(linkState({ relayed: true, link: "live", status: arm, failed: false })).toEqual({ text: "Live", tone: "ok" }); | |
| 9 | expect(linkState({ relayed: false, link: null, status: arm, failed: false })).toEqual({ text: "Live", tone: "ok" }); | |
| 10 | }); | |
| 11 | ||
| 12 | test("reconnecting whether the relay or the arm's status says so, and before a poll that failed", () => { | |
| 13 | expect(linkState({ relayed: true, link: "reconnecting", status: arm, failed: false }).text).toBe("Reconnecting…"); | |
| 14 | expect(linkState({ relayed: true, link: "live", status: { reconnecting: true }, failed: false }).tone).toBe("warn"); | |
| 15 | expect(linkState({ relayed: true, link: "reconnecting", status: null, failed: true }).text).toBe("Reconnecting…"); | |
| 16 | }); | |
| 17 | ||
| 18 | test("offline and the simulation are said as such, never as live", () => { | |
| 19 | expect(linkState({ relayed: true, link: "offline", status: arm, failed: false })).toEqual({ text: "Offline · simulation", tone: "bad" }); | |
| 20 | expect(linkState({ relayed: true, link: "simulated", status: arm, failed: false })).toEqual({ text: "Simulation", tone: "dim" }); | |
| 21 | expect(linkState({ relayed: true, link: null, status: arm, failed: false }).text).toBe("Connecting…"); | |
| 22 | }); | |
| 23 | ||
| 24 | test("no answer is no arm; nothing yet is connecting", () => { | |
| 25 | expect(linkState({ relayed: false, link: null, status: arm, failed: true })).toEqual({ text: "No arm", tone: "bad" }); | |
| 26 | expect(linkState({ relayed: true, link: null, status: null, failed: false })).toEqual({ text: "Connecting…", tone: "dim" }); | |
| 27 | }); | |
| 28 | }); |
Software/so101/src/ui/mobile.css added +31
| @@ -0,0 +1,31 @@ | ||
| 1 | /* A phone held upright. The page links this file only at (orientation: portrait) and (max-width: 640px), after its | |
| 2 | own styles, so a wider screen or a phone on its side never sees these rules. | |
| 3 | Top to bottom: the picture full-bleed at 16:9, its box reserved before the first frame so nothing moves when it | |
| 4 | comes; one status strip (who drives and the time left, your place in line, the arm's connection, the STOP); the | |
| 5 | open tab's panel, which scrolls on its own; the tab bar Drive · Queue · Chat (· Mod) under the thumb. */ | |
| 6 | ||
| 7 | #shell { grid-template-rows: auto auto minmax(0, 1fr); } | |
| 8 | #app { width: 100%; aspect-ratio: 16 / 9; } | |
| 9 | /* Typing, the keyboard takes half the screen: the picture gives way to the chat. */ | |
| 10 | #shell.typing { grid-template-rows: minmax(0, 24%) auto minmax(0, 1fr); } | |
| 11 | #shell.typing #app { aspect-ratio: auto; } | |
| 12 | ||
| 13 | /* One status strip: what the overlays on the picture repeated lives in it instead. */ | |
| 14 | #top .info, #driverTag { display: none; } | |
| 15 | #strip { min-height: 64px; gap: 8px; padding-top: 6px; padding-bottom: 6px; } | |
| 16 | #strip .who { display: grid; gap: 1px; line-height: 1.3; } | |
| 17 | #driverLine { font-size: 14px; } | |
| 18 | #clock { font-size: 12px; min-height: 1.3em; } /* its line is there before its words: the strip never grows under the panel */ | |
| 19 | #linkLine { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; font-weight: 600; color: var(); white-space: nowrap; overflow: hidden; } | |
| 20 | #linkLine .dot { background: currentColor; } | |
| 21 | #linkLine.ok { color: var(); } #linkLine.warn { color: var(); } #linkLine.bad { color: var(); } | |
| 22 | #linkWord { overflow: hidden; text-overflow: ellipsis; } | |
| 23 | ||
| 24 | /* The tab bar: Drive first, short names, the Machine panel left to wider screens. | |
| 25 | 56 px tall over the home indicator's inset; the forge pill keeps the corner the bar's right padding leaves it. */ | |
| 26 | #tabs .long { display: none; } #tabs .short { display: inline; } | |
| 27 | #tabs button { min-height: 56px; } | |
| 28 | /* Drive is a tab from the first paint, before the page knows whose turn it is: the bar never reflows under the thumb. */ | |
| 29 | #tabs #t-controls { display: block ; } | |
| 30 | #t-controls { order: 1; } #t-queue { order: 2; } #t-chat { order: 3; } #t-admin { order: 4; } | |
| 31 | #t-machine { display: none; } |
Software/so101/src/viewer.html +23 −6
| @@ -86,6 +86,8 @@ | ||
| 86 | 86 | #driverLine { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #driverLine.none { color: var(); font-weight: 500; } |
| 87 | 87 | #clock { color: var(); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } #clock.idle { color: var(); } |
| 88 | 88 | #capLine { color: var(); font-size: 12px; } #capLine:empty { display: none; } |
| 89 | /* a phone held upright shows these (src/ui/mobile.css) */ | |
| 90 | #linkLine, #tabs .short { display: none; } | |
| 89 | 91 | #driverLine.paused { color: var(); } |
| 90 | 92 | #turnActions { display: flex; gap: 6px; } #turnActions:empty { display: none; } |
| 91 | 93 | .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); } |
| @@ -292,6 +294,7 @@ | ||
| 292 | 294 | @media (max-width: 420px) { #top .label { display: none; } #link { max-width: 30vw; } } |
| 293 | 295 | @media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none ; animation: none ; scroll-behavior: auto ; } } |
| 294 | 296 | </style> |
| 297 | <link rel="stylesheet" href="/ui/__VERSION__/mobile.css" media="(orientation: portrait) and (max-width: 640px)"> | |
| 295 | 298 | </head> |
| 296 | 299 | <body> |
| 297 | 300 | <div id="shell"> |
| @@ -318,7 +321,7 @@ | ||
| 318 | 321 | |
| 319 | 322 | <section id="strip" aria-label="Who drives" aria-live="polite"> |
| 320 | 323 | <div id="ring" hidden aria-hidden="true"><span id="ringN"></span></div> |
| 321 | <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="capLine"></div></div> | |
| 324 | <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock" aria-live="off"></div><div id="linkLine" class="dim"><span class="dot"></span><span id="linkWord">Connecting…</span></div><div id="capLine"></div></div> | |
| 322 | 325 | <div id="turnActions"></div> |
| 323 | 326 | <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button> |
| 324 | 327 | <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> |
| @@ -449,8 +452,8 @@ | ||
| 449 | 452 | <nav id="tabs" role="tablist" aria-label="Sheet"> |
| 450 | 453 | <button role="tab" id="t-chat" data-tab="chat" aria-controls="tab-chat" aria-selected="true">Chat<span class="badge" id="unread"></span></button> |
| 451 | 454 | <button role="tab" id="t-queue" data-tab="queue" aria-controls="tab-queue" aria-selected="false">Queue<span class="badge" id="waiting"></span></button> |
| 452 | <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden>Controls</button> | |
| 453 | <button role="tab" id="t-admin" data-tab="admin" aria-controls="tab-admin" aria-selected="false" hidden>Admin</button> | |
| 455 | <button role="tab" id="t-controls" data-tab="controls" aria-controls="tab-controls" aria-selected="false" hidden><span class="long">Controls</span><span class="short">Drive</span></button> | |
| 456 | <button role="tab" id="t-admin" data-tab="admin" aria-controls="tab-admin" aria-selected="false" hidden><span class="long">Admin</span><span class="short">Mod</span></button> | |
| 454 | 457 | <button role="tab" id="t-machine" data-tab="machine" aria-controls="tab-machine" aria-selected="false">Machine</button> |
| 455 | 458 | </nav> |
| 456 | 459 | </section> |
| @@ -547,6 +550,9 @@ | ||
| 547 | 550 | }; |
| 548 | 551 | $("sheetToggle").onclick = () => setBare(!shell.classList.contains("bare")); |
| 549 | 552 | const sideways = matchMedia("(orientation: landscape) and (max-height: 500px)"); |
| 553 | /** A phone held upright (src/ui/mobile.css): Drive is always a tab. */ | |
| 554 | const upright = matchMedia("(orientation: portrait) and (max-width: 640px)"); | |
| 555 | upright.addEventListener("change", () => { applyLock(); if (upright.matches && tab === "machine") showTab(relayed ? "chat" : "controls"); }); | |
| 550 | 556 | let tab = "chat"; |
| 551 | 557 | /** The Machine tab's panel, once it is loaded (below); here, because leaving any tab closes it. */ |
| 552 | 558 | const machine = { panel: null }; |
| @@ -567,7 +573,8 @@ | ||
| 567 | 573 | for (const b of $("tabs").querySelectorAll("[role=tab]")) b.onclick = () => showTab(b.dataset.tab); |
| 568 | 574 | $("tabs").addEventListener("keydown", (e) => { |
| 569 | 575 | if (e.key !== "ArrowLeft" && e.key !== "ArrowRight") return; |
| 570 | const shown = [...$("tabs").querySelectorAll("[role=tab]:not([hidden])")]; | |
| 576 | // in the order on screen (src/ui/mobile.css) | |
| 577 | const shown = [...$("tabs").querySelectorAll("[role=tab]")].filter((b) => b.getClientRects().length).sort((a, b) => getComputedStyle(a).order - getComputedStyle(b).order); | |
| 571 | 578 | const i = shown.findIndex((b) => b.dataset.tab === tab); |
| 572 | 579 | showTab(shown[(i + (e.key === "ArrowRight" ? 1 : shown.length - 1)) % shown.length].dataset.tab, true); |
| 573 | 580 | }); |
| @@ -597,6 +604,7 @@ | ||
| 597 | 604 | const other = linkMode !== null && realArm(l.mode) !== realArm(linkMode); |
| 598 | 605 | if ((other || (l.mode === "live" && !limits?.ok)) && linkMode !== null && !stream.ws && !leader) return location.reload(); |
| 599 | 606 | if (linkMode === null) linkMode = l.mode; |
| 607 | showLink(); | |
| 600 | 608 | } |
| 601 | 609 | setTimeout(pollLink, l?.mode === "live" ? 3000 : 1000); |
| 602 | 610 | } |
| @@ -1568,7 +1576,7 @@ | ||
| 1568 | 1576 | const why = explainLock(); |
| 1569 | 1577 | if (why) intent.clear(); |
| 1570 | 1578 | const can = mayDrive() && !why, owner = isOwner(); |
| 1571 | $("t-controls").hidden = !mayDrive(); | |
| 1579 | $("t-controls").hidden = !mayDrive() && !upright.matches; | |
| 1572 | 1580 | $("t-admin").hidden = !owner; |
| 1573 | 1581 | $("t-chat").hidden = $("t-queue").hidden = !relayed; |
| 1574 | 1582 | for (const id of ["joints", "poses", "drive", "reach", "touch", "sticks"]) $(id).inert = !can; |
| @@ -1942,7 +1950,7 @@ | ||
| 1942 | 1950 | if (!started) return void (early = d); |
| 1943 | 1951 | { |
| 1944 | 1952 | const was = $("why").textContent; |
| 1945 | status = d; | |
| 1953 | status = d; statusFailed = false; showLink(); | |
| 1946 | 1954 | driver.seed(d.joints.filter((j) => j.position != null).map((j) => [j.id, j.position])); |
| 1947 | 1955 | if ((explainLock() ?? "") !== was) applyLock(); |
| 1948 | 1956 | // Stopped, reconnecting or no longer this person's turn: a held thumb lets go, and its zero goes out now. |
| @@ -1965,7 +1973,16 @@ | ||
| 1965 | 1973 | $("readout").innerHTML = `<span>lowest part <b>${Number.isFinite(d.lowestMm) ? d.lowestMm : "—"} mm</b> above the table</span><span>zone <b>${d.zone === "enforce" || d.zone === "warn" || d.zone === "off" ? d.zone : "—"}</b></span>`; |
| 1966 | 1974 | } |
| 1967 | 1975 | } |
| 1976 | /** The strip's word for the arm's connection (src/ui/link-state.js). */ | |
| 1977 | let statusFailed = false, linkState = null; | |
| 1978 | import("/ui/__VERSION__/link-state.js").then((m) => { linkState = m.linkState; showLink(); }); | |
| 1979 | function showLink() { | |
| 1980 | if (!linkState) return; | |
| 1981 | const { text, tone } = linkState({ relayed, link: linkNow, status, failed: statusFailed }); | |
| 1982 | $("linkLine").className = tone; $("linkWord").textContent = text; | |
| 1983 | } | |
| 1968 | 1984 | function noStatus() { |
| 1985 | statusFailed = true; showLink(); | |
| 1969 | 1986 | const reconnecting = linkNow === "reconnecting"; |
| 1970 | 1987 | $("dot").className = reconnecting ? "dot warn" : "dot"; $("state").textContent = reconnecting ? "reconnecting…" : "no arm"; |
| 1971 | 1988 | } |
new above
offline