Node/Express server shells out to adb (connect/pair/keyevent/text/app launch) and serves a mobile-first installable PWA remote: power, mute, input switch, volume/channel rockers, D-pad, media transport, text entry, and one-tap streaming app launch. Supports multiple saved TVs and the Android 11+ wireless-debugging pairing flow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RSVyYcrjrbmrMKT85G4fyn
26 lines
858 B
JavaScript
26 lines
858 B
JavaScript
const CACHE = "tv-remote-shell-v1";
|
|
const SHELL_FILES = ["/", "/styles.css", "/app.js", "/manifest.json"];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL_FILES)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
// Network-first for API calls (never serve stale remote-control state),
|
|
// cache-first for the static shell so the app still opens offline.
|
|
self.addEventListener("fetch", (event) => {
|
|
const url = new URL(event.request.url);
|
|
if (url.pathname.startsWith("/api/")) return;
|
|
|
|
event.respondWith(
|
|
caches.match(event.request).then((cached) => cached || fetch(event.request))
|
|
);
|
|
});
|