workspace-v1/projects/gamilit/apps/frontend/public/firebase-messaging-sw.js
Adrian Flores Cortes 967ab360bb Initial commit: Workspace v1 with 3-layer architecture
Structure:
- control-plane/: Registries, SIMCO directives, CI/CD templates
- projects/: Gamilit, ERP-Suite, Trading-Platform, Betting-Analytics
- shared/: Libs catalog, knowledge-base

Key features:
- Centralized port, domain, database, and service registries
- 23 SIMCO directives + 6 fundamental principles
- NEXUS agent profiles with delegation rules
- Validation scripts for workspace integrity
- Dockerfiles for all services
- Path aliases for quick reference

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-23 00:35:19 -06:00

77 lines
2.4 KiB
JavaScript

// Firebase Messaging Service Worker
// This file must be in the public directory to be served from root
// Import Firebase scripts
importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-app-compat.js');
importScripts('https://www.gstatic.com/firebasejs/10.7.0/firebase-messaging-compat.js');
// Initialize Firebase with same config
// Note: These will need to be updated with actual values or injected at build time
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: '',
storageBucket: '',
messagingSenderId: '',
appId: '',
};
// Only initialize if we have configuration
if (firebaseConfig.apiKey && firebaseConfig.projectId) {
firebase.initializeApp(firebaseConfig);
const messaging = firebase.messaging();
// Handle background messages
messaging.onBackgroundMessage((payload) => {
console.log('[SW] Background message received:', payload);
const notificationTitle = payload.notification?.title || 'GAMILIT';
const notificationOptions = {
body: payload.notification?.body || '',
icon: '/icons/icon-192x192.png',
badge: '/icons/badge-72x72.png',
tag: payload.data?.tag || 'default',
data: payload.data,
// Vibration pattern: vibrate 200ms, pause 100ms, vibrate 200ms
vibrate: [200, 100, 200],
// Actions for interactive notifications
actions: [
{ action: 'open', title: 'Ver' },
{ action: 'dismiss', title: 'Cerrar' },
],
};
self.registration.showNotification(notificationTitle, notificationOptions);
});
// Handle notification click
self.addEventListener('notificationclick', (event) => {
console.log('[SW] Notification clicked:', event);
event.notification.close();
if (event.action === 'dismiss') {
return;
}
// Open or focus the app
const urlToOpen = event.notification.data?.action_url || '/notifications';
event.waitUntil(
clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => {
// Check if app is already open
for (const client of clientList) {
if (client.url.includes(self.location.origin) && 'focus' in client) {
client.focus();
client.navigate(urlToOpen);
return;
}
}
// If not open, open new window
if (clients.openWindow) {
return clients.openWindow(urlToOpen);
}
})
);
});
}