web: add MoQ player CDN fallback and path query alias
This commit is contained in:
parent
fe97623ba8
commit
f77fab378b
1 changed files with 22 additions and 3 deletions
|
|
@ -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 || ""),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue