-
Notifications
You must be signed in to change notification settings - Fork 93
/
sw.js
27 lines (22 loc) · 863 Bytes
/
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
function receivePushNotification(event) {
console.log("[Service Worker] Push Received.");
const { image, tag, url, title, text } = event.data.json();
const options = {
data: url,
body: text,
icon: image,
vibrate: [200, 100, 200],
tag: tag,
image: image,
badge: "https://spyna.it/icons/favicon.ico",
actions: [{ action: "Detail", title: "View", icon: "https://via.placeholder.com/128/ff0000" }]
};
event.waitUntil(self.registration.showNotification(title, options));
}
function openPushNotification(event) {
console.log("[Service Worker] Notification click Received.", event.notification.data);
event.notification.close();
event.waitUntil(clients.openWindow(event.notification.data));
}
self.addEventListener("push", receivePushNotification);
self.addEventListener("notificationclick", openPushNotification);