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

Migrated from github.com/Trevato/SO-ARM100

workbenchthis machine

src/ui/video-pane.js chooses H.264 or the frame feed for a camera and builds a labelled 44 px quality select - module and test only #410

Merged opened this

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

Merged

smith/arm:smith/382-src-ui-video-pane-js-chooses-h-264-or-th → main 1 commit fork 1 thread · 1 unresolved

  • Merged. smith/382-src-ui-video-pane-js-chooses-h-264-or-th was merged into main as 6ea12c2.

Review

Sign in to review this change.
2 files changed +67 −0
Software/so101/src/ui/video-pane.js added +28
@@ -0,0 +1,28 @@
1 /**
2 * Which feed a camera gets, and the quality control beside it. Plain ESM, served at /ui/ and imported by the tests.
3 * Nothing here touches the network or the page: the caller passes in what the browser can decode and its document.
4 */
5
6 /** 'h264' only when the relay flags the camera and the browser can decode it, else the frame feed. @param {{ h264?: unknown }} camera @param {boolean} canDecode */
7 export function choose(camera, canDecode) {
8 return camera?.h264 === true && canDecode === true ? "h264" : "frames";
9 }
10
11 /**
12 * A labelled quality select, at least 44x44 px to touch. Option text goes in through textContent.
13 * @param {any} doc @param {{ value: string, label: string }[]} options @param {(value: string) => void} onChange
14 */
15 export function qualitySelect(doc, options, onChange) {
16 const select = doc.createElement("select");
17 select.setAttribute("aria-label", "Video quality");
18 select.style.minWidth = "44px";

Nice: the 44px minimum is applied inline. When wiring, also set a default selected value so the select reflects the active quality on first paint.

19 select.style.minHeight = "44px";
20 for (const o of options) {
21 const opt = doc.createElement("option");
22 opt.value = String(o.value);
23 opt.textContent = String(o.label);
24 select.appendChild(opt);
25 }
26 select.addEventListener("change", () => onChange(select.value));
27 return select;
28 }
Software/so101/src/ui/video-pane.test.ts added +39
@@ -0,0 +1,39 @@
1 import { describe, expect, test } from "bun:test";
2 import { choose, qualitySelect } from "./video-pane.js";
3
4 function fakeDoc() {
5 const el = (tag: string) => {
6 const attrs: Record<string, string> = {};
7 const listeners: Record<string, () => void> = {};
8 return {
9 tag, style: {} as Record<string, string>, children: [] as any[], value: "", textContent: "", attrs, listeners,
10 setAttribute: (k: string, v: string) => void (attrs[k] = v),
11 appendChild(c: any) { this.children.push(c); },
12 addEventListener: (e: string, f: () => void) => void (listeners[e] = f),
13 };
14 };
15 return { createElement: el };
16 }
17
18 describe("the video pane", () => {
19 test("h264 only when the camera is flagged and the browser can decode it", () => {
20 expect(choose({ h264: true }, true)).toBe("h264");
21 expect(choose({ h264: true }, false)).toBe("frames");
22 expect(choose({ h264: false }, true)).toBe("frames");
23 expect(choose({}, false)).toBe("frames");
24 expect(choose({ h264: "true" }, true)).toBe("frames");
25 });
26
27 test("the quality select is labelled, 44 px at least, and its text is set as text", () => {
28 const heard: string[] = [];
29 const s: any = qualitySelect(fakeDoc(), [{ value: "hd", label: "<b>HD</b>" }, { value: "sd", label: "SD" }], (v) => heard.push(v));
30 expect(s.tag).toBe("select");
31 expect(s.attrs["aria-label"]).toBe("Video quality");
32 expect(s.style.minWidth).toBe("44px");
33 expect(s.style.minHeight).toBe("44px");
34 expect(s.children.map((o: any) => [o.value, o.textContent])).toEqual([["hd", "<b>HD</b>"], ["sd", "SD"]]);
35 s.value = "sd";
36 s.listeners.change();
37 expect(heard).toEqual(["sd"]);
38 });
39 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs