feat(push): implementar Web Push VAPID en segundo plano con app cerrada para iOS y Android

This commit is contained in:
unknown
2026-10-06 01:29:25 -06:00
parent a948ed03fd
commit 70700356a7
7 changed files with 516 additions and 16 deletions
+28 -2
View File
@@ -1,5 +1,5 @@
// RecreoPay PWA Service Worker v8.3 - Buscador Inteligente Carga Manual
const CACHE_NAME = 'recreopay-v8.3';
// RecreoPay PWA Service Worker v8.5 - Soporte Web Push VAPID en Segundo Plano
const CACHE_NAME = 'recreopay-v8.5';
const STATIC_ASSETS = [
'/',
'/index.html',
@@ -76,6 +76,32 @@ self.addEventListener('fetch', (event) => {
);
});
// Manejador de Notificaciones Push de Fondo (VAPID) - Activo aun con la app CERRADA
self.addEventListener('push', (event) => {
let data = {};
if (event.data) {
try {
data = event.data.json();
} catch (e) {
data = { title: '🔔 RecreoPay', body: event.data.text() };
}
}
const title = data.title || '🔔 RecreoPay';
const options = {
body: data.body || 'Tienes una nueva notificación de RecreoPay',
icon: data.icon || '/icons/icon-192.png',
badge: data.badge || '/icons/icon-192.png',
vibrate: [250, 100, 250, 100, 250],
data: data.data || { url: '/pos.html?tab=sinpe' },
tag: data.tag || `recreopay-push-${Date.now()}`,
renotify: true,
requireInteraction: true
};
event.waitUntil(self.registration.showNotification(title, options));
});
// Manejador de clics en Notificaciones Push
self.addEventListener('notificationclick', (event) => {
event.notification.close();