1// Firebase-Konfiguration 2 3let messaging = undefined; 4let app = undefined; 5function initPush() { 6 setTimeout(() => { 7 if (!($('html').data('plt-android') || $('html').data('plt-ios'))) { 8 if (!('serviceWorker' in navigator)) { 9 console.warn('[Push] Service Worker nicht verfügbar â Firebase Messaging nicht initialisiert'); 10 return; 11 } 12 const firebaseConfig = { 13 apiKey: "AIzaSyCxwzTqEWvoCmMYGhVDAk9d6sEU3E_tT7Q", 14 authDomain: "appec-app.firebaseapp.com", 15 projectId: "appec-app", 16 storageBucket: "appec-app.firebasestorage.app", 17 messagingSenderId: "301629644694", 18 appId: "1:301629644694:web:0834065de2d28e2be687b7", 19 measurementId: "G-Z3K9V7GC2Q" 20 }; 21 22 // Firebase initialisieren 23 app = firebase.initializeApp(firebaseConfig); 24 firebase.analytics(); 25 messaging = firebase.messaging(); 26 27 28 // Push-Nachricht empfangen, wenn Tab aktiv ist 29 messaging.onMessage(function (payload) { 30 $('#pushMessage').text(payload.notification.title + ': ' + payload.notification.body); 31 32 const notification = payload.notification || {}; 33 const data = payload.data || {}; 34 35 const title = notification.title || 'Notification'; 36 const body = notification.body || ''; 37 const icon = notification.icon || 'favicon/favicon-96x96.png'; 38 39 const url = (payload.fcmOptions && payload.fcmOptions.link) 40 || data.url || '/'; 41 presentToast(title + '<br />' + body, 'fa-message', 'secondary', 10000, url); 42 43 }); 44 } 45 $('#registerPushToken').removeClass('hide-me'); 46 if ($('html').data('user_login_check') && shouldRegisterTokenAgain()) { 47 setTimeout(() => { 48 registerPushToken(); 49 }, 500); 50 } 51 if (!$('html').data('user_login_check')) { 52 setTimeout(() => { 53 removeToken(); 54 }, 500); 55 } 56 }, 1000); 57} 58 59$('#registerPushToken').click(function () { 60 registerPushToken(true); 61}) 62 63initPush(); 64 65// Hauptfunktion zum Registrieren des Push Tokens 66registerPushToken = async function (manual = false) { 67 localStorage.removeItem('push_declined'); 68 if (!($('html').data('plt-android') || $('html').data('plt-ios'))) { 69 try { 70 if (!('serviceWorker' in navigator)) { 71 console.warn('[Push] Service Worker nicht verfügbar â Firebase Messaging nicht initialisiert'); 72 return; 73 } 74 const registration = await navigator.serviceWorker.register('firebase-messaging-sw.js'); 75 const permission = await Notification.requestPermission(); 76 if (permission !== 'granted') { 77 console.warn('[Push] Berechtigung abgelehnt'); 78 localStorage.setItem('push_declined', 'true'); 79 if (manual) { 80 presentToast(translate['USER_PUSH_TOKEN']['PUSH_DECLINED'], 'fa-exclamation-triangle', 'warning', 4000); 81 } 82 return; 83 } 84 85 const token = await messaging.getToken({ 86 vapidKey: 'BCgnWoJvvE1aYwl9psj66UME7IDgttfdLou8LYJonJQV8ctyJ6ezsk6eczZVM-zJHNVmYyyde79PmxqBIXYp9S8', 87 serviceWorkerRegistration: registration 88 }); 89 90 if (!token) { 91 console.warn('[Push] Kein Token erhalten'); 92 return; 93 } 94 95 const deviceData = { 96 token: token, 97 user_agent: navigator.userAgent 98 }; 99 100 sendTokenToServer(deviceData, manual); 101 102 } catch (err) { 103 console.error('[Push] Fehler bei der Tokenregistrierung:', err); 104 } 105 } else { 106 if (window.webkit && webkit.messageHandlers && webkit.messageHandlers.cordova_iab) { 107 var messageObj = { function: 'requestPush', manual: manual }; 108 var stringifiedMessageObj = JSON.stringify(messageObj); 109 webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj); 110 } else { 111 console.log('Push nur auf iOS WebView möglich'); 112 } 113 } 114}; 115async function sendTokenToServer(deviceData, manual = false) { 116 return new Promise(async (resolve, reject) => { 117 $.ajax({ 118 type: 'POST', 119 url: 'addpushtoken', 120 data: { data: deviceData }, 121 cache: false, 122 success: function (result) { 123 localStorage.setItem('push_token', deviceData.token); 124 localStorage.setItem('push_token_last', Date.now().toString()); 125 localStorage.removeItem('push_declined'); 126 // console.log('[Push] Token wurde dem Server hinzugefügt.'); 127 128 if (manual) { 129 try { 130 const myNotification = new Notification(translate['USER_PUSH_TOKEN']['PUSH_ENABELD'], {
131 body: '', 132 icon: 'favicon/favicon-96x96.png' 133 }); 134 } catch (err) { 135 presentToast(translate['USER_PUSH_TOKEN']['PUSH_ENABELD'], 'fa-message', 'secondary', 5000) 136 } 137 resolve(true); 138 } 139 }, 140 error: function (xhr, status, error) { 141 console.error('[Push] Fehler beim Speichern des Tokens:', error); 142 resolve(false); 143 } 144 }); 145 }); 146 147} 148// Alle 6 h wird token aktualisiert 149function shouldRegisterTokenAgain() { 150 const lastToken = localStorage.getItem('push_token'); 151 const lastTime = localStorage.getItem('push_token_last'); 152 const push_declined = localStorage.getItem('push_declined'); 153 154 if (push_declined !== 'true') { 155 if (!lastToken || !lastTime || (Date.now() - parseInt(lastTime)) > 21600000) { 156 return true; 157 } 158 } 159 return false; 160} 161async function removeTokenFromServer(token) { 162 if (token) { 163 $.ajax({ 164 type: 'POST', 165 url: 'deletepushtoken', 166 data: { token: token }, 167 cache: false, 168 success: function (result) { 169 // console.log('[Push] Token wurde vom Server entfernt.'); 170 }, 171 error: function (xhr, status, error) { 172 console.error('[Push] Fehler beim Löschen des Tokens vom Server:', error); 173 } 174 }); 175 } 176 localStorage.removeItem('push_token'); 177 localStorage.removeItem('push_token_last'); 178 localStorage.removeItem('push_declined'); 179} 180async function removeToken() { 181 let token = localStorage.getItem('push_token'); 182 if (!($('html').data('plt-android') || $('html').data('plt-ios'))) { 183 if (!token && messaging) { 184 try { 185 token = await messaging.getToken(); 186 // console.log('[Push] Token bei Firebase geholt:', token); 187 } catch (err) { 188 console.warn('[Push] Konnte Token nicht von Firebase abrufen:', err); 189 } 190 } 191 if (token && messaging) { 192 try { 193 const deleted = await messaging.deleteToken(token); 194 // console.log('[Push] Token bei Firebase gelöscht:', deleted); 195 } catch (err) { 196 console.warn('[Push] Fehler beim Löschen des Tokens bei Firebase:', err); 197 } 198 } 199 removeTokenFromServer(token); 200 } else { 201 var messageObj = { function: 'removetoken' }; 202 var stringifiedMessageObj = JSON.stringify(messageObj); 203 webkit.messageHandlers.cordova_iab.postMessage(stringifiedMessageObj); 204 } 205}
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.