1/* eslint-disable no-undef */ 2// Pemblokir iklan/jaringan bisa menggagalkan importScripts; SW tetap terdaftar tanpa push, bukan gagal evaluasi. 3let firebaseLoaded = false; 4try { 5 importScripts("https://www.gstatic.com/firebasejs/8.2.7/firebase-app.js"); 6 importScripts("https://www.gstatic.com/firebasejs/8.2.7/firebase-messaging.js"); 7 firebaseLoaded = typeof firebase !== "undefined"; 8} catch (e) { 9 firebaseLoaded = false; 10} 11 12const firebaseConfig = { 13 apiKey: "AIzaSyApdo0hDJkgskWQPqJQC1tMYpGaoGayRx4", 14 authDomain: "tribelio.firebaseapp.com", 15 databaseURL: "https://tribelio.firebaseio.com", 16 projectId: "tribelio", 17 storageBucket: "tribelio.appspot.com", 18 messagingSenderId: "875692224499", 19 appId: "1:875692224499:web:2116fa0f974ed4073e2c86", 20 measurementId: "G-LGJS22JVRR" 21}; 22 23// Browser tanpa Push API (Safari lama, webview, Firefox dengan push mati) membuat firebase.messaging() melempar unsupported-browser. 24const messagingSupported = firebaseLoaded && firebase.messaging && firebase.messaging.isSupported(); 25const messaging = messagingSupported ? (firebase.initializeApp(firebaseConfig), firebase.messaging()) : null; 26 27if (messaging) { 28 29 30// If you would like to customize notifications that are received in the 31// background (Web app is closed or not in browser focus) then you should 32// implement this optional method. 33// Keep in mind that FCM will still show notification messages automatically 34// and you should use data messages for custom notifications. 35// For more info see: 36// https://firebase.google.com/docs/cloud-messaging/concept-options 37messaging.onBackgroundMessage(function (payload) { 38 console.log("[firebase-messaging-sw.js] Received background message ", payload); 39 40 let data = JSON.parse(payload.data.payload); 41 console.log("fcmData", data); 42 43 if (!data) { return; } 44 45 var username = data.username; 46 var useravatar = data.user_avatar; 47 var roomName = data.room_name; 48 // var title = "New message from " + username; 49 var title = username; 50 51 if (data.chat_type == "group") { 52 // title = `[${roomName}] : ${username}`; 53 title = roomName; 54 } 55 56 var body = data.message; 57 58 var options = { 59 icon: useravatar, 60 body: body 61 }; 62 63 console.log({ title }, options); 64 65 // let notification = new Notification(title, options); 66 // notification.onclick = (e) => { 67 // e.preventDefault(); 68 // console.log("onclick", data); 69 70 // var result = ""; 71 // var characters = 72 // "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 73 // var charactersLength = characters.length; 74 // for (var i = 0; i < 64; i++) { 75 // result += characters.charAt( 76 // Math.floor(Math.random() * charactersLength) 77 // ); 78 // } 79 // result = btoa(`${result}-${data.room_id}`); 80 81 // window.open(`/?c=${result}`, "_blank"); 82 // notification.close(); 83 // }; 84 85 // Customize notification here 86 // let notification = payload.notification; 87 // const title = notification.title; 88 // const options = { 89 // body: notification.body, 90 // icon: "/firebase-logo.png" 91 // }; 92 93 // console.log(title, options); 94 95 self.registration.showNotification(title, options); 96 97 self.addEventListener("notificationclick", function (event) { 98 console.log("onclick", data); 99 100 var result = ""; 101 var characters = 102 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; 103 var charactersLength = characters.length; 104 for (var i = 0; i < 64; i++) { 105 result += characters.charAt( 106 Math.floor(Math.random() * charactersLength) 107 ); 108 } 109 result = btoa(`${result}-${data.room_id}`); 110 let url = `/qchat/?c=${result}`; 111 event.notification.close(); // Android needs explicit close. 112 event.waitUntil( 113 clients.matchAll({ type: "window" }).then(windowClients => { 114 // Check if there is already a window/tab open with the target URL 115 for (var i = 0; i < windowClients.length; i++) { 116 var client = windowClients[i]; 117 // If so, just focus it. 118 if (client.url === url && "focus" in client) { 119 return client.focus(); 120 } 121 } 122 // If not, then open the target URL in a new window/tab. 123 if (clients.openWindow) { 124 return clients.openWindow(url); 125 } 126 }) 127 ); 128 }); 129}); 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.