send notifications over SSE to be displayed inside the app

This commit is contained in:
m5r
2022-06-19 17:57:51 +02:00
parent a46a4a3861
commit 6cf2f8cb94
13 changed files with 146 additions and 63 deletions

View File

@ -59,7 +59,8 @@ const lastTimeRevalidated: Record<string, number> = {};
export function fetchLoaderData(event: FetchEvent): Promise<Response> {
const url = new URL(event.request.url);
if (url.pathname === "/outgoing-call/twilio-token") {
const doNotCacheList = ["/outgoing-call/twilio-token"];
if (doNotCacheList.includes(url.pathname)) {
return fetch(event.request);
}

View File

@ -20,14 +20,6 @@ export default async function handlePush(event: PushEvent) {
revalidateChannel.postMessage("revalidateLoaderData");
revalidateChannel.close();
const clients = await self.clients.matchAll({ type: "window" });
const hasOpenTab = clients.some((client) => client.focused === true);
if (hasOpenTab) {
const notifyChannel = new BroadcastChannel("notifications");
notifyChannel.postMessage(JSON.stringify(payload));
notifyChannel.close();
} else {
await self.registration.showNotification(payload.title, options);
await addBadge(1);
}
await self.registration.showNotification(payload.title, options);
await addBadge(1);
}