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) {
|
async function sendMessage(message: any) {
|
||||||
if (
|
const clients = await self.clients.matchAll()
|
||||||
"type" in event &&
|
|
||||||
event.type === "subscribed" &&
|
await Promise.all(
|
||||||
"subscription" in event
|
clients.map(async (client) => client.postMessage(message))
|
||||||
) {
|
)
|
||||||
await event.waitUntil(
|
}
|
||||||
submitSubscription(
|
|
||||||
self.registration,
|
self.addEventListener("message", function (event) {
|
||||||
event.subscription as PushSubscription
|
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) {
|
self.addEventListener("pushsubscriptionchange", function (event) {
|
||||||
|
|
@ -67,18 +91,7 @@ export default function start(self: ServiceWorkerGlobalScope) {
|
||||||
existingSubscription
|
existingSubscription
|
||||||
)
|
)
|
||||||
|
|
||||||
const clients = await self.clients.matchAll()
|
await sendMessage({ type: "sent subscription", newSubscription })
|
||||||
|
|
||||||
await Promise.all(
|
|
||||||
clients.map(async (client) =>
|
|
||||||
client.postMessage({
|
|
||||||
subscription:
|
|
||||||
await self.registration.pushManager.getSubscription(),
|
|
||||||
event,
|
|
||||||
newSubscription,
|
|
||||||
})
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})()
|
})()
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue