45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
// Service Worker pour les notifications push — Dashboard Admin CHU-IPTV
|
|
|
|
self.addEventListener('push', (event) => {
|
|
if (!event.data) return;
|
|
|
|
const data = event.data.json();
|
|
const options = {
|
|
body: data.body || 'Nouvelle notification',
|
|
icon: data.icon || '/icon-192.png',
|
|
badge: data.badge || '/badge-72.png',
|
|
data: data.data || {},
|
|
vibrate: [200, 100, 200],
|
|
requireInteraction: true,
|
|
tag: data.data?.requestId || 'chu-iptv-notification',
|
|
actions: [
|
|
{ action: 'view', title: 'Voir' },
|
|
{ action: 'dismiss', title: 'Ignorer' }
|
|
]
|
|
};
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title || 'CHU-IPTV', options)
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
|
|
if (event.action === 'dismiss') return;
|
|
|
|
// Ouvrir ou focus le dashboard admin
|
|
event.waitUntil(
|
|
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
|
|
for (const client of clientList) {
|
|
if (client.url.includes('chu-iptv-admin') && 'focus' in client) {
|
|
return client.focus();
|
|
}
|
|
}
|
|
return clients.openWindow('https://chu-iptv-admin.cosmolan.fr');
|
|
})
|
|
);
|
|
});
|
|
|
|
self.addEventListener('install', () => self.skipWaiting());
|
|
self.addEventListener('activate', () => self.clients.claim());
|