1// Service Worker for Firebase Cloud Messaging 2importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js'); 3importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js'); 4 5// Initialize Firebase in the service worker 6firebase.initializeApp({ 7 apiKey: "AIzaSyCOEwqU1FXbCM_6Z16J-0eIk-zqP8KRcHk", 8 authDomain: "newslinemedia-9ff5f.firebaseapp.com", 9 projectId: "newslinemedia-9ff5f", 10 storageBucket: "newslinemedia-9ff5f.firebasestorage.app", 11 messagingSenderId: "105396564197777951159", 12 appId: "1:105396564197777951159:web:c95c2ec6ae5d09fabc9b76", 13 measurementId: "G-KQ6JQQMGQL" 14}); 15 16// Retrieve an instance of Firebase Messaging 17const messaging = firebase.messaging(); 18 19// Handle background messages 20messaging.onBackgroundMessage((payload) => { 21 console.log('[firebase-messaging-sw.js] Received background message ', payload); 22 23 const notificationTitle = payload.notification?.title || payload.data?.title || 'Newsline Radio'; 24 const notificationOptions = { 25 body: payload.notification?.body || payload.data?.body || 'New notification from Newsline Radio', 26 icon: '/newsline-logo.png', 27 badge: '/newsline-logo.png', 28 vibrate: [200, 100, 200], 29 tag: 'newsline-notification', 30 requireInteraction: true, 31 data: { 32 url: payload.data?.url || 'https://radio.kenlive.co.ke' 33 } 34 }; 35 36 self.registration.showNotification(notificationTitle, notificationOptions); 37}); 38 39// Handle notification click 40self.addEventListener('notificationclick', (event) => { 41 console.log('[firebase-messaging-sw.js] Notification click received.'); 42 43 event.notification.close(); 44 45 // Open the URL from the notification data or default to homepage 46 const urlToOpen = event.notification.data?.url || 'https://radio.kenlive.co.ke'; 47 48 event.waitUntil( 49 clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => { 50 // Check if there's already a window open with this URL 51 for (const client of clientList) { 52 if (client.url === urlToOpen && 'focus' in client) { 53 return client.focus(); 54 } 55 } 56 // If not, open a new window 57 if (clients.openWindow) { 58 return clients.openWindow(urlToOpen); 59 } 60 }) 61 ); 62});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.