-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswfcm.js
More file actions
40 lines (34 loc) · 997 Bytes
/
Copy pathswfcm.js
File metadata and controls
40 lines (34 loc) · 997 Bytes
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
self.skipWaiting()
self.addEventListener('push', function (event) {
const data = event.data.json()
data.notification.data = data.data
if (data.data.requireInteraction) {
data.notification.requireInteraction = true
}
if (data.data.image) {
data.notification.image = data.data.image;
}
data.notification.data.url = data.notification.click_action
event.waitUntil(self.registration.showNotification(data.notification.title, data.notification))
// Track open
fetch('https://api.mailfire.io/v1/webpush/show/' + data.data.id, {
method: 'post'
})
})
self.addEventListener('notificationclick', function (event) {
event.notification.close()
// Show page
event.waitUntil(
clients
.matchAll({
type: 'window'
})
.then(function() {
return clients.openWindow(event.notification.data.url)
})
)
// Track click
fetch('https://api.mailfire.io/v1/webpush/click/' + event.notification.data.id, {
method: 'post'
})
})