-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw.js
More file actions
60 lines (52 loc) · 1.7 KB
/
sw.js
File metadata and controls
60 lines (52 loc) · 1.7 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
self.addEventListener('push', function(event) {
console.log('Received push');
const notification_payload = JSON.parse(event.data.text())
console.dir(notification_payload)
let notificationTitle = 'Hello';
const notificationOptions = {
body: 'Thanks for sending this push msg.',
icon: './images/logo-192x192.png',
badge: './images/badge-72x72.png',
tag: 'simple-push-demo-notification',
data: {
url: notification_payload.action,
},
};
if (event.data) {
//const dataText = event.data.text();
notificationTitle = notification_payload.title;
notificationOptions.body = notification_payload.body;
notificationOptions.icon = notification_payload.icon;
notificationOptions.image = notification_payload.image;
notificationOptions.tag = notification_payload.title;
notificationOptions.data.url = notification_payload.action;
}
//console.log(notificationOptions)
console.log(notificationOptions);
event.waitUntil(
self.registration.showNotification(
notificationTitle, notificationOptions)
);
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
console.log(event)
let clickResponsePromise = Promise.resolve();
if (event.notification.data && event.notification.data.url) {
clickResponsePromise = clients.openWindow(event.notification.data.url);
}
// event.waitUntil(
// Promise.all([
// clickResponsePromise,
// self.analytics.trackEvent('notification-click'),
// ])
// );
});
//
// self.addEventListener('notificationclose', function(event) {
// event.waitUntil(
// Promise.all([
// self.analytics.trackEvent('notification-close'),
// ])
// );
// });