From f62b6eb75e0a6e8fafbebf3a41b913cd2cb929ed Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 24 Jan 2023 01:59:39 +0300 Subject: Web Push --- src/main/resources/static/sw.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/resources/static/sw.js (limited to 'src/main/resources') diff --git a/src/main/resources/static/sw.js b/src/main/resources/static/sw.js new file mode 100644 index 00000000..48fe7787 --- /dev/null +++ b/src/main/resources/static/sw.js @@ -0,0 +1,29 @@ +/// +/// +/// + +var sw = /** @type {ServiceWorkerGlobalScope & typeof self} */ (self); +sw.addEventListener('install', function() { + sw.skipWaiting(); +}); +sw.addEventListener('activate', function() { + sw.clients.claim(); +}); +sw.addEventListener('push', function(evt) { + if (evt.data) { + const data = evt.data.json(); + console.log('Push', data); + if (data.body) { + sw.registration.showNotification(data.title, { + body: data.body, + icon: data.custom.message.user.avatar + }); + } + } +}); +sw.addEventListener('notificationclick', function(evt) { + evt.notification.close(); + evt.waitUntil( + sw.clients.openWindow('https://juick.com/') + ); +}); -- cgit v1.2.3