read message_delivery_method_web_push_vapid_public_key from public settings db
Main daploy / deploy (push) Successful in 43s
Main daploy / deploy (push) Successful in 43s
This commit is contained in:
@@ -2,7 +2,7 @@ import webpush from "web-push";
|
||||
import PouchDB from "./PouchDB.js";
|
||||
|
||||
if (!process.env.VAPID_SUBJECT) {
|
||||
throw new Error('VAPID_SUBJECT env is empty!');
|
||||
throw new Error("VAPID_SUBJECT env is empty!");
|
||||
}
|
||||
|
||||
const vapidKeys = webpush.generateVAPIDKeys();
|
||||
@@ -16,3 +16,12 @@ await new PouchDB(`${process.env.API_URL}/server_settings`, {
|
||||
keys: vapidKeys,
|
||||
},
|
||||
});
|
||||
|
||||
await new PouchDB(`${process.env.API_URL}/public_settings`, {
|
||||
skip_setup: true,
|
||||
}).put({
|
||||
_id: "public_settings:message_delivery_method_web_push_vapid_public_key",
|
||||
type: "public_settings",
|
||||
name: "message_delivery_method_web_push_vapid_public_key",
|
||||
value: vapidKeys.publicKey,
|
||||
});
|
||||
|
||||
@@ -24,8 +24,9 @@
|
||||
},
|
||||
"contributors": [],
|
||||
"scripts": {
|
||||
"dev": "",
|
||||
"test": ""
|
||||
"generate-keys": "node ./generate-keys.js",
|
||||
"test-send-notification": "node ./test-send-notification.js",
|
||||
"test-send-notification-cancel": "node ./test-send-notification-cancel.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"pouchdb-adapter-http": "^9.0.0",
|
||||
|
||||
@@ -22,13 +22,30 @@ const notification = {
|
||||
options: {
|
||||
icon: "/images/qr-code-logo-200x200.jpg",
|
||||
body: "Test push message from DevTools.",
|
||||
tag: "2105ef6f-3ca6-4f99-b258-0ca23f014309",
|
||||
tag: "01936062-d10f-7f2f-8ae3-dd7f9fbc5c7f",
|
||||
vibrate: [200, 100, 200, 100, 200, 100, 200],
|
||||
data: {
|
||||
url: "http://localhost:5173/chat/6ilhxu/13trvu",
|
||||
payload: { tag: "01936062-d10f-7f2f-8ae3-dd7f9fbc5c7f" },
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const notification2 = {
|
||||
type: "notification",
|
||||
notification: {
|
||||
title: "test",
|
||||
options: {
|
||||
icon: "/images/qr-code-logo-200x200.jpg",
|
||||
body: "Test push message from DevTools.",
|
||||
tag: "01936062-d10f-7f2f-8ae3-dd7f9fbc5c7f",
|
||||
// requireInteraction: true,
|
||||
// silent: false,
|
||||
// vibrate: [200, 100, 200, 100, 200, 100, 200],
|
||||
data: {
|
||||
url: "/chat/6ilhxu/13trvu",
|
||||
payload: { tag: "2105ef6f-3ca6-4f99-b258-0ca23f014309" },
|
||||
payload: { tag: "01936062-d10f-7f2f-8ae3-dd7f9fbc5c7f" },
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -50,7 +67,7 @@ const { rows } = await new PouchDB(
|
||||
},
|
||||
);
|
||||
|
||||
await Promise.allSettled(
|
||||
const result = await Promise.allSettled(
|
||||
rows.map(async ({ doc }) => {
|
||||
await webpush.sendNotification(
|
||||
doc.subscription,
|
||||
@@ -59,6 +76,7 @@ await Promise.allSettled(
|
||||
console.log("sent ", doc._id);
|
||||
}),
|
||||
);
|
||||
console.log(result);
|
||||
|
||||
// issues:
|
||||
// 1. NO SOUND
|
||||
|
||||
Reference in New Issue
Block a user