-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
39 lines (36 loc) · 1.38 KB
/
sw.js
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
30
31
32
33
34
35
36
37
38
39
self.addEventListener('push', (e) => {
const title = 'id-go Authentication request';
const options =
{ body : 'Proceed to accept or reject this authentication reqeust'
, requireInteraction: true // visible until user clicks or dismisses
, vibrate : [200, 100, 200, 100, 200, 100, 200] // vibration patter to play when notification is dislpayed
, icon : './img/id-go.png'
, image : './img/unitus-logo-360-240.png', // needs to be 360x240
};
self.registration.showNotification(title, options)
.then(() => { console.log('calling showNotification()') })
.catch((err) => { console.error(`showNotification error: ${err}`) });
});
self.addEventListener('notificationclick', (event) => {
console.log('On notification click: ', event.notification?.tag);
// Android doesn't close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(
clients.matchAll({
type: "window"
})
.then((clientList) => {
for (var i = 0; i < clientList.length; i++) {
var client = clientList[i];
if (client.url == '/' && 'focus' in client)
return client.focus();
}
if (clients.openWindow) {
return clients.openWindow('/');
}
})
);
});