-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice-worker.js
32 lines (27 loc) · 1022 Bytes
/
service-worker.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
self.addEventListener('push', (event) => {
console.log('Push event received:', event);
// Extract plain text data from the push event
const message = event.data ? event.data.json() : 'Default notification text';
// Display the notification
const options = {
body: message, // Use the plain text as the notification body
icon: '', // Replace with the actual path to your icon
badge: '', // Replace with the actual path to your badge icon
};
event.waitUntil(
self.registration.showNotification('New Notification', options)
);
});
self.addEventListener('notificationclick', (event) => {
event.notification.close();
event.waitUntil(
clients.openWindow('http://localhost:5174') // Replace with your app's URL
);
});
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('notification-sounds').then((cache) => {
return cache.add('public/simple-notification-152054.mp3');
})
);
});