Refactor subscription format
Place the actual push subscription data into a push property on the subscription so that other properties can be added to it.
This commit is contained in:
parent
b4934005ae
commit
abdcc83eb9
5 changed files with 29 additions and 11 deletions
|
@ -14,9 +14,11 @@ export async function sendPush(title: string, body: string) {
|
|||
const removeIndexes = [];
|
||||
for (let index = 0; index < subscriptions.length; index += 1) {
|
||||
const subscription = subscriptions[index];
|
||||
if (subscription.type !== "push")
|
||||
continue;
|
||||
try {
|
||||
await webPush.sendNotification(
|
||||
subscription as webPush.PushSubscription,
|
||||
subscription.push as webPush.PushSubscription,
|
||||
payload,
|
||||
{
|
||||
TTL: 3600,
|
||||
|
@ -24,10 +26,11 @@ export async function sendPush(title: string, body: string) {
|
|||
}
|
||||
)
|
||||
} catch (err: any) {
|
||||
console.error("Received error sending push notice:", err.message, err?.statusCode)
|
||||
console.error(err);
|
||||
if (err?.statusCode >= 400 && err?.statusCode < 500) {
|
||||
removeIndexes.push(index)
|
||||
if (err?.statusCode === 410) {
|
||||
removeIndexes.push(index);
|
||||
} else {
|
||||
console.error("Received error sending push notice:", err.message, err?.statusCode)
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue