From 1cec607a48f3ef43fc5ba1dde01798eb9105fdea Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 25 Nov 2026 20:37:32 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m2/huh/tracks-and-discovery.md Quest-Claim: 1ffa228550fc8d0a From 665508ed5c43b14325bfed4d68f4374b41bb26ba Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 25 Nov 2026 20:53:34 -0800 Subject: [PATCH 2/3] feat(huh): Sections 4-5 (on-demand tracks and live discovery) Section 4 is a track rack for one hang broadcast: pull tracks or pick a viewer preset, and only the pulled tracks' encoders run, with the uplink meter and live catalog.json following. An E2EE toggle, labeled as the moq-e2ee project draft, swaps what the relay sees for opaque names. The displayed catalog is checked against @moq/hang's own schema. Section 5 is a three-relay announce mesh: publishers come online and offline, and the rosters of sessions watching room/* or boat/* update as the gossip lands, with a seeded property test against an oracle. Sections now take a list of badges, so a standard feature and its project-draft extension each get their own. Co-Authored-By: Claude Opus 5.5 --- bun.lock | 1 + package.json | 1 + quest/m2/huh/routing-and-timestamps.md | 4 - quest/m2/huh/tracks-and-discovery.md | 50 ----- src/components/huh/discovery.tsx | 250 +++++++++++++++++++++++++ src/components/huh/gossip.test.ts | 99 ++++++++++ src/components/huh/gossip.ts | 110 +++++++++++ src/components/huh/rack.test.ts | 47 +++++ src/components/huh/rack.ts | 91 +++++++++ src/components/huh/section.astro | 9 +- src/components/huh/tracks.tsx | 231 +++++++++++++++++++++++ src/unreleased/huh.astro | 80 +++++++- 12 files changed, 906 insertions(+), 67 deletions(-) delete mode 100644 quest/m2/huh/tracks-and-discovery.md create mode 100644 src/components/huh/discovery.tsx create mode 100644 src/components/huh/gossip.test.ts create mode 100644 src/components/huh/gossip.ts create mode 100644 src/components/huh/rack.test.ts create mode 100644 src/components/huh/rack.ts create mode 100644 src/components/huh/tracks.tsx diff --git a/bun.lock b/bun.lock index 8c457f4..d7f0ba2 100644 --- a/bun.lock +++ b/bun.lock @@ -21,6 +21,7 @@ "@astrojs/ts-content-mapper": "^0.2.0", "@biomejs/biome": "^2.6.7", "@microsoft/api-extractor": "7.60.1", + "@moq/hang": "workspace:*", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", "@tailwindcss/vite": "^4.3.5", diff --git a/package.json b/package.json index aa481ae..203d2d0 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "@astrojs/solid-js": "7.1.5", "@astrojs/ts-content-mapper": "^0.2.0", "@biomejs/biome": "^2.6.7", + "@moq/hang": "workspace:*", "@microsoft/api-extractor": "7.60.1", "@tailwindcss/forms": "^0.5.11", "@tailwindcss/typography": "^0.5.20", diff --git a/quest/m2/huh/routing-and-timestamps.md b/quest/m2/huh/routing-and-timestamps.md index 8053717..f5dc2f8 100644 --- a/quest/m2/huh/routing-and-timestamps.md +++ b/quest/m2/huh/routing-and-timestamps.md @@ -82,7 +82,3 @@ Recommendations: and multi-subscriber `max_age` expiration math with `bun test`. - Check `src/lib/landing.test.ts` (and update if it asserts the exact homepage hero buttons or nav links) and verify on desktop and mobile in `just dev`. - -## Required - -- [Add /huh Sections 4–5](/quest/m2/huh/tracks-and-discovery.md) - adds Sections 4–5 to the `/huh` page (`src/unreleased/huh.astro`) diff --git a/quest/m2/huh/tracks-and-discovery.md b/quest/m2/huh/tracks-and-discovery.md deleted file mode 100644 index f7ddf4a..0000000 --- a/quest/m2/huh/tracks-and-discovery.md +++ /dev/null @@ -1,50 +0,0 @@ -# [M] Add /huh Sections 4–5 (on-demand tracks and broadcast discovery gossip) - -## Goal - -The `/huh` page (`src/unreleased/huh.astro`, served only in dev and staging, not -other builds) includes interactive SolidJS visuals for Sections 4 and 5: - -4. **Tracks: Media & Arbitrary Data on Demand** (`Standard + hang`) — an - interactive broadcast track rack (`video/1080p`, `video/480p`, second camera - track, `audio`, `captions`, and arbitrary app data such as `controls.json`) - beside a live `catalog.json` view and uplink bandwidth meter. Unsubscribed - tracks visibly sleep (`0 kbps`, encoder idle); toggling subscriptions or - presets wakes only the pulled tracks, and an E2EE toggle—explicitly labeled - as the separate `moq-e2ee` project draft rather than part of `hang` or IETF - `moq-transport`—shows relays forwarding opaque ciphertext without parsing - payloads. -5. **Broadcasts & Live Discovery** (`Standard + extensions`) — an interactive - namespace prefix-gossip playground where publishers announce paths (e.g. - `room/alice`, `room/bob`, `room/carol`, `boat/cam-1`) through a relay mesh - to subscribers watching prefixes (`room/*`, `boat/*`). Toggling publishers - online/offline animates `ANNOUNCE` / withdrawal gossip and updates matching - live rosters immediately with zero polling, room server, or SDP, while - highlighting that sessions are bidirectional. - -Both sections respect `MotionToggle` and `prefers-reduced-motion`, work cleanly -on desktop and mobile in `just dev`, and pass `just check` and `just test`. - -## Plan - -Decided 2026-11-24 in [the epic](/quest/m2/huh/README.md): - -- Media + arbitrary data combined: ✅ explain media renditions, captions, - pull-on-demand sleeping encoders, E2EE, and arbitrary app data tracks in - Section 4 (rejected: separate "Your App" section; separate "Media" layer). -- Discovery: ✅ include a dedicated section explaining broadcasts/namespaces - and live `ANNOUNCE` gossip so visitors see how publishers and subscribers - find each other without a room server or SDP. - -Recommendations: - -- Reuse the section shell (`src/components/huh/section.astro`), standards - badge (`badge.astro`), and diagram helpers (`clock.ts` for the motion-aware - animation loop and pre-seeding, `ui.tsx` for the figure card, buttons, - sliders, and palette) that Sections 1–3 established, with pure simulation - math beside each diagram and unit-tested like `hol.ts` / `priority.ts` / - `groups.ts`. -- Keep the Standards badge accurate against `moq/doc/concept/standard.md` - (pull-on-demand tracks and namespace announcements are IETF `moq-transport`; - the `hang` catalog and prefix-route gossip / `solicit` / `active-count` - extensions are project drafts). diff --git a/src/components/huh/discovery.tsx b/src/components/huh/discovery.tsx new file mode 100644 index 0000000..205bfe8 --- /dev/null +++ b/src/components/huh/discovery.tsx @@ -0,0 +1,250 @@ +// Section 5: publishers announce paths to their relay, the relay mesh gossips them, and every session watching a +// matching prefix updates its roster the moment the message lands. +import { createMemo, createSignal, For, Index, onCleanup, onMount, Show } from "solid-js"; +import { advance, animate } from "./clock"; +import { type Client, Mesh, type Node, SETTLE, watchers } from "./gossip"; +import { Button, COLOR, Figure, MONO, Swatch } from "./ui"; + +const RELAYS = [ + { name: "sfo", x: 230, y: 125, above: false }, + { name: "fra", x: 370, y: 58, above: true }, + { name: "sin", x: 370, y: 192, above: false }, +]; +const CLIENTS: (Client & { x: number; y: number })[] = [ + { name: "alice", relay: 0, publishes: "room/alice", watches: "room/", x: 70, y: 80 }, + { name: "harbor", relay: 0, watches: "boat/", x: 70, y: 170 }, + { name: "bob", relay: 1, publishes: "room/bob", watches: "room/", x: 530, y: 30 }, + { name: "cam-1", relay: 1, publishes: "boat/cam-1", x: 530, y: 100 }, + { name: "carol", relay: 2, publishes: "room/carol", watches: "room/", x: 530, y: 192 }, +]; +const ONLINE = ["alice", "bob", "cam-1"]; // carol starts offline, so there's someone to bring online + +const W = 600; +const H = 236; +const RELAY_R = 24; +const BOX = { w: 76, h: 26 }; +const FRESH = 1.2; // seconds a new roster entry stays highlighted + +const pos = (n: Node) => ("relay" in n ? RELAYS[n.relay] : CLIENTS[n.client]); +const pattern = (prefix: string) => `${prefix}*`; + +export default function DiscoveryDiagram() { + const mesh = new Mesh(RELAYS.length, CLIENTS); + const [frame, redraw] = createSignal(undefined, { equals: false }); + const [news, setNews] = createSignal(""); + const tick = (dt: number) => { + mesh.step(dt); + redraw(); + }; + CLIENTS.forEach((c, i) => { + if (ONLINE.includes(c.name)) mesh.set(i, true); + }); + advance(SETTLE + FRESH, tick); + + let root!: SVGSVGElement; + let clock: ReturnType | undefined; + onMount(() => { + clock = animate(root, tick); + onCleanup(() => clock?.stop()); + }); + + const toggle = (i: number) => { + const c = CLIENTS[i]; + const path = c.publishes as string; + const online = !mesh.online[i]; + mesh.set(i, online); + const who = watchers(CLIENTS, path, i).map((w) => CLIENTS[w].name); + const heard = who.length ? `${who.join(" and ")} hear it as it crosses the mesh` : "nobody watches that prefix"; + setNews(`${c.name} ${online ? "announced" : "withdrew"} ${path}: ${heard}. Nothing polls.`); + // With motion paused, jump straight to the settled rosters. + if (clock?.live()) redraw(); + else advance(SETTLE + FRESH, tick); + }; + + const view = createMemo(() => { + frame(); + return { + t: mesh.t, + online: [...mesh.online], + known: mesh.known.map((k) => k.size), + rosters: mesh.roster.map((r) => [...r].sort(([a], [b]) => a.localeCompare(b))), + messages: mesh.inflight.map((m) => { + const a = pos(m.from); + const b = pos(m.to); + const k = Math.max(0, Math.min(1, (mesh.t - m.sent) / (m.arrives - m.sent))); + return { x: a.x + (b.x - a.x) * k, y: a.y + (b.y - a.y) * k, kind: m.kind, path: m.path }; + }), + }; + }); + + const label = + "Five sessions connect to three meshed relays. Alice, Bob, and Carol each publish a path under room and watch the room prefix; a boat camera publishes under boat, and a harbor screen watches the boat prefix. Bringing a publisher online or offline sends an announcement or withdrawal through the relays to every matching watcher, whose roster updates without polling."; + + return ( +
+ announce + withdraw + Click a publisher to take it online or offline. +

+ {news()} +

+ + } + > + + +
    + + {(c, i) => { + const on = () => view().online[i()]; + return ( +
  • + + {c.name} + via {RELAYS[c.relay].name} + + + {(path) => ( + + publishes + + + )} + + + {(prefix) => ( + + watches + + {pattern(prefix())} + + {c.publishes} (you) + + + nobody yet + + } + > + {(entry) => ( + + {entry()[0]} + + )} + + + + )} + +
  • + ); + }} +
    +
+
+ ); +} diff --git a/src/components/huh/gossip.test.ts b/src/components/huh/gossip.test.ts new file mode 100644 index 0000000..e55e58e --- /dev/null +++ b/src/components/huh/gossip.test.ts @@ -0,0 +1,99 @@ +import { describe, expect, test } from "bun:test"; +import { type Client, LOCAL, Mesh, SETTLE, watchers } from "./gossip"; + +const CLIENTS: Client[] = [ + { name: "alice", relay: 0, publishes: "room/alice", watches: "room/" }, + { name: "harbor", relay: 0, watches: "boat/" }, + { name: "bob", relay: 1, publishes: "room/bob", watches: "room/" }, + { name: "cam", relay: 1, publishes: "boat/cam-1" }, + { name: "carol", relay: 2, publishes: "room/carol", watches: "room/" }, +]; +const [ALICE, HARBOR, BOB, CAM, CAROL] = [0, 1, 2, 3, 4]; + +const run = (mesh: Mesh, seconds: number, dt = 1 / 60) => { + for (let t = 0; t < seconds; t += dt) mesh.step(dt); +}; +const seen = (mesh: Mesh, client: number) => [...mesh.roster[client].keys()].sort(); + +describe("Mesh", () => { + test("an announcement reaches every matching watcher and no one else", () => { + const mesh = new Mesh(3, CLIENTS); + mesh.set(BOB, true); + run(mesh, SETTLE + 0.1); + expect(seen(mesh, ALICE)).toEqual(["room/bob"]); + expect(seen(mesh, CAROL)).toEqual(["room/bob"]); + expect(seen(mesh, BOB)).toEqual([]); // its own broadcast never echoes back + expect(seen(mesh, HARBOR)).toEqual([]); + expect(mesh.inflight).toEqual([]); + }); + + test("a watcher on the publisher's relay hears it without crossing the mesh", () => { + const mesh = new Mesh(3, CLIENTS); + mesh.set(ALICE, true); + run(mesh, 2 * LOCAL + 0.05); + expect(mesh.roster[HARBOR].size).toBe(0); + mesh.set(CAM, true); + run(mesh, SETTLE + 0.1); + expect(seen(mesh, HARBOR)).toEqual(["boat/cam-1"]); + expect(mesh.roster[HARBOR].get("boat/cam-1")).toBeCloseTo(2 * LOCAL + 0.05 + SETTLE, 1); + }); + + test("a withdrawal clears every roster", () => { + const mesh = new Mesh(3, CLIENTS); + mesh.set(CAROL, true); + run(mesh, SETTLE + 0.1); + mesh.set(CAROL, false); + run(mesh, SETTLE + 0.1); + for (let i = 0; i < CLIENTS.length; i++) expect(mesh.roster[i].size).toBe(0); + for (const known of mesh.known) expect(known.size).toBe(0); + }); + + test("a coarse step delivers the same as a fine one", () => { + const fine = new Mesh(3, CLIENTS); + const coarse = new Mesh(3, CLIENTS); + for (const m of [fine, coarse]) { + m.set(ALICE, true); + m.set(CAM, true); + } + run(fine, SETTLE); + coarse.step(SETTLE); + expect(coarse.roster).toEqual(fine.roster); + }); + + test("rosters match who is online after any toggling", () => { + // A seeded generator, so a failure reproduces. + let seed = 7; + const random = () => { + seed = (Math.imul(seed, 1103515245) + 12345) >>> 0; + return seed / 2 ** 32; + }; + const publishers = CLIENTS.flatMap((c, i) => (c.publishes ? [i] : [])); + for (let round = 0; round < 50; round++) { + const mesh = new Mesh(3, CLIENTS); + for (let n = 0; n < 20; n++) { + const p = publishers[Math.floor(random() * publishers.length)]; + mesh.set(p, !mesh.online[p]); + run(mesh, random() * SETTLE, 1 / 30); + } + run(mesh, SETTLE + 0.1); + + CLIENTS.forEach((_, i) => { + const expected = publishers + .filter((p) => mesh.online[p] && watchers(CLIENTS, CLIENTS[p].publishes ?? "", p).includes(i)) + .map((p) => CLIENTS[p].publishes) + .sort(); + expect(seen(mesh, i)).toEqual(expected as string[]); + }); + const live = publishers.filter((p) => mesh.online[p]).map((p) => CLIENTS[p].publishes); + for (const known of mesh.known) expect([...known].sort()).toEqual(live.sort() as string[]); + } + }); +}); + +describe("watchers", () => { + test("matches by prefix and skips the publisher", () => { + expect(watchers(CLIENTS, "room/alice", ALICE)).toEqual([BOB, CAROL]); + expect(watchers(CLIENTS, "boat/cam-1", CAM)).toEqual([HARBOR]); + expect(watchers(CLIENTS, "zoo/lion")).toEqual([]); + }); +}); diff --git a/src/components/huh/gossip.ts b/src/components/huh/gossip.ts new file mode 100644 index 0000000..a045458 --- /dev/null +++ b/src/components/huh/gossip.ts @@ -0,0 +1,110 @@ +// Section 5's discovery mesh: clients announce broadcast paths to their relay, the relays gossip them to each other, +// and each relay tells the clients watching a matching prefix. Nothing polls: a roster changes when a message lands. +// +// The relays form a full mesh, so a relay forwards only what its own clients announce to the other relays, and what +// it hears from a relay only to its own clients. That keeps every path loop-free without route bookkeeping. + +export interface Client { + name: string; + relay: number; + publishes?: string; // the broadcast path it announces while online + watches?: string; // the prefix it asked to hear announcements under, such as "room/" +} + +export type Node = { relay: number } | { client: number }; + +export interface Message { + kind: "announce" | "end"; + path: string; + from: Node; + to: Node; + sent: number; + arrives: number; +} + +// Seconds per hop, slowed down so each one can be followed. +export const LOCAL = 0.35; // client to relay +export const MESH = 0.7; // relay to relay + +export class Mesh { + t = 0; + inflight: Message[] = []; + readonly online: boolean[]; + // What each relay currently knows is announced. + readonly known: Set[]; + // What each watcher has heard, and when it first did. + readonly roster: Map[]; + + constructor( + readonly relays: number, + readonly clients: readonly Client[], + ) { + this.online = clients.map(() => false); + this.known = Array.from({ length: relays }, () => new Set()); + this.roster = clients.map(() => new Map()); + } + + // Brings a publisher online or offline; its relay hears about it one hop later. + set(client: number, online: boolean) { + const path = this.clients[client].publishes; + if (path === undefined) throw new Error(`${this.clients[client].name} publishes nothing`); + if (this.online[client] === online) return; + this.online[client] = online; + this.send(online ? "announce" : "end", path, { client }, { relay: this.clients[client].relay }, this.t); + } + + step(dt: number) { + this.t += dt; + for (;;) { + // Every hop of one kind takes as long, so delivering in arrival order keeps each link first in, first out. + let next = -1; + for (let i = 0; i < this.inflight.length; i++) { + if (this.inflight[i].arrives > this.t) continue; + if (next < 0 || this.inflight[i].arrives < this.inflight[next].arrives) next = i; + } + if (next < 0) return; + const [m] = this.inflight.splice(next, 1); + this.deliver(m); + } + } + + private deliver(m: Message) { + if ("client" in m.to) { + const roster = this.roster[m.to.client]; + if (m.kind === "announce") roster.set(m.path, m.arrives); + else roster.delete(m.path); + return; + } + + const relay = m.to.relay; + const known = this.known[relay]; + if (m.kind === "announce") known.add(m.path); + else known.delete(m.path); + + // Split horizon: only what a relay's own client said goes back out over the mesh. + if ("client" in m.from) { + for (let r = 0; r < this.relays; r++) { + if (r !== relay) this.send(m.kind, m.path, { relay }, { relay: r }, m.arrives); + } + } + this.clients.forEach((c, i) => { + if (c.relay !== relay || c.watches === undefined || !m.path.startsWith(c.watches)) return; + if ("client" in m.from && m.from.client === i) return; // it knows its own broadcast + this.send(m.kind, m.path, { relay }, { client: i }, m.arrives); + }); + } + + // Forwards from the moment a message landed rather than from the end of the step, so a coarse step changes nothing. + private send(kind: Message["kind"], path: string, from: Node, to: Node, sent: number) { + const hop = "relay" in from && "relay" in to ? MESH : LOCAL; + this.inflight.push({ kind, path, from, to, sent, arrives: sent + hop }); + } +} + +// The longest a change takes to reach every watcher: up to the relay, across the mesh, down to the client. +export const SETTLE = 2 * LOCAL + MESH; + +// Who should hear `path` once the mesh settles: every other client watching a prefix of it. +export function watchers(clients: readonly Client[], path: string, except?: number): number[] { + return clients.flatMap((c, i) => (i !== except && c.watches !== undefined && path.startsWith(c.watches) ? [i] : [])); +} diff --git a/src/components/huh/rack.test.ts b/src/components/huh/rack.test.ts new file mode 100644 index 0000000..f4d7553 --- /dev/null +++ b/src/components/huh/rack.test.ts @@ -0,0 +1,47 @@ +import { describe, expect, test } from "bun:test"; +import { RootSchema } from "@moq/hang/catalog"; +import { catalog, opaque, PRESETS, PUSH_ALL, REAR, TRACKS, uplink } from "./rack"; + +describe("catalog", () => { + const lines = catalog(); + const json = JSON.parse(lines.map((l) => l.text).join("\n")); + + test("is a catalog the real hang reader accepts", () => { + const parsed = RootSchema.parse(json); + expect(Object.keys(parsed.video?.renditions ?? {})).toEqual(["video/1080p", "video/480p"]); + expect(parsed.contributions?.rear.broadcast as string).toBe(REAR); + }); + + test("lists every track on exactly one line, tagged with it", () => { + for (const t of TRACKS) { + const tagged = lines.filter((l) => l.track === t.name); + expect(tagged).toHaveLength(1); + expect(tagged[0].text).toContain(JSON.stringify(t.name)); + } + expect(lines.filter((l) => l.track).length).toBe(TRACKS.length); + }); +}); + +describe("uplink", () => { + test("costs nothing when nobody pulls", () => { + expect(uplink(new Set())).toBe(0); + }); + + test("counts only the pulled tracks", () => { + expect(uplink(new Set(["audio", "video/480p"]))).toBe(128 + 900); + expect(uplink(new Set(TRACKS.map((t) => t.name)))).toBe(PUSH_ALL); + }); + + test("every preset names real tracks", () => { + const names = new Set(TRACKS.map((t) => t.name)); + for (const p of PRESETS) for (const name of p.pulls) expect(names.has(name)).toBe(true); + }); +}); + +describe("opaque", () => { + test("is stable and hides the name", () => { + expect(opaque("audio")).toBe(opaque("audio")); + expect(opaque("audio")).not.toBe(opaque("video/480p")); + expect(opaque("audio")).not.toContain("audio"); + }); +}); diff --git a/src/components/huh/rack.ts b/src/components/huh/rack.ts new file mode 100644 index 0000000..cbcc0cb --- /dev/null +++ b/src/components/huh/rack.ts @@ -0,0 +1,91 @@ +// Section 4's broadcast: the tracks one publisher offers, the hang catalog that lists them, and what a viewer's pulls +// cost the publisher's uplink. Nothing is sent, or encoded, for a track nobody pulls. + +export type Kind = "video" | "audio" | "text" | "data" | "camera"; + +export interface Track { + name: string; // the track name a viewer subscribes to + kind: Kind; + kbps: number; // while someone pulls it + detail: string; +} + +// The broadcast the catalog is served from, and the second camera's sibling broadcast that it lists. +export const BROADCAST = "studio/front.hang"; +export const REAR = "rear.hang"; // relative: resolves to studio/rear.hang + +export const TRACKS: readonly Track[] = [ + { name: "video/1080p", kind: "video", kbps: 4500, detail: "H.264 1920×1080" }, + { name: "video/480p", kind: "video", kbps: 900, detail: "H.264 854×480" }, + { name: "rear", kind: "camera", kbps: 2500, detail: "second camera, its own broadcast" }, + { name: "audio", kind: "audio", kbps: 128, detail: "Opus stereo" }, + { name: "captions", kind: "text", kbps: 2, detail: "WebVTT, English" }, + { name: "controls.json", kind: "data", kbps: 8, detail: "your app's own JSON" }, +]; + +// What a few kinds of viewer pull. +export const PRESETS: readonly { name: string; pulls: readonly string[] }[] = [ + { name: "TV", pulls: ["video/1080p", "audio", "captions"] }, + { name: "Phone", pulls: ["video/480p", "audio"] }, + { name: "Both cameras", pulls: ["video/1080p", "rear", "audio"] }, + { name: "Audio only", pulls: ["audio"] }, + { name: "Bot", pulls: ["controls.json"] }, + { name: "Nobody", pulls: [] }, +]; + +// The publisher's uplink in kbps: only what is pulled. The catalog itself is a few hundred bytes, sent once. +export function uplink(pulled: ReadonlySet): number { + return TRACKS.reduce((n, t) => n + (pulled.has(t.name) ? t.kbps : 0), 0); +} + +// What pushing every track regardless of demand would cost. +export const PUSH_ALL = TRACKS.reduce((n, t) => n + t.kbps, 0); + +export interface Line { + text: string; + track?: string; // the track this line lists +} + +// The catalog.json a viewer reads, as hang (draft-lcurley-moq-hang) lays it out, one track per line so the view can +// light up what's pulled. +export function catalog(): Line[] { + const section = (key: string, inner: string | undefined, entries: [string, object][], last = false): Line[] => { + const indent = inner ? " " : " "; + const lines: Line[] = [{ text: ` ${JSON.stringify(key)}: {` }]; + if (inner) lines.push({ text: ` ${JSON.stringify(inner)}: {` }); + entries.forEach(([track, value], i) => { + const comma = i < entries.length - 1 ? "," : ""; + // One line per entry, spaced so it wraps on a narrow screen. + const json = JSON.stringify(value, null, 1).replace(/\n\s*/g, " "); + lines.push({ text: `${indent}${JSON.stringify(track)}: ${json}${comma}`, track }); + }); + if (inner) lines.push({ text: " }" }); + lines.push({ text: ` }${last ? "" : ","}` }); + return lines; + }; + const legacy = { kind: "legacy" }; + return [ + { text: "{" }, + ...section("video", "renditions", [ + ["video/1080p", { codec: "avc1.640028", bitrate: 4_500_000, container: legacy }], + ["video/480p", { codec: "avc1.64001e", bitrate: 900_000, container: legacy }], + ]), + ...section("audio", "renditions", [ + ["audio", { codec: "opus", sampleRate: 48000, numberOfChannels: 2, container: legacy }], + ]), + ...section("text", "renditions", [["captions", { format: "vtt", lang: "en", container: legacy }]]), + ...section("json", "tracks", [["controls.json", { mode: "snapshot" }]]), + ...section("contributions", undefined, [["rear", { broadcast: REAR }]], true), + { text: "}" }, + ]; +} + +// A stand-in for the opaque name moq-e2ee derives from a track name, so the relay can route it without learning it. +// Real names come from the credential and the publisher's epoch; this only needs to look the part and stay stable. +export function opaque(name: string): string { + // FNV-1a. + let h = 0x811c9dc5; + for (const c of name) h = Math.imul(h ^ c.charCodeAt(0), 0x01000193) >>> 0; + const hex = h.toString(16).padStart(8, "0"); + return `${hex.slice(0, 4)}…${hex.slice(4)}`; +} diff --git a/src/components/huh/section.astro b/src/components/huh/section.astro index c1bdc68..de50f94 100644 --- a/src/components/huh/section.astro +++ b/src/components/huh/section.astro @@ -1,15 +1,14 @@ --- import Badge, { type Props as BadgeProps } from "./badge.astro"; -// One /huh section: a numbered heading with its standards badge, the copy, then its interactive figure. +// One /huh section: a numbered heading with its standards badges, the copy, then its interactive figure. export interface Props { id: string; n: number; title: string; - badge: string; - kind: BadgeProps["kind"]; + badges: { text: string; kind: BadgeProps["kind"] }[]; } -const { id, n, title, badge, kind } = Astro.props; +const { id, n, title, badges } = Astro.props; ---
@@ -17,7 +16,7 @@ const { id, n, title, badge, kind } = Astro.props;

