mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
More web push progress.
This commit is contained in:
parent
50185dac86
commit
af1fcb8431
4 changed files with 86 additions and 22 deletions
|
@ -1,18 +1,13 @@
|
|||
|
||||
self.addEventListener('push', function (event) {
|
||||
console.log('Service Worker push', JSON.stringify(event));
|
||||
if (event.data) {
|
||||
console.log("Push event!! ", event.data.text());
|
||||
showLocalNotification("Yolo", event.data.text(), self.registration);
|
||||
} else {
|
||||
console.log("Push event but no data");
|
||||
}
|
||||
if (event.data == null) return;
|
||||
var json = event.data.json();
|
||||
const options = { body: json.body, icon: '/favicon-303x303.png', tag: json.url };
|
||||
if (json.icon) { options.icon = '/images/notify/icons128-' + json.icon + '.png'; }
|
||||
self.registration.showNotification(json.title, options);
|
||||
});
|
||||
|
||||
const showLocalNotification = function(title, body, swRegistration) {
|
||||
const options = {
|
||||
body
|
||||
// here you can add more properties like icon, image, vibrate, etc.
|
||||
};
|
||||
swRegistration.showNotification(title, options);
|
||||
};
|
||||
self.addEventListener('notificationclick', function (event) {
|
||||
event.notification.close();
|
||||
if ((event.notification.tag != null) && (event.notification.tag != '')) { event.waitUntil(self.clients.openWindow(event.notification.tag)); }
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue