send notifications over SSE to be displayed inside the app
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user