{String(n).padStart(2, "0")}

{title} - {badge} + {badges.map((b) => {b.text})}

diff --git a/src/components/huh/tracks.tsx b/src/components/huh/tracks.tsx new file mode 100644 index 0000000..ac61a07 --- /dev/null +++ b/src/components/huh/tracks.tsx @@ -0,0 +1,231 @@ +// Section 4: one broadcast's tracks, pulled one by one. An unpulled track's encoder sleeps, and with E2EE on the relay +// routes names and payloads it cannot read. +import { createSignal, For, onCleanup, onMount, Show } from "solid-js"; +import { animate } from "./clock"; +import { BROADCAST, catalog, type Kind, opaque, PRESETS, PUSH_ALL, REAR, TRACKS, uplink } from "./rack"; +import { Button, COLOR, Figure } from "./ui"; + +const KIND: Record = { + video: COLOR.green, + camera: COLOR.violet, + audio: COLOR.sky, + text: "#f472b6", + data: "#2dd4bf", +}; + +const SPEED = 40; // px per second the packets drift along a wire +const START = ["video/1080p", "audio", "captions"]; // the TV preset, so a few encoders sleep on first paint + +const rate = (kbps: number) => (kbps >= 1000 ? `${(kbps / 1000).toFixed(1)} Mbps` : `${kbps} kbps`); + +// The broadcast each track lives in, as the relay sees it. +const broadcast = (name: string) => (name === "rear" ? BROADCAST.replace(/[^/]+$/, REAR) : BROADCAST); + +export default function TracksDiagram() { + const [pulled, setPulled] = createSignal>(new Set(START)); + const [e2ee, setE2ee] = createSignal(false); + const [t, setT] = createSignal(0); + const [news, setNews] = createSignal(""); + const lines = catalog(); + + let root!: HTMLDivElement; + onMount(() => { + const clock = animate(root, (dt) => setT((t) => t + dt)); + onCleanup(() => clock.stop()); + }); + + const toggle = (name: string) => { + const next = new Set(pulled()); + const on = !next.has(name); + if (on) next.add(name); + else next.delete(name); + setPulled(next); + setNews( + on + ? `Subscribed to ${name}: its encoder wakes and the relay starts forwarding it.` + : `Unsubscribed from ${name}: nobody else wants it, so its encoder goes idle at 0 kbps.`, + ); + }; + const preset = (p: (typeof PRESETS)[number]) => { + setPulled(new Set(p.pulls)); + setNews( + p.pulls.length + ? `${p.name}: only ${p.pulls.join(", ")} ${p.pulls.length === 1 ? "is" : "are"} encoded and sent.` + : "Nobody is watching: every encoder sleeps and the uplink is idle.", + ); + }; + const same = (a: ReadonlySet, b: readonly string[]) => a.size === b.length && b.every((n) => a.has(n)); + + const seen = (name: string) => (e2ee() ? opaque(name) : name); + + const label = + "A publisher offers six tracks: two video renditions, a second camera, audio, captions, and an app data track, all listed in its catalog. Only the tracks a viewer subscribes to are encoded and sent; the rest sit idle at zero bandwidth. With end-to-end encryption on, the relay forwards track names and payloads it cannot read."; + + return ( +
+ viewer + + {(p) => ( + + )} + + + + + moq-e2ee project draft, not part of hang or{" "} + moq-transport + + +

