aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2023-01-24 01:59:39 +0300
committerGravatar Vitaly Takmazov2023-01-24 02:30:14 +0300
commitf62b6eb75e0a6e8fafbebf3a41b913cd2cb929ed (patch)
tree8e87c9b50a6518d0fedf03956c1769aa680fc4c3 /src/main/resources
parent93b812e56856a9426c681d5a783e089bcee3210d (diff)
Web Push
Diffstat (limited to 'src/main/resources')
-rw-r--r--src/main/resources/static/sw.js29
1 files changed, 29 insertions, 0 deletions
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 @@
+/// <reference no-default-lib="true"/>
+/// <reference lib="esnext" />
+/// <reference lib="WebWorker" />
+
+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/')
+ );
+});