From f77fab378bc7cbd1af501f577cf99060cea8cbee Mon Sep 17 00:00:00 2001 From: "every.channel" Date: Sun, 22 Feb 2026 02:14:01 -0800 Subject: [PATCH] web: add MoQ player CDN fallback and path query alias --- apps/web/app.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/apps/web/app.js b/apps/web/app.js index fe3b004..4c916e0 100644 --- a/apps/web/app.js +++ b/apps/web/app.js @@ -4,7 +4,11 @@ // It is intentionally dependency-light: no framework, no bundler. const DEFAULT_RELAY_URL = "https://cdn.moq.dev/anon"; -const MOQ_WATCH_MODULE_URL = "https://esm.sh/@moq/watch@0.1.1/element"; +const MOQ_WATCH_MODULE_URLS = [ + "https://esm.sh/@moq/watch@0.1.1/element", + "https://cdn.jsdelivr.net/npm/@moq/watch@0.1.1/element/+esm", + "https://unpkg.com/@moq/watch@0.1.1/element.js?module", +]; let moqWatchModulePromise = null; let disposePlayerSignals = null; @@ -140,7 +144,21 @@ function mountPlayer(relayUrl, name) { async function ensureMoqWatchElement() { if (window.customElements && window.customElements.get("moq-watch")) return; if (!moqWatchModulePromise) { - moqWatchModulePromise = import(MOQ_WATCH_MODULE_URL); + moqWatchModulePromise = (async () => { + let lastErr = null; + for (const moduleUrl of MOQ_WATCH_MODULE_URLS) { + try { + await import(moduleUrl); + } catch (err) { + lastErr = err; + continue; + } + if (window.customElements && window.customElements.get("moq-watch")) { + return; + } + } + throw lastErr || new Error("moq-watch custom element is unavailable"); + })(); } await moqWatchModulePromise; if (!(window.customElements && window.customElements.get("moq-watch"))) { @@ -172,7 +190,8 @@ function readParams() { u.searchParams.get("relayUrl"); const name = u.searchParams.get("name") || - u.searchParams.get("broadcast"); + u.searchParams.get("broadcast") || + u.searchParams.get("path"); return { relayUrl: normalizeRelayUrl(relay || DEFAULT_RELAY_URL), name: normalizeName(name || ""),