+ {news()} +

+
+

+ catalog.json + + {e2ee() + ? ` · decrypted by the viewer; the relay carries ${opaque("catalog.json")}` + : " · always pulled first"} + +

+
+							
+								{(line) => (
+									
+										{line.text}
+									
+								)}
+							
+						
+
+ + } + > +
+
+ publisher · encoder + + relay sees + + {e2ee() ? opaque(BROADCAST) : BROADCAST} + + + +
+ +
    + + {(track) => { + const on = () => pulled().has(track.name); + const color = KIND[track.kind]; + const gap = Math.round(34 - 6 * Math.log10(track.kbps)); + const wire = () => ({ + "background-image": on() + ? `repeating-linear-gradient(90deg, ${color} 0 4px, transparent 4px ${4 + gap}px)` + : "none", + "background-position-x": `${t() * SPEED}px`, + "background-color": COLOR.track, + }); + return ( +
  • + + + + {on() ? rate(track.kbps) : "idle · 0 kbps"} + + + + + + ·}> + {seen(track.name)} + + + + + {track.detail} +
  • + ); + }} +
    +
+ +
+ +

+ + The relay routes by broadcast and track name and never parses a payload. The second camera is its own + broadcast, {broadcast("rear")}, listed under{" "} + contributions. + + } + > + With E2EE, paths, track names, and every group are ciphertext. The relay still routes each subscription by + its opaque name; only the viewer holds the key. + +

+
+
+
+ ); +} + +// The publisher's uplink against what pushing every track would cost. +function Meter(props: { kbps: number }) { + return ( +
+
+ uplink + 0 ? COLOR.green : COLOR.dim }}> + {rate(props.kbps)} + +
+ + ); +} diff --git a/src/unreleased/huh.astro b/src/unreleased/huh.astro index e0ccc1c..47b7071 100644 --- a/src/unreleased/huh.astro +++ b/src/unreleased/huh.astro @@ -1,20 +1,34 @@ --- // The /huh explainer: how MoQ works, one interactive section at a time, each flagged as IETF standard or not. // Unreleased (see UNRELEASED in astro.config.ts) and unlinked from the navigation until every section has landed. -import Badge, { type Props as BadgeProps } from "@/components/huh/badge.astro"; +import Badge from "@/components/huh/badge.astro"; import Congestion from "@/components/huh/congestion"; -import Section from "@/components/huh/section.astro"; +import Discovery from "@/components/huh/discovery"; +import Section, { type Props as SectionProps } from "@/components/huh/section.astro"; import Timeline from "@/components/huh/timeline"; +import Tracks from "@/components/huh/tracks"; import Transport from "@/components/huh/transport"; import MotionToggle from "@/components/motion-toggle.astro"; import Layout from "@/layouts/global.astro"; -const sections: { id: string; title: string; badge: string; kind: BadgeProps["kind"] }[] = [ - { id: "quic", title: "QUIC & Multiple Streams", badge: "Standard · RFC 9000", kind: "standard" }, - { id: "congestion", title: "Congestion & Prioritization", badge: "Standard · QUIC / IETF", kind: "standard" }, - { id: "groups", title: "Frames & Groups", badge: "Standard · IETF MoQ", kind: "standard" }, +const standard = (text: string) => ({ text, kind: "standard" as const }); +const extension = (text: string) => ({ text, kind: "extension" as const }); +const sections: Omit[] = [ + { id: "quic", title: "QUIC & Multiple Streams", badges: [standard("Standard · RFC 9000")] }, + { id: "congestion", title: "Congestion & Prioritization", badges: [standard("Standard · QUIC / IETF")] }, + { id: "groups", title: "Frames & Groups", badges: [standard("Standard · IETF MoQ")] }, + { + id: "tracks", + title: "Tracks: Media & Arbitrary Data on Demand", + badges: [standard("Standard · IETF MoQ"), extension("+ hang")], + }, + { + id: "discovery", + title: "Broadcasts & Live Discovery", + badges: [standard("Standard · IETF MoQ"), extension("+ cluster")], + }, ]; -const [quic, congestion, groups] = sections.map((s, i) => ({ ...s, n: i + 1 })); +const [quic, congestion, groups, tracks, discovery] = sections.map((s, i) => ({ ...s, n: i + 1 })); --- @@ -34,7 +48,7 @@ const [quic, congestion, groups] = sections.map((s, i) => ({ ...s, n: i + 1 })); {String(i + 1).padStart(2, "0")} {s.title} - {s.badge} + {s.badges.map((b) => {b.text})} )) @@ -99,4 +113,54 @@ const [quic, congestion, groups] = sections.map((s, i) => ({ ...s, n: i + 1 }));

+ +
+

+ A broadcast is a bundle of named tracks: each video rendition, the audio, captions, and anything else your app + needs, like a controls.json track. Every track is the same sequence of groups, so a relay carries data + exactly like media. +

+

+ Viewers pull. A relay forwards a track only to sessions subscribed to it, and merges duplicate subscriptions on + the way upstream, so a track nobody watches never leaves the publisher. A publisher that watches demand can go + further and leave that track's encoder idle: if nobody's on a big screen, nobody encodes 1080p. +

+

+ To know what to ask for, a viewer first subscribes to catalog.json, a track + from hang, this project's media format. It lists every + rendition with its decoder config and updates live as tracks come and go. A second camera is its own + broadcast, listed under contributions and opened only when someone picks it. +

+

Pick a viewer or toggle tracks, and watch the uplink.

+

+ End-to-end encryption is a separate project draft, moq-e2ee, not part of hang or + IETF moq-transport. It swaps broadcast paths and track names for opaque ones and encrypts every payload, + so a relay routes ciphertext it can't read. Relays never parse payloads anyway; with E2EE they can't. +

+ +
+ +
+

+ Broadcasts are named by paths, like room/alice or boat/cam-1. A publisher announces its + path to its relay, and any session can ask for every announcement under a prefix like room/: what's + live now, then each change as it happens. +

