1let oldToken = ""; 2let error_db_error = ""; 3(() => { 4 const asyncForEach = (array, callback, done) => { 5 const runAndWait = (i) => { 6 if (i === array.length) return done(); 7 return callback(array[i], () => runAndWait(i + 1)); 8 }; 9 return runAndWait(0); 10 }; 11 12 const dump = {}; 13 var dbExists = true; 14 var dbRequest = window.indexedDB.open("firebase-messaging-database"); 15 dbRequest.onerror = function (event) { 16 //console.log("ERROR: " + event.target.errorCode) 17 }; 18 19 dbRequest.onupgradeneeded = function (e) { 20 e.target.transaction.abort(); 21 dbExists = false; 22 }; 23 dbRequest.onsuccess = () => { 24 const db = dbRequest.result; 25 const stores = ["firebase-messaging-store"]; 26 const tx = db.transaction(stores); 27 asyncForEach( 28 stores, 29 (store, next) => { 30 const req = tx.objectStore(store).getAll(); 31 32 req.onsuccess = () => { 33 dump[store] = req.result; 34 next(); 35 }; 36 }, 37 () => { 38 if(dump["firebase-messaging-store"][0] !== undefined && dump["firebase-messaging-store"][0].token !== undefined) { 39 oldToken += dump["firebase-messaging-store"][0].token; 40 } 41 } 42 ); 43 }; 44})(); 45 46if (typeof firebase !== 'undefined') { 47 firebase.initializeApp(firebaseConfig); 48} 49 50var messaging = ""; 51if (typeof firebase !== 'undefined' && firebase.messaging.isSupported()) { 52 messaging = firebase.messaging(); 53} 54 55var swRegistration = null; 56 57if ("serviceWorker" in navigator) { 58 navigator.serviceWorker 59 .register("/firebase-messaging-sw.js") 60 .then((registration) => { 61 console.log("Service Worker registered successfully:", registration); 62 swRegistration = registration; 63 return navigator.serviceWorker.ready; 64 }) 65 .then(() => { 66 console.log("Service Worker is now active and ready"); 67 }) 68 .catch((e) => { 69 console.error("Service Worker registration failed:", e); 70 }); 71} 72 73function InitializeFireBaseMessaging() { 74 if (typeof firebase !== 'undefined' && firebase.messaging.isSupported()) { 75 // Modern API: Notification.requestPermission() kullan 76 Notification.requestPermission() 77 .then(function (permission) { 78 if (permission === 'granted') { 79 console.log('Notification permission granted.'); 80 81 // Service Worker'ın aktif olmasını bekle 82 return navigator.serviceWorker.ready; 83 } else { 84 console.log('Notification permission denied.'); 85 throw new Error('Permission denied'); 86 } 87 }) 88 .then(function(registration) { 89 console.log('Service Worker ready, getting token...'); 90 // VAPID key ile token al ve service worker registration belirt 91 return messaging.getToken({ 92 serviceWorkerRegistration: swRegistration 93 }); 94 }) 95 .then(function (token) { 96 if (token) { 97 $(function () { 98 console.log("new:" + token); 99 console.log("old:" + oldToken); 100 if (oldToken === "") oldToken = ""; 101 $.post( 102 "/set-token-notification", 103 { token: token, userAgent: navigator.userAgent, oldToken: oldToken }, 104 function (data) { 105 console.log("Token sent to server successfully", data); 106 } 107 ).fail(function(xhr, status, error) { 108 console.error("Failed to send token to server:"); 109 console.error("Status:", status); 110 console.error("Error:", error); 111 console.error("Response:", xhr.responseText); 112 console.error("Status Code:", xhr.status); 113 }); 114 }); 115 } else { 116 console.log('No registration token available.'); 117 } 118 }) 119 .catch(function (reason) { 120 console.error('Error getting permission or token:', reason); 121 }); 122 123 // Foreground mesajları dinle 124 messaging.onMessage(function (payload) { 125 console.log('Message received in foreground:', payload); 126 const notificationOption = { 127 body: payload.notification.body, 128 icon: payload.notification.icon, 129 }; 130 if (Notification.permission === "granted") { 131 var notification = new Notification( 132 payload.notification.title, 133 notificationOption 134 ); 135 136 notification.onclick = function (ev) { 137 ev.preventDefault(); 138 window.open(payload.notification.click_action || payload.fcmOptions?.link, "_blank"); 139 notification.close(); 140 }; 141 } 142 }); 143 } 144}
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.