tvpipe 0.3.0

Stream a program's frames and sound, files, web pages or the screen to Apple TVs, Chromecasts and browser tabs with low latency, in process
Documentation
// The TV page: tvpipe renders it in a headless browser and casts it. It
// connects as the screen (its link has #r=…&k=…&role=screen) and draws
// view.screen (what the host page sets) and view.join (the QR code and the
// short link to type, tvpipe.party/CODE, when there is one).
import { PartyClient, joinText, qrSvg } from "/_tvpipe/lib/client.js";

const $ = (id) => document.getElementById(id);
const client = PartyClient.fromLocation();

client.on("view", (view) => {
  const s = view.screen ?? {};
  $("qr").innerHTML = qrSvg(view.join?.qr);
  $("code").textContent = joinText(view.join) ?? "";
  $("status").textContent = !s.round ? "Scan to join, then the host starts a round" : `Round ${s.round}: buzz!`;
  $("buzzed").replaceChildren(...(s.buzzed ?? []).map((name) => item(name)));
  $("scores").replaceChildren(...(s.scores ?? []).map((p) => item(`${p.name}: ${p.points}`)));
});
client.on("status", (st) => {
  if (st !== "open") $("status").textContent = st;
});

function item(text) {
  const li = document.createElement("li");
  li.textContent = text; // text from players is always text, never HTML
  return li;
}

await client.connect();