PWA (installable radio player)
The primary radio player is an installable Progressive Web App served
statically by the Go server (:8093) at api.mediahubnetwork.net
(source html/index.html on the production node). It plays the HLS stream with
OGG fallback, shows an artist backdrop, supports push notifications, works
offline, and adds live chat + listener presence on top.
What it is
A single-page player (client-side JS + hls.js) that:
- Loads the HLS stream with hls.js 1.5.15 (fallback: native HLS on iOS,
then the OGG master
files.mediahubnetwork.net/mainif HLS auth fails). - Counts listeners from HTTPS
https://api.mediahubnetwork.net/v3/paths/list(the Go server forwards/v3/*to the read-only MediaMTX listener proxy:19353), polled by a race-guardedpollListeners()every 5s with an IcecastSTATUS_URLfallback; metadata polled by a guardedpollMetadata(). - Renders now-playing from the engine proxy (
/api/next,/api/status,/api/station/state,/api/content/status, push registration via/api/push/register— all forwarded to the control planehttp://10.40.3.174:5000). - Paints a large artist-image backdrop (
fetchBackdrop(artist, title)) that dims over the page at ~20% opacity. - Uses an inline SVG favicon (no extra request).
- Registers a service worker for installability + offline shell, and
web-push for notifications (
VAPID_KEYfilled from server.js). - Live chat + presence: stacked avatars in the header LIVE badge (max 5 +
+N), a "Sara and 3 others" presence line, auto-rejoin via localStorage (loklok.chatName/loklok.chatToken), history poll 4s / presence 10s / heartbeat 30s, 120-msg DOM cap, and a#chatOffoffline fallback. The chat itself is served by the long-poll companionchat-server.js:8094(see Chat server).
PWA assets (served alongside the page)
| Asset | Purpose |
|---|---|
manifest.json | Install manifest: name "LOKLOK", icons, start URL / |
sw.js | Service worker — cache shell, offline handling, push listener |
icons/ | App icons (e.g. path848.png) |
offline.html | Offline fallback page |
Service worker behaviour
- Install: pre-caches the player shell (page, CSS, JS, icons).
- Fetch: serves cached assets first (offline-capable), falling back to the network and populating the cache.
- Push: listens for push events → shows a notification (web-push path from Notifications).
- Activate: cleans old cache versions when a new service worker activates.
Bumping the cache version
When the app shell changes, bump the service worker's cache name so clients download the new shell instead of serving stale files. The old caches are purged automatically on activation.
Install flow
- Visit
https://api.mediahubnetwork.net/on a supporting browser. - The page registers
sw.jsand the manifest is detected. - Users can Add to Home Screen / install for a native-like app.
Offline behaviour
The player shell is pre-cached, so the app opens offline; live audio obviously needs the network. Offline mode shows the cached shell until the socket and stream reconnect.
Related
- Streaming — the HLS + OGG endpoints it plays.
- Chat server — the long-poll chat companion.
- Next.js player — the alternative player app.
- Socket events — the metadata feed it renders.