Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
Mobile chat: the keyboard never covers the composer, the video shrinks to a mini player, and chat floats over the video for watchers #55
smith/arm:smith/51-mobile-chat-the-keyboard-never-covers-th → main 2 commits fork
5 files
changed +87
−11
Software/README.md +1 −1
| @@ -389,7 +389,7 @@ the app's own page. | ||
| 389 | 389 | **On a phone.** The page is laid out for one thumb, phone first. The view |
| 390 | 390 | (camera or 3D) sits on top at full width. Under it a status strip shows who |
| 391 | 391 | drives, your place in the line, the time left, the turn's one button, and |
| 392 | the red **Stop**. Stop is there whenever you drive, and for the owner. Below | |
| 392 | the red **E-STOP** (the emergency stop) and, when you drive, **End move**. These labels are the page's; the terminal door keeps its own commands. End move is there whenever you drive, and for the owner. Below | |
| 393 | 393 | that is a sheet with tabs at the bottom edge: **Chat**, **Queue**, |
| 394 | 394 | **Controls** (only on your turn, and it opens by itself when your turn |
| 395 | 395 | starts) and **Admin** (the owner: the room, the safe zone, the trims, |
Software/so101/src/server.test.ts +9
| @@ -134,6 +134,15 @@ describe("viewer page", () => { | ||
| 134 | 134 | expect(page).toContain("prefers-reduced-motion: reduce"); |
| 135 | 135 | expect(page).toMatch(/#tabs \{[^}]*var\(--pill\)/); |
| 136 | 136 | }); |
| 137 | ||
| 138 | test("chat on a phone: a 120px mini player under the keyboard, a new-messages pill, the last three lines over the video, one E-stop", async () => { | |
| 139 | const page = await (await fetch(`${base}/`)).text(); | |
| 140 | expect(page).toContain("#shell.typing { --view: 120px; }"); | |
| 141 | expect(page).toContain('id="newMsgs"'); | |
| 142 | expect(page).toContain('id="ticker"'); | |
| 143 | expect(page).toContain(">E-STOP</button>"); | |
| 144 | expect(page).toContain(">End move</button>"); | |
| 145 | }); | |
| 137 | 146 | }); |
| 138 | 147 | |
| 139 | 148 | describe("moves over HTTP", () => { |
Software/so101/src/ui/chat-ticker.js added +21
| @@ -0,0 +1,21 @@ | ||
| 1 | /** | |
| 2 | * The chat over the video: the last lines of the chat log, copied (text only, no tap targets) into the ticker, and the | |
| 3 | * "near the bottom" test that decides between following the chat and showing the new-messages pill. Plain ESM, served | |
| 4 | * at /ui/ and imported by the tests. The ticker is rebuilt from the log every time, so a deleted line leaves both. | |
| 5 | */ | |
| 6 | ||
| 7 | /** Rebuild `ticker` from the last `count` children of `chat`. */ | |
| 8 | export function syncTicker(chat, ticker, count = 3) { | |
| 9 | const copies = [...chat.children].slice(-count).map((line) => { | |
| 10 | const copy = line.cloneNode(true); | |
| 11 | copy.removeAttribute("tabindex"); copy.removeAttribute("title"); | |
| 12 | copy.className = line.classList.contains("sys") ? "sys" : ""; | |
| 13 | return copy; | |
| 14 | }); | |
| 15 | ticker.replaceChildren(...copies); | |
| 16 | } | |
| 17 | ||
| 18 | /** True when the box is scrolled to within `slack` pixels of its end. */ | |
| 19 | export function nearBottom(box, slack = 40) { | |
| 20 | return box.scrollHeight - box.scrollTop - box.clientHeight < slack; | |
| 21 | } |
Software/so101/src/ui/chat-ticker.test.ts added +31
| @@ -0,0 +1,31 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { nearBottom, syncTicker } from "./chat-ticker.js"; | |
| 3 | ||
| 4 | // Just enough DOM: a line that clones, a box that holds children. | |
| 5 | const line = (id: number, sys = false): any => ({ | |
| 6 | id, className: sys ? "line sys" : "line", classList: { contains: (c: string) => sys && c === "sys" }, | |
| 7 | removeAttribute() {}, cloneNode() { return { ...this }; }, | |
| 8 | }); | |
| 9 | const box = (children: any[]): any => ({ children, replaceChildren(...c: any[]) { this.children = c; } }); | |
| 10 | ||
| 11 | describe("the chat ticker", () => { | |
| 12 | test("shows the last three lines, system lines marked", () => { | |
| 13 | const chat = box([line(1), line(2), line(3, true), line(4)]), ticker = box([]); | |
| 14 | syncTicker(chat, ticker); | |
| 15 | expect(ticker.children.map((c: any) => c.id)).toEqual([2, 3, 4]); | |
| 16 | expect(ticker.children.map((c: any) => c.className)).toEqual(["", "sys", ""]); | |
| 17 | }); | |
| 18 | ||
| 19 | test("a deleted line leaves the ticker when it is rebuilt, and an older line takes its place", () => { | |
| 20 | const chat = box([line(1), line(2), line(3), line(4)]), ticker = box([]); | |
| 21 | syncTicker(chat, ticker); | |
| 22 | chat.children = chat.children.filter((l: any) => l.id !== 4); // the 'unsaid' branch removes it from the log | |
| 23 | syncTicker(chat, ticker); | |
| 24 | expect(ticker.children.map((c: any) => c.id)).toEqual([1, 2, 3]); | |
| 25 | }); | |
| 26 | ||
| 27 | test("near the bottom is within 40px of the end", () => { | |
| 28 | expect(nearBottom({ scrollHeight: 1000, scrollTop: 570, clientHeight: 400 })).toBe(true); | |
| 29 | expect(nearBottom({ scrollHeight: 1000, scrollTop: 500, clientHeight: 400 })).toBe(false); | |
| 30 | }); | |
| 31 | }); |
Software/so101/src/viewer.html +25 −10
| @@ -53,7 +53,7 @@ | ||
| 53 | 53 | [inert] { opacity: .5; } |
| 54 | 54 | |
| 55 | 55 | #shell { position: fixed; left: 0; right: 0; top: var(, 0px); height: var(, 100dvh); display: grid; grid-template-columns: 100%; grid-template-rows: minmax(0, var()) auto minmax(0, 1fr); grid-template-areas: "view" "strip" "sheet"; } |
| 56 | #shell.typing { : 24%; } | |
| 56 | #shell.typing { : 120px; } /* the keyboard is up: the view shrinks to a mini player */ | |
| 57 | 57 | |
| 58 | 58 | /* the view: cameras and the 3D model, always on black */ |
| 59 | 59 | #app { grid-area: view; position: relative; min-height: 0; background: #000; color: #e8eaed; overflow: hidden; } |
| @@ -112,7 +112,14 @@ | ||
| 112 | 112 | #chat .line b { color: var(); font-weight: 650; margin-right: 6px; } #chat .line.me b { color: var(); } |
| 113 | 113 | #chat .line.held { background: var(); } |
| 114 | 114 | #chat.moderated .line:not(.sys) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: context-menu; } |
| 115 | #chat .sys { color: var(); font-style: italic; } | |
| 115 | #chat .sys { color: var(); font-style: italic; font-size: 13px; opacity: .8; } | |
| 116 | #chatWrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; } | |
| 117 | #newMsgs { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 2; min-height: 36px; padding: 0 14px; border-radius: 18px; background: var(); border-color: var(); color: var(); box-shadow: 0 2px 8px rgba(0,0,0,.35); } | |
| 118 | /* what watchers see over the video: the last three lines, transparent, never in the way of a tap */ | |
| 119 | #ticker { position: absolute; left: calc(8px + var()); bottom: 8px; z-index: 4; max-width: min(70%, 420px); display: flex; flex-direction: column; gap: 2px; pointer-events: none; font-size: 13px; color: #fff; text-shadow: 0 1px 3px #000; overflow-wrap: anywhere; } | |
| 120 | #ticker div { padding: 2px 8px; border-radius: 10px; background: rgba(0,0,0,.35); } #ticker .sys { opacity: .7; font-style: italic; } #ticker b { margin-right: 5px; } | |
| 121 | #ticker:empty, #shell.typing #ticker, #shell.driving #ticker { display: none; } | |
| 122 | @media (min-width: 900px) and (min-height: 501px) { #ticker { display: none; } } | |
| 116 | 123 | #say { display: flex; gap: 8px; padding: 8px calc(12px + var()) 8px calc(12px + var()); border-top: 1px solid var(); } |
| 117 | 124 | #say input { flex: 1; min-width: 0; } |
| 118 | 125 | #sayNote { color: var(); font-size: 13px; padding: 10px calc(12px + var()) 10px calc(12px + var()); border-top: 1px solid var(); } #sayNote:empty { display: none; } |
| @@ -240,6 +247,7 @@ | ||
| 240 | 247 | <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> |
| 241 | 248 | <button id="fs" title="F">Fullscreen</button> |
| 242 | 249 | </div> |
| 250 | <div id="ticker" aria-hidden="true"></div> | |
| 243 | 251 | <div id="banner" role="alert"></div> |
| 244 | 252 | <div id="msg" role="status"></div> |
| 245 | 253 | </div> |
| @@ -248,14 +256,15 @@ | ||
| 248 | 256 | <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock"></div><div id="capLine"></div></div> |
| 249 | 257 | <div id="turnActions"></div> |
| 250 | 258 | <button id="sheetToggle" hidden aria-controls="sheet" aria-expanded="true">Hide</button> |
| 251 | <button id="stop" class="danger" hidden title="End what the arm is doing and hold (space)">Stop</button> | |
| 252 | <button id="estop" class="estop" title="Emergency stop (Esc): halt, hold with torque, until an admin clears it" aria-label="Emergency stop">Stop</button> | |
| 259 | <button id="stop" class="danger" hidden title="End what the arm is doing and hold (space)">End move</button> | |
| 260 | <button id="estop" class="estop" title="Emergency stop (Esc): halt, hold with torque, until an admin clears it" aria-label="Emergency stop">E-STOP</button> | |
| 253 | 261 | </section> |
| 254 | 262 | |
| 255 | 263 | <section id="sheet" aria-label="Chat, queue and controls"> |
| 256 | 264 | <div id="notice" role="status" hidden></div> |
| 257 | 265 | <div class="tab" id="tab-chat" role="tabpanel" aria-labelledby="t-chat"> |
| 258 | <div id="chat" role="log" aria-label="Chat"></div> | |
| 266 | <div id="chatWrap"><div id="chat" role="log" aria-label="Chat"></div> | |
| 267 | <button id="newMsgs" type="button" hidden>New messages ↓</button></div> | |
| 259 | 268 | <form id="say" hidden><input id="sayText" type="text" maxlength="500" autocomplete="off" enterkeyhint="send" placeholder="Say something" aria-label="Message"><button class="go">Send</button></form> |
| 260 | 269 | <div id="sayNote"></div> |
| 261 | 270 | </div> |
| @@ -458,6 +467,7 @@ | ||
| 458 | 467 | </div> |
| 459 | 468 | <script type="module"> |
| 460 | 469 | import { cameraPlan } from "/ui/__VERSION__/camera-plan.js"; |
| 470 | import { nearBottom, syncTicker } from "/ui/__VERSION__/chat-ticker.js"; | |
| 461 | 471 | import { mapLeaderFrame, parseCalibration } from "/leader-map.js"; |
| 462 | 472 | |
| 463 | 473 | const $ = (id) => document.getElementById(id); |
| @@ -497,7 +507,7 @@ | ||
| 497 | 507 | $(b.getAttribute("aria-controls")).hidden = !on; |
| 498 | 508 | if (on && focus) b.focus(); |
| 499 | 509 | } |
| 500 | if (name === "chat") { $("unread").textContent = ""; chatBox.scrollTop = chatBox.scrollHeight; } | |
| 510 | if (name === "chat") { $("unread").textContent = ""; chatBox.scrollTop = chatBox.scrollHeight; $("newMsgs").hidden = true; } | |
| 501 | 511 | if (name === "controls") load3D(); |
| 502 | 512 | if (name === "admin") loadSettings(); |
| 503 | 513 | } |
| @@ -1287,6 +1297,7 @@ | ||
| 1287 | 1297 | if (!can) reachEnd(); |
| 1288 | 1298 | if (!can && leaderStreaming()) stopLeaderDrive(); // the server closes it too; the page need not wait for that |
| 1289 | 1299 | // Your turn just came: open the controls. It just ended: back to the chat. |
| 1300 | shell.classList.toggle("driving", mayDrive()); | |
| 1290 | 1301 | if (mayDrive() !== drove) { drove = mayDrive(); if (relayed) showTab(drove ? "controls" : "chat"); } |
| 1291 | 1302 | else if ($(`t-${tab}`).hidden) showTab(tab); |
| 1292 | 1303 | } |
| @@ -1386,6 +1397,8 @@ | ||
| 1386 | 1397 | button.disabled = false; |
| 1387 | 1398 | }; |
| 1388 | 1399 | const chatBox = $("chat"); |
| 1400 | $("newMsgs").onclick = () => { chatBox.scrollTop = chatBox.scrollHeight; $("newMsgs").hidden = true; }; | |
| 1401 | chatBox.addEventListener("scroll", () => { if (nearBottom(chatBox)) $("newMsgs").hidden = true; }); | |
| 1389 | 1402 | function chatLine(m) { |
| 1390 | 1403 | const me = lobby.hello?.you; |
| 1391 | 1404 | const line = el("div", { className: m.from ? `line${me && m.from.id === me.id ? " me" : ""}` : "line sys", title: new Date(m.at).toLocaleTimeString() }); |
| @@ -1396,11 +1409,13 @@ | ||
| 1396 | 1409 | return line; |
| 1397 | 1410 | } |
| 1398 | 1411 | function addChat(lines, replace = false) { |
| 1399 | const atEnd = chatBox.scrollHeight - chatBox.scrollTop - chatBox.clientHeight < 40; | |
| 1412 | const atEnd = nearBottom(chatBox); | |
| 1400 | 1413 | if (replace) chatBox.replaceChildren(); |
| 1401 | 1414 | chatBox.append(...lines.map(chatLine)); |
| 1402 | 1415 | while (chatBox.children.length > 200) chatBox.firstChild.remove(); |
| 1403 | if (atEnd || replace) chatBox.scrollTop = chatBox.scrollHeight; | |
| 1416 | if (atEnd || replace) { chatBox.scrollTop = chatBox.scrollHeight; $("newMsgs").hidden = true; } | |
| 1417 | else if (lines.length) $("newMsgs").hidden = false; | |
| 1418 | syncTicker(chatBox, $("ticker")); | |
| 1404 | 1419 | if (!replace && tab !== "chat") $("unread").textContent = String(Math.min(99, Number($("unread").textContent || 0) + lines.length)); |
| 1405 | 1420 | } |
| 1406 | 1421 | // Moderation on a phone: long-press a line (or right-click it, or Enter on it) for delete and mute. |
| @@ -1445,7 +1460,7 @@ | ||
| 1445 | 1460 | else if (m.type === "state") { lobby.offset = m.now - Date.now(); lobby.state = m; } |
| 1446 | 1461 | else if (m.type === "chat") return addChat(m.messages, true); |
| 1447 | 1462 | else if (m.type === "said") return addChat([m.message]); |
| 1448 | else if (m.type === "unsaid") return chatBox.querySelector(`[data-id="${Number(m.id)}"]`)?.remove(); | |
| 1463 | else if (m.type === "unsaid") { chatBox.querySelector(`[data-id="${Number(m.id)}"]`)?.remove(); return syncTicker(chatBox, $("ticker")); } | |
| 1449 | 1464 | else if (m.type === "muted") lobby.mutedList = m.muted; |
| 1450 | 1465 | else if (m.type === "banned") lobby.bannedList = m.banned; |
| 1451 | 1466 | else if (m.type === "words") { const f = $("wordsForm"); if (document.activeElement !== f.elements.words) f.elements.words.value = m.words.join(", "); if (wordsSent) { wordsSent = false; msg(`Word filter saved: ${m.words.length} word${m.words.length === 1 ? "" : "s"}.`); } } |
| @@ -1589,7 +1604,7 @@ | ||
| 1589 | 1604 | if (Boolean(d.estop) !== wasStopped) applyLock(); |
| 1590 | 1605 | $("dot").className = "dot on"; |
| 1591 | 1606 | $("state").textContent = d.driving === null ? "idle" : d.driving === "record" ? `recording ${d.recording}` : leaderStreaming() ? `leader · ${leader.frames} frames` : d.driving; |
| 1592 | $("estop").classList.toggle("on", Boolean(d.estop)); $("estop").textContent = d.estop ? "Stopped" : "Stop"; | |
| 1607 | $("estop").classList.toggle("on", Boolean(d.estop)); $("estop").textContent = d.estop ? "Stopped" : "E-STOP"; | |
| 1593 | 1608 | $("record").textContent = d.driving === "record" ? "■ Stop recording" : "● Record"; |
| 1594 | 1609 | for (const id of ["hold", "releaseBtn", "play"]) $(id).disabled = d.driving !== null; |
| 1595 | 1610 | if (tab === "controls") render(d); |
new above
offline