+

+ That's the whole discovery story. A room's roster is a prefix subscription: no room server, no polling, and no SDP + offer and answer. When Carol comes online, everyone watching room/ hears about it as her announcement + crosses the relays, and when she leaves, the withdrawal follows the same way. +

+

+ Sessions are bidirectional. Alice publishes room/alice and watches room/ over the same + connection, so joining a call is one announcement plus one prefix subscription. Take people online and offline. +

+

+ IETF moq-transport calls these PUBLISH_NAMESPACE and SUBSCRIBE_NAMESPACE. + It doesn't say how to build a mesh of relays; the cluster project draft adds the hop lists that keep + announcements from looping. This diagram simplifies: each relay forwards only its own clients' announcements to + the others. +

+ +
From d9fbf3c41cfd710b957c9cc59a04493d57e4c8d4 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 25 Nov 2026 20:59:47 -0800 Subject: [PATCH 3/3] fix(huh): route the rear camera to its own broadcast, keep rosters live The relay column now names the rear camera's own broadcast and rendition, and E2EE hides both in the label and tooltip. Discovery's clock watches the rosters too, so they keep updating on a phone after the diagram scrolls away. The E2EE note says who holds the credential and what the relay still sees, the uplink meter skips its transition with motion off, and the /huh smoke test covers Sections 4 and 5. Co-Authored-By: Claude Opus 5.5 --- src/components/huh/discovery.tsx | 299 ++++++++++++++++--------------- src/components/huh/rack.ts | 24 ++- src/components/huh/tracks.tsx | 24 +-- src/lib/landing.test.ts | 6 +- 4 files changed, 194 insertions(+), 159 deletions(-) diff --git a/src/components/huh/discovery.tsx b/src/components/huh/discovery.tsx index 205bfe8..e8ba5db 100644 --- a/src/components/huh/discovery.tsx +++ b/src/components/huh/discovery.tsx @@ -41,7 +41,8 @@ export default function DiscoveryDiagram() { }); advance(SETTLE + FRESH, tick); - let root!: SVGSVGElement; + // Covers the rosters too, so they keep updating while only they are on screen. + let root!: HTMLDivElement; let clock: ReturnType | undefined; onMount(() => { clock = animate(root, tick); @@ -94,157 +95,167 @@ export default function DiscoveryDiagram() { } > -
+ + )} + + + + {(c, i) => { + const on = () => c.publishes !== undefined && view().online[i()]; + return ( + + + + + {c.name} + + + ); + }} + -
    - - {(c, i) => { - const on = () => view().online[i()]; - return ( -
  • - - {c.name} - via {RELAYS[c.relay].name} - - - {(path) => ( - - publishes - - - )} - - - {(prefix) => ( - - watches - - {pattern(prefix())} - - {c.publishes} (you) - - - nobody yet - - } + {/* Fresh objects every frame, so reuse the elements by position rather than rebuilding them. */} + + {(m) => { + const color = () => (m().kind === "announce" ? COLOR.green : COLOR.red); + return ( + + + + {m().kind === "announce" ? "+" : "−"} + {m().path} + + + ); + }} + + + +
      + + {(c, i) => { + const on = () => view().online[i()]; + return ( +
    • + + {c.name} + via {RELAYS[c.relay].name} + + + {(path) => ( + + publishes + + + )} + + + {(prefix) => ( + + watches + + {pattern(prefix())} + + {c.publishes} (you) + + + nobody yet + + } + > + {(entry) => ( + + {entry()[0]} + + )} + + - - )} - -
    • - ); - }} -
      -
    + )} + +
  • + ); + }} +
    +
