WebpushClient
WebpushClient
Send a Web push notification using the web-push npm module, referer to it for details how to generate VAPID credentials to
configure this module with 3 required parameters:
key- VAPID private keypubkey- VAPID public keyemail- an admin email for the VAPID subject
The device token must be generated in the browser after successful subscription:
navigator.serviceWorker.register("/js/webpush.js", { scope: "/" }).then(function(registration) {
registration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: vapidKeyPublic }).then(function(subscription) {
bkjs.send({ url: '/user/update', data: { pushkey: "wp://" + window.btoa(JSON.stringify(subscription)) }, type: "POST" });
}).catch((err) => {})
});