send notification when sms arrives
This commit is contained in:
40
worker/index.js
Normal file
40
worker/index.js
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict";
|
||||
|
||||
self.addEventListener("push", function (event) {
|
||||
console.log("event.data.text()", event.data.text());
|
||||
const data = JSON.parse(event.data.text());
|
||||
event.waitUntil(
|
||||
registration.showNotification(data.title, {
|
||||
body: data.message,
|
||||
icon: "/icons/android-chrome-192x192.png",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("notificationclick", function (event) {
|
||||
event.notification.close();
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: "window", includeUncontrolled: true }).then(function (clientList) {
|
||||
if (clientList.length > 0) {
|
||||
let client = clientList[0];
|
||||
for (let i = 0; i < clientList.length; i++) {
|
||||
if (clientList[i].focused) {
|
||||
client = clientList[i];
|
||||
}
|
||||
}
|
||||
return client.focus();
|
||||
}
|
||||
return clients.openWindow("/");
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
// self.addEventListener('pushsubscriptionchange', function(event) {
|
||||
// event.waitUntil(
|
||||
// Promise.all([
|
||||
// Promise.resolve(event.oldSubscription ? deleteSubscription(event.oldSubscription) : true),
|
||||
// Promise.resolve(event.newSubscription ? event.newSubscription : subscribePush(registration))
|
||||
// .then(function(sub) { return saveSubscription(sub) })
|
||||
// ])
|
||||
// )
|
||||
// })
|
Reference in New Issue
Block a user