-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpush-sw.js
29 lines (24 loc) · 883 Bytes
/
push-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
/* global self, clients */
// triggered everytime, when a push notification is received.
console.log('Reached Here v6')
let url
self.addEventListener('push', function (event) {
console.info('Event: Push')
console.log(event.data && event.data.json())
const playload = (event.data && event.data.json()) || {}
var title = playload.title || 'No Title'
var body = {
body: playload.body || 'No Body',
icon:
playload.icon ||
'https://linklet.ml/static/favicons/android-chrome-192x192.png',
badge: 'https://linklet.ml/static/favicons/mstile-70x70.png'
}
url = playload.body
event.waitUntil(self.registration.showNotification(title, body))
})
self.addEventListener('notificationclick', function (event) {
console.log(event.notification)
event.notification.close() // Close the notification
event.waitUntil(clients.openWindow(url || '/'))
})