Files
openchamber/packages/web/src/main.tsx
T
Bohdan Triapitsyn 1f23b63c0b feat: add Web Push API support and PWA integration (#189)
* feat: add Web Push API support and PWA integration

Add web Push API with subscribe/unsubscribe and visibility endpoints
Introduce usePushVisibilityBeacon and useSessionDeepLink hooks
Integrate PWA with service worker, registerSW, and VAPID key persistence

* feat: add heartbeat visibility beacon for web runtime

Add a 10s heartbeat to ping visibility while visible
Subscribe to visibilitychange, focus, blur, pageshow, and pagehide events to report state
Clear heartbeat interval on unmount to avoid leaks
2026-01-22 01:19:24 +02:00

33 lines
789 B
TypeScript

import { createWebAPIs } from './api';
import { registerSW } from 'virtual:pwa-register';
import type { RuntimeAPIs } from '@openchamber/ui/lib/api/types';
import '@openchamber/ui/index.css';
import '@openchamber/ui/styles/fonts';
declare global {
interface Window {
__OPENCHAMBER_RUNTIME_APIS__?: RuntimeAPIs;
}
}
window.__OPENCHAMBER_RUNTIME_APIS__ = createWebAPIs();
registerSW({
onRegistered(registration: ServiceWorkerRegistration | undefined) {
if (!registration) {
return;
}
// Periodic update check (best-effort)
setInterval(() => {
void registration.update();
}, 60 * 60 * 1000);
},
onRegisterError(error: unknown) {
console.warn('[PWA] service worker registration failed:', error);
},
});
import('@openchamber/ui/main');