From 7fdb60f5e7886cb98b5afd516ae19038732e2d23 Mon Sep 17 00:00:00 2001 From: Androtim <143963999+Androtim@users.noreply.github.com> Date: Sat, 4 Jul 2026 00:39:47 +0200 Subject: [PATCH 1/3] feat(pwa): installable app with an offline shell Adds a web manifest (standalone display, theme color, app icon) and registers the service worker on load so Beacon is installable and opens offline. The existing streaming worker gains app-shell caching rather than adding a second worker that would fight it for the root scope: navigations are network-first with a cached-shell fallback, content-hashed assets are cache-first, and /p2p/, /api/, /socket.io/, media, and range requests are all left untouched so streaming and live data keep working. Co-Authored-By: Claude Fable 5 --- client/index.html | 3 ++ client/public/app-icon.svg | 6 +++ client/public/manifest.webmanifest | 18 +++++++++ client/public/sw.js | 59 +++++++++++++++++++++++++++++- client/src/main.jsx | 11 +++++- 5 files changed, 94 insertions(+), 3 deletions(-) create mode 100644 client/public/app-icon.svg create mode 100644 client/public/manifest.webmanifest diff --git a/client/index.html b/client/index.html index 44ae045a..c0986a88 100644 --- a/client/index.html +++ b/client/index.html @@ -3,6 +3,9 @@ + + + Beacon diff --git a/client/public/app-icon.svg b/client/public/app-icon.svg new file mode 100644 index 00000000..4ade1051 --- /dev/null +++ b/client/public/app-icon.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/client/public/manifest.webmanifest b/client/public/manifest.webmanifest new file mode 100644 index 00000000..cbd90815 --- /dev/null +++ b/client/public/manifest.webmanifest @@ -0,0 +1,18 @@ +{ + "name": "Beacon", + "short_name": "Beacon", + "description": "Watch videos in sync and send files directly between browsers.", + "start_url": "/", + "scope": "/", + "display": "standalone", + "background_color": "#10131A", + "theme_color": "#10131A", + "icons": [ + { + "src": "/app-icon.svg", + "type": "image/svg+xml", + "sizes": "any", + "purpose": "any maskable" + } + ] +} diff --git a/client/public/sw.js b/client/public/sw.js index bff5b07e..bef55d3e 100644 --- a/client/public/sw.js +++ b/client/public/sw.js @@ -10,8 +10,25 @@ const streams = new Map() // key -> { size, mime, clientId } const MAX_WINDOW = 2 * 1024 * 1024 // cap each 206 response; browser follows up -self.addEventListener('install', () => self.skipWaiting()) -self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim())) +// App-shell cache, so an installed PWA opens offline. Bump the version to +// invalidate old entries on the next activate. Hashed build assets are +// immutable, so caching them is safe; the HTML shell is refreshed +// network-first below. +const SHELL_CACHE = 'beacon-shell-v1' +const SHELL_URLS = ['/', '/index.html', '/favicon.svg', '/manifest.webmanifest'] + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(SHELL_CACHE).then((c) => c.addAll(SHELL_URLS)).catch(() => {}).then(() => self.skipWaiting()), + ) +}) +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys() + .then((keys) => Promise.all(keys.filter((k) => k !== SHELL_CACHE).map((k) => caches.delete(k)))) + .then(() => self.clients.claim()), + ) +}) self.addEventListener('message', (event) => { const { t } = event.data ?? {} @@ -41,6 +58,44 @@ async function fetchRangeFromClient(entry, key, start, end) { self.addEventListener('fetch', (event) => { const url = new URL(event.request.url) + + // App-shell caching for same-origin GETs — but never the P2P stream, the + // API, or the socket transport, which must always hit the live server/peer. + if ( + event.request.method === 'GET' && + url.origin === self.location.origin && + !url.pathname.startsWith('/p2p/') && + !url.pathname.startsWith('/api/') && + !url.pathname.startsWith('/socket.io/') + ) { + if (event.request.mode === 'navigate') { + // Network-first for navigations so a fresh shell wins when online, with + // the cached shell as the offline fallback. + event.respondWith( + fetch(event.request).catch(() => caches.match('/index.html').then((r) => r ?? Response.error())), + ) + return + } + // Cache-first only for content-hashed build assets — never media, and + // never a Range request (partial responses would corrupt the cache and + // break video seeking). + const isAsset = /\.(js|mjs|css|woff2?|svg|png|ico|webmanifest)$/.test(url.pathname) + if (isAsset && !event.request.headers.has('range')) { + event.respondWith( + caches.match(event.request).then((hit) => + hit ?? fetch(event.request).then((res) => { + if (res.ok && res.type === 'basic') { + const copy = res.clone() + caches.open(SHELL_CACHE).then((c) => c.put(event.request, copy)).catch(() => {}) + } + return res + }), + ), + ) + } + return + } + if (!url.pathname.startsWith('/p2p/')) return const key = url.pathname.slice('/p2p/'.length) const entry = streams.get(key) diff --git a/client/src/main.jsx b/client/src/main.jsx index 0291fe5b..c7939e8f 100644 --- a/client/src/main.jsx +++ b/client/src/main.jsx @@ -7,4 +7,13 @@ ReactDOM.createRoot(document.getElementById('root')).render( , -) \ No newline at end of file +) + +// Register the service worker so the app is installable and opens offline. +// It's the same worker that powers stream-while-downloading; registering it on +// load (rather than lazily on first stream) is what makes the PWA installable. +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + navigator.serviceWorker.register('/sw.js').catch(() => {}) + }) +} \ No newline at end of file From f51de46b41b480a9ac41f61762f74eed20c34303 Mon Sep 17 00:00:00 2001 From: Androtim <143963999+Androtim@users.noreply.github.com> Date: Sat, 4 Jul 2026 00:40:03 +0200 Subject: [PATCH 2/3] docs: note PWA install, key backup, and multi-device in the readme Co-Authored-By: Claude Fable 5 --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c859b6e..c342e2ac 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,12 @@ Direct messages are end-to-end encrypted. or host immediately. Accounts add direct messages, a persistent identity, and stats. - End-to-end encrypted DMs (ECDH P-256 + AES-GCM); the server stores only - ciphertext it cannot read. + ciphertext it cannot read. Keys are per-device, with a passphrase-protected + backup to carry your history to another device. +- Use one account from several devices at once; messages reach all of them. + +**Installable** — Beacon is a PWA: install it from the browser's address bar +for an app window and an offline shell. --- From 7cbd38a46863b0c2c608c78bc1672d5823f64bbd Mon Sep 17 00:00:00 2001 From: Androtim <143963999+Androtim@users.noreply.github.com> Date: Sat, 4 Jul 2026 00:40:33 +0200 Subject: [PATCH 3/3] docs: bring the roadmap up to date with this session's work Co-Authored-By: Claude Fable 5 --- ROADMAP.md | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 3fe07e80..87783de0 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,6 +1,6 @@ # Beacon Roadmap -Where the project stands and everything left to do. Updated 2026-07-03. +Where the project stands and everything left to do. Updated 2026-07-04. ## Done @@ -27,28 +27,29 @@ Where the project stands and everything left to do. Updated 2026-07-03. - **Cinema mode** — pure-CSS lights-down while playing. - **Reliability** — P2P connections fail gracefully with a clear error + retry (no more infinite spinner); shared playback control (anyone can pause/seek). -- **Deployed** — live on an Oracle Cloud free VM behind Caddy (HTTPS), systemd, - SQLite on a persistent path. See `deploy/DEPLOY.md`. +- **Multi-device** — one account can be connected from several devices at once; + DMs, offers, invites, and presence track all of them. +- **DM key backup** — passphrase-encrypted export/restore of the message key, + so history can move to a new device. +- **Installable PWA** — web manifest, app icon, and an offline app shell. +- **Hardening** — audited and patched: no email leakage, proxy-aware rate + limits, hostile-peer defenses in the P2P receiver (with regression tests), + clean dependency audit enforced in CI. +- **UI** — pared back from the templated look to a restrained, neutral theme; + all panels on the design tokens; own favicon. +- **Ops** — nightly SQLite backup script; CI runs typecheck, build, and audit. +- **Deployed** — live on an Oracle Cloud free VM behind Caddy (HTTPS + security + headers), systemd, SQLite on a persistent path. See `deploy/DEPLOY.md`. ## Remaining -### UI polish -- [ ] The inner FileShare, VideoFileSharing, and Voice panels still carry - pre-design-system blue/green accents. -- [ ] Replace the default Vite favicon with a real one. - ### Connectivity - [ ] Firefox + TURN: the free Metered relay gives Firefox zero relay candidates (see QUESTIONS.md). Try another provider and verify on two - real devices on different networks. - -### PWA -- [ ] Installable app: manifest, icons, offline shell ("add to home screen"). -- [ ] (Optional, later) Tauri desktop wrapper from the same web code. + real devices on different networks. (Needs a provider account.) ### Smaller debt -- [ ] DM key backup (passphrase) + device-only delivery toggle (deferred from - the DM work). -- [ ] OPFS cleanup sweep for abandoned partial transfers. +- [ ] Device-only DM delivery toggle (deferred from the DM work). - [ ] Swap the temporary hostname for a real (sub)domain when one is available: edit the Caddyfile site line + ALLOWED_ORIGINS, reload Caddy. +- [ ] (Optional, later) Tauri desktop wrapper from the same web code.