1importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-app-compat.js'); 2importScripts('https://www.gstatic.com/firebasejs/10.13.2/firebase-messaging-compat.js'); 3 4// Initialize the Firebase app in the service worker by passing in the 5// messagingSenderId. 6firebase.initializeApp({ 7 apiKey: "AIzaSyCE6m7NnEvlvqtaZqtWir5SxiPi9ZawAYQ", 8 authDomain: "sanjeev-kumar-189208.firebaseapp.com", 9 databaseURL: "https://sanjeev-kumar-189208.firebaseio.com", 10 projectId: "sanjeev-kumar-189208", 11 storageBucket: "sanjeev-kumar-189208.appspot.com", 12 messagingSenderId: "576916930437", 13 appId: "1:576916930437:web:2c9a38c23a6aa42df24eec" 14}); 15 16const messaging = firebase.messaging(); 17 18function getPayloadValue(payload, key, defaultValue) { 19 if (payload && payload.notification && payload.notification[key]) { 20 return payload.notification[key]; 21 } 22 if (payload && payload.data && payload.data[key]) { 23 return payload.data[key]; 24 } 25 return defaultValue; 26} 27 28function showWebPushNotification(payload) { 29 const title = getPayloadValue(payload, 'title', 'MoneyWorks4Me.com'); 30 const body = getPayloadValue(payload, 'body', ''); 31 const icon = getPayloadValue(payload, 'icon', 'https://moneyworks4me.com/images/common/logo-v4.png'); 32 const image = getPayloadValue(payload, 'image', ''); 33 const clickAction = getPayloadValue(payload, 'click_action', ''); 34 const redirectUrl = (clickAction && clickAction.indexOf('http') === 0) 35 ? clickAction 36 : ('https://www.moneyworks4me.com/' + String(clickAction).replace(/^\/+/, '')); 37 38 const notificationOptions = { 39 body: body, 40 icon: icon, 41 image: image, 42 requireInteraction: true, 43 data: { 44 click_action: redirectUrl 45 } 46 }; 47 return self.registration.showNotification(title, notificationOptions); 48} 49 50function notifyOpenClients(payload) { 51 return self.clients.matchAll({ 52 type: 'window', 53 includeUncontrolled: true 54 }).then(function(clientList) { 55 clientList.forEach(function(client) { 56 client.postMessage({ 57 type: 'MW4ME_PUSH_RECEIVED', 58 payload: payload 59 }); 60 }); 61 }); 62} 63 64messaging.onBackgroundMessage(function(payload) { 65 console.log('[firebase-messaging-sw.js] Received background message ', payload); 66 return Promise.all([ 67 showWebPushNotification(payload), 68 notifyOpenClients(payload) 69 ]); 70}); 71 72self.addEventListener('push', function(event) { 73 if (!event || !event.data) { 74 return; 75 } 76 event.waitUntil((async function() { 77 try { 78 const payload = event.data.json(); 79 await Promise.all([ 80 showWebPushNotification(payload), 81 notifyOpenClients(payload) 82 ]); 83 } catch (error) { 84 console.log('[firebase-messaging-sw.js] push handler parse failed', error); 85 } 86 })()); 87}); 88 89self.addEventListener('notificationclick', function(event) 90{ 91 console.log('On notification click: ', event.notification); 92 event.notification.close(); 93 var redirectUrl = null; 94 if (event.notification.data) 95 { 96 redirectUrl = event.notification.data ? event.notification.data.click_action : null; 97 } 98 console.log("redirect url is : " + redirectUrl); 99 if (redirectUrl) 100 { 101 event.waitUntil(async function () { 102 var allClients = await clients.matchAll({ 103 includeUncontrolled: true 104 }); 105 var chatClient; 106 for (var i = 0; i < allClients.length; i++) { 107 var client = allClients[i]; 108 if (client['url'].indexOf(redirectUrl) >= 0) { 109 client.focus(); 110 chatClient = client; 111 break; 112 } 113 } 114 if (chatClient == null || chatClient == 'undefined') { 115 chatClient = clients.openWindow(redirectUrl); 116 return chatClient; 117 } 118 }()); 119 } 120// console.log(event.notification.data.click_action); 121// event.notification.close(); 122 //event.waitUntil(self.registration.showNotification(notificationTitle, notificationOptions));
123// event.waitUntil(self.clients.openWindow(event.notification.data.click_action)); 124}); 125 126self.addEventListener("notificationclose", function (event) 127{ 128 event.notification.close(); 129 console.log('user has clicked notification close'); 130});
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.