aboutsummaryrefslogtreecommitdiff
path: root/src/main/resources/static/sw.js
blob: 48fe778743b2125c9f14971c3d06819064a45f0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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/')
  );
});