+
); } diff --git a/src/components/huh/rack.ts b/src/components/huh/rack.ts index cbcc0cb..208cd83 100644 --- a/src/components/huh/rack.ts +++ b/src/components/huh/rack.ts @@ -8,21 +8,41 @@ export interface Track { kind: Kind; kbps: number; // while someone pulls it detail: string; + // Where the subscription actually goes, when not to a track of that name in BROADCAST. + route?: Route; +} + +export interface Route { + broadcast: string; + track: string; } // The broadcast the catalog is served from, and the second camera's sibling broadcast that it lists. export const BROADCAST = "studio/front.hang"; -export const REAR = "rear.hang"; // relative: resolves to studio/rear.hang +export const REAR = "rear.hang"; // as the catalog lists it, relative to BROADCAST +export const REAR_PATH = "studio/rear.hang"; export const TRACKS: readonly Track[] = [ { name: "video/1080p", kind: "video", kbps: 4500, detail: "H.264 1920×1080" }, { name: "video/480p", kind: "video", kbps: 900, detail: "H.264 854×480" }, - { name: "rear", kind: "camera", kbps: 2500, detail: "second camera, its own broadcast" }, + { + name: "rear", + kind: "camera", + kbps: 2500, + detail: "second camera, its own broadcast", + // A rendition from the rear camera's own catalog. + route: { broadcast: REAR_PATH, track: "video/720p" }, + }, { name: "audio", kind: "audio", kbps: 128, detail: "Opus stereo" }, { name: "captions", kind: "text", kbps: 2, detail: "WebVTT, English" }, { name: "controls.json", kind: "data", kbps: 8, detail: "your app's own JSON" }, ]; +// The broadcast and track a subscription to `t` names. +export function route(t: Track): Route { + return t.route ?? { broadcast: BROADCAST, track: t.name }; +} + // What a few kinds of viewer pull. export const PRESETS: readonly { name: string; pulls: readonly string[] }[] = [ { name: "TV", pulls: ["video/1080p", "audio", "captions"] }, diff --git a/src/components/huh/tracks.tsx b/src/components/huh/tracks.tsx index ac61a07..b04bb07 100644 --- a/src/components/huh/tracks.tsx +++ b/src/components/huh/tracks.tsx @@ -2,7 +2,7 @@ // routes names and payloads it cannot read. import { createSignal, For, onCleanup, onMount, Show } from "solid-js"; import { animate } from "./clock"; -import { BROADCAST, catalog, type Kind, opaque, PRESETS, PUSH_ALL, REAR, TRACKS, uplink } from "./rack"; +import { BROADCAST, catalog, type Kind, opaque, PRESETS, PUSH_ALL, REAR_PATH, route, TRACKS, uplink } from "./rack"; import { Button, COLOR, Figure } from "./ui"; const KIND: Record = { @@ -18,9 +18,6 @@ const START = ["video/1080p", "audio", "captions"]; // the TV preset, so a few e const rate = (kbps: number) => (kbps >= 1000 ? `${(kbps / 1000).toFixed(1)} Mbps` : `${kbps} kbps`); -// The broadcast each track lives in, as the relay sees it. -const broadcast = (name: string) => (name === "rear" ? BROADCAST.replace(/[^/]+$/, REAR) : BROADCAST); - export default function TracksDiagram() { const [pulled, setPulled] = createSignal>(new Set(START)); const [e2ee, setE2ee] = createSignal(false); @@ -56,6 +53,7 @@ export default function TracksDiagram() { }; const same = (a: ReadonlySet, b: readonly string[]) => a.size === b.length && b.every((n) => a.has(n)); + // A name as the relay sees it. const seen = (name: string) => (e2ee() ? opaque(name) : name); const label = @@ -164,12 +162,16 @@ export default function TracksDiagram() { ·}> - {seen(track.name)} + {/* Only the second camera lives outside the broadcast named above the rack. */} + + {seen(route(track).broadcast)} + + {seen(route(track).track)} @@ -189,13 +191,13 @@ export default function TracksDiagram() { fallback={ <> The relay routes by broadcast and track name and never parses a payload. The second camera is its own - broadcast, {broadcast("rear")}, listed under{" "} + broadcast, {REAR_PATH}, listed under{" "} contributions. } > - With E2EE, paths, track names, and every group are ciphertext. The relay still routes each subscription by - its opaque name; only the viewer holds the key. + With E2EE, the relay sees opaque paths and track names and encrypted payloads, though still the group and + frame boundaries it forwards by. Only the publisher and viewers holding the credential can read them.

@@ -221,7 +223,7 @@ function Meter(props: { kbps: number }) { aria-hidden="true" >
diff --git a/src/lib/landing.test.ts b/src/lib/landing.test.ts index b1d2f7e..07d208c 100644 --- a/src/lib/landing.test.ts +++ b/src/lib/landing.test.ts @@ -42,6 +42,8 @@ test("/huh renders every section with its diagram", async () => { const response = await fetch(url("/huh")); expect(response.status).toBe(200); const html = await response.text(); - for (const id of ["quic", "congestion", "groups"]) expect(html).toContain(`id="${id}"`); - for (const drawn of ["over TCP", "SENT", "behind live"]) expect(html).toContain(drawn); + for (const id of ["quic", "congestion", "groups", "tracks", "discovery"]) expect(html).toContain(`id="${id}"`); + for (const drawn of ["over TCP", "SENT", "behind live", "pushing every track", "take it online or offline"]) { + expect(html).toContain(drawn); + } }, 30_000);