Send debug messages back to client
Test / test (push) Failing after 52s
Details
Test / test (push) Failing after 52s
Details
This commit is contained in:
parent
4a7d752230
commit
07d638b66c
|
|
@ -40,19 +40,43 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
|||
// )
|
||||
// })
|
||||
|
||||
self.addEventListener("message", async function (event) {
|
||||
if (
|
||||
"type" in event &&
|
||||
event.type === "subscribed" &&
|
||||
"subscription" in event
|
||||
) {
|
||||
await event.waitUntil(
|
||||
submitSubscription(
|
||||
self.registration,
|
||||
event.subscription as PushSubscription
|
||||
)
|
||||
)
|
||||
}
|
||||
async function sendMessage(message: any) {
|
||||
const clients = await self.clients.matchAll()
|
||||
|
||||
await Promise.all(
|
||||
clients.map(async (client) => client.postMessage(message))
|
||||
)
|
||||
}
|
||||
|
||||
self.addEventListener("message", function (event) {
|
||||
const waitEvent = event as ExtendableEvent
|
||||
waitEvent.waitUntil(
|
||||
(async () => {
|
||||
if (
|
||||
"type" in event &&
|
||||
event.type === "subscribed" &&
|
||||
"subscription" in event
|
||||
) {
|
||||
try {
|
||||
await event.waitUntil(
|
||||
submitSubscription(
|
||||
self.registration,
|
||||
event.subscription as PushSubscription
|
||||
)
|
||||
)
|
||||
} catch (e) {
|
||||
await sendMessage({
|
||||
message: "Got error processing subscription",
|
||||
error: (e as Error).toString(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
await sendMessage({
|
||||
message: "Processed subscription",
|
||||
})
|
||||
})()
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener("pushsubscriptionchange", function (event) {
|
||||
|
|
@ -67,18 +91,7 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
|||
existingSubscription
|
||||
)
|
||||
|
||||
const clients = await self.clients.matchAll()
|
||||
|
||||
await Promise.all(
|
||||
clients.map(async (client) =>
|
||||
client.postMessage({
|
||||
subscription:
|
||||
await self.registration.pushManager.getSubscription(),
|
||||
event,
|
||||
newSubscription,
|
||||
})
|
||||
)
|
||||
)
|
||||
await sendMessage({ type: "sent subscription", newSubscription })
|
||||
})()
|
||||
)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue