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

Closed opened this in answer to
Closed without merging

smith/arm:smith/51-mobile-chat-the-keyboard-never-covers-th → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +87 −11
Software/README.md +1 −1
@@ -389,7 +389,7 @@ the app's own page.
389389 **On a phone.** The page is laid out for one thumb, phone first. The view
390390 (camera or 3D) sits on top at full width. Under it a status strip shows who
391391 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
393393 that is a sheet with tabs at the bottom edge: **Chat**, **Queue**,
394394 **Controls** (only on your turn, and it opens by itself when your turn
395395 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", () => {
134134 expect(page).toContain("prefers-reduced-motion: reduce");
135135 expect(page).toMatch(/#tabs \{[^}]*var\(--pill\)/);
136136 });
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 });
137146 });
138147
139148 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 @@
5353 [inert] { opacity: .5; }
5454
5555 #shell { position: fixed; left: 0; right: 0; top: var(--vv-top, 0px); height: var(--vv-h, 100dvh); display: grid; grid-template-columns: 100%; grid-template-rows: minmax(0, var(--view)) auto minmax(0, 1fr); grid-template-areas: "view" "strip" "sheet"; }
56 #shell.typing { --view: 24%; }
56 #shell.typing { --view: 120px; } /* the keyboard is up: the view shrinks to a mini player */
5757
5858 /* the view: cameras and the 3D model, always on black */
5959 #app { grid-area: view; position: relative; min-height: 0; background: #000; color: #e8eaed; overflow: hidden; }
@@ -112,7 +112,14 @@
112112 #chat .line b { color: var(--fg2); font-weight: 650; margin-right: 6px; } #chat .line.me b { color: var(--link); }
113113 #chat .line.held { background: var(--blue-soft); }
114114 #chat.moderated .line:not(.sys) { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: context-menu; }
115 #chat .sys { color: var(--dim); font-style: italic; }
115 #chat .sys { color: var(--dim); 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(--blue); border-color: var(--blue); color: var(--on-blue); 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(--safe-l)); 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; } }
116123 #say { display: flex; gap: 8px; padding: 8px calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); border-top: 1px solid var(--line); }
117124 #say input { flex: 1; min-width: 0; }
118125 #sayNote { color: var(--dim); font-size: 13px; padding: 10px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l)); border-top: 1px solid var(--line); } #sayNote:empty { display: none; }
@@ -240,6 +247,7 @@
240247 <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>
241248 <button id="fs" title="F">Fullscreen</button>
242249 </div>
250 <div id="ticker" aria-hidden="true"></div>
243251 <div id="banner" role="alert"></div>
244252 <div id="msg" role="status"></div>
245253 </div>
@@ -248,14 +256,15 @@
248256 <div class="who"><div id="driverLine" class="none">Connecting…</div><div id="clock"></div><div id="capLine"></div></div>
249257 <div id="turnActions"></div>
250258 <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>
253261 </section>
254262
255263 <section id="sheet" aria-label="Chat, queue and controls">
256264 <div id="notice" role="status" hidden></div>
257265 <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>
259268 <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>
260269 <div id="sayNote"></div>
261270 </div>
@@ -458,6 +467,7 @@
458467 </div>
459468 <script type="module">
460469 import { cameraPlan } from "/ui/__VERSION__/camera-plan.js";
470 import { nearBottom, syncTicker } from "/ui/__VERSION__/chat-ticker.js";
461471 import { mapLeaderFrame, parseCalibration } from "/leader-map.js";
462472
463473 const $ = (id) => document.getElementById(id);
@@ -497,7 +507,7 @@
497507 $(b.getAttribute("aria-controls")).hidden = !on;
498508 if (on && focus) b.focus();
499509 }
500 if (name === "chat") { $("unread").textContent = ""; chatBox.scrollTop = chatBox.scrollHeight; }
510 if (name === "chat") { $("unread").textContent = ""; chatBox.scrollTop = chatBox.scrollHeight; $("newMsgs").hidden = true; }
501511 if (name === "controls") load3D();
502512 if (name === "admin") loadSettings();
503513 }
@@ -1287,6 +1297,7 @@
12871297 if (!can) reachEnd();
12881298 if (!can && leaderStreaming()) stopLeaderDrive(); // the server closes it too; the page need not wait for that
12891299 // Your turn just came: open the controls. It just ended: back to the chat.
1300 shell.classList.toggle("driving", mayDrive());
12901301 if (mayDrive() !== drove) { drove = mayDrive(); if (relayed) showTab(drove ? "controls" : "chat"); }
12911302 else if ($(`t-${tab}`).hidden) showTab(tab);
12921303 }
@@ -1386,6 +1397,8 @@
13861397 button.disabled = false;
13871398 };
13881399 const chatBox = $("chat");
1400 $("newMsgs").onclick = () => { chatBox.scrollTop = chatBox.scrollHeight; $("newMsgs").hidden = true; };
1401 chatBox.addEventListener("scroll", () => { if (nearBottom(chatBox)) $("newMsgs").hidden = true; });
13891402 function chatLine(m) {
13901403 const me = lobby.hello?.you;
13911404 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 @@
13961409 return line;
13971410 }
13981411 function addChat(lines, replace = false) {
1399 const atEnd = chatBox.scrollHeight - chatBox.scrollTop - chatBox.clientHeight < 40;
1412 const atEnd = nearBottom(chatBox);
14001413 if (replace) chatBox.replaceChildren();
14011414 chatBox.append(...lines.map(chatLine));
14021415 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"));
14041419 if (!replace && tab !== "chat") $("unread").textContent = String(Math.min(99, Number($("unread").textContent || 0) + lines.length));
14051420 }
14061421 // Moderation on a phone: long-press a line (or right-click it, or Enter on it) for delete and mute.
@@ -1445,7 +1460,7 @@
14451460 else if (m.type === "state") { lobby.offset = m.now - Date.now(); lobby.state = m; }
14461461 else if (m.type === "chat") return addChat(m.messages, true);
14471462 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")); }
14491464 else if (m.type === "muted") lobby.mutedList = m.muted;
14501465 else if (m.type === "banned") lobby.bannedList = m.banned;
14511466 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 @@
15891604 if (Boolean(d.estop) !== wasStopped) applyLock();
15901605 $("dot").className = "dot on";
15911606 $("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";
15931608 $("record").textContent = d.driving === "record" ? "■ Stop recording" : "● Record";
15941609 for (const id of ["hold", "releaseBtn", "play"]) $(id).disabled = d.driving !== null;
15951610 if (tab === "controls") render(d);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs