diff --git a/.env.development b/.env.development index da96fb5..9c5f3a0 100644 --- a/.env.development +++ b/.env.development @@ -1 +1,3 @@ +PUBLIC_RELAY_SCHEME="http" PUBLIC_RELAY_HOST="localhost:4443" +PUBLIC_RELAY_REGIONS="" diff --git a/.env.production b/.env.production index 7a9770e..95c5877 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,3 @@ +PUBLIC_RELAY_SCHEME="https" PUBLIC_RELAY_HOST="relay.quic.video" +PUBLIC_RELAY_REGIONS="us-central,europe-west,asia-southeast" diff --git a/astro.config.ts b/astro.config.ts index 1bf3e37..4d72f4c 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -49,5 +49,9 @@ export default defineConfig({ "@": "/src", }, }, + // Workaround for: https://github.com/vitejs/vite/issues/8427 + optimizeDeps: { + exclude: ["@kixelated/moq"], + }, }, }); diff --git a/bun.lockb b/bun.lockb index b3a8e21..7d2fc10 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/env.d.ts b/env.d.ts index 4df96c2..375d2c0 100644 --- a/env.d.ts +++ b/env.d.ts @@ -1,7 +1,9 @@ /// interface ImportMetaEnv { + readonly PUBLIC_RELAY_SCHEME: string; readonly PUBLIC_RELAY_HOST: string; + readonly PUBLIC_RELAY_REGIONS: string; } interface ImportMeta { diff --git a/package.json b/package.json index f52385e..2afe94e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "@astrojs/node": "8.3.4", "@astrojs/solid-js": "4.4.4", "@astrojs/tailwind": "5.1.2", - "@kixelated/moq": "^0.3.8", + "@kixelated/moq": "^0.3.12", "@tailwindcss/forms": "^0.5.9", "@tailwindcss/typography": "^0.5.15", "astro": "4.16.16", diff --git a/src/components/region.tsx b/src/components/region.tsx new file mode 100644 index 0000000..12f48c5 --- /dev/null +++ b/src/components/region.tsx @@ -0,0 +1,49 @@ +import "@kixelated/moq/video"; +import { For, type Setter, createEffect, createSignal } from "solid-js"; + +// Exposes a region selector to allow overriding the region used by the relay. +export default function Region(props: { path: string; setUrl: Setter }) { + // Use query params to allow overriding environment variables. + const urlSearchParams = new URLSearchParams(window.location.search); + const params = Object.fromEntries(urlSearchParams.entries()); + + const [region, setRegion] = createSignal(params.region ?? null); + const regions = import.meta.env.PUBLIC_RELAY_REGIONS ? import.meta.env.PUBLIC_RELAY_REGIONS.split(",") : []; + const host = params.server || import.meta.env.PUBLIC_RELAY_HOST; + + createEffect(() => { + const scheme = params.scheme || import.meta.env.PUBLIC_RELAY_SCHEME || "https"; + + const r = region(); + const server = r === null ? host : `${r}.${host}`; + + props.setUrl(`${scheme}://${server}/${props.path}`); + }); + + return ( +
+ + Relay: + + + + {(r) => ( + + )} + +
+ ); +} diff --git a/src/components/watch.tsx b/src/components/watch.tsx index 5968b6a..b287fe7 100644 --- a/src/components/watch.tsx +++ b/src/components/watch.tsx @@ -1,16 +1,16 @@ -import "@kixelated/moq/video"; +import "@kixelated/moq/watch"; -export default function Watch(props: { path: string }) { - // Use query params to allow overriding environment variables. - const urlSearchParams = new URLSearchParams(window.location.search); - const params = Object.fromEntries(urlSearchParams.entries()); - const server = params.server ?? import.meta.env.PUBLIC_RELAY_HOST; +import { createSignal } from "solid-js"; + +import Region from "@/components/region"; - const url = `https://${server}/${props.path}`; +export default function Watch(props: { path: string }) { + const [url, setUrl] = createSignal(""); return ( - - - +
+ + +
); } diff --git a/src/layouts/global.css b/src/layouts/global.css index 7df573f..ce05579 100644 --- a/src/layouts/global.css +++ b/src/layouts/global.css @@ -26,7 +26,7 @@ button, .form-button { @apply rounded-md border-0 bg-slate-700 font-bold shadow-sm hover:bg-slate-800 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2; - @apply px-12 py-4 text-2xl; + @apply px-8 py-3 text-lg; } input,