61 lines
1.9 KiB
JavaScript
61 lines
1.9 KiB
JavaScript
importScripts("https://www.gstatic.com/firebasejs/7.14.2/firebase-app.js");
|
|
importScripts(
|
|
"https://www.gstatic.com/firebasejs/7.14.2/firebase-messaging.js"
|
|
);
|
|
|
|
// firebase.initializeApp({
|
|
// apiKey: "AIzaSyDSezy-jGJreo7ulgpLdlpOwAOrgcaEkhU",
|
|
// authDomain: "imex-prod.firebaseapp.com",
|
|
// databaseURL: "https://imex-prod.firebaseio.com",
|
|
// projectId: "imex-prod",
|
|
// storageBucket: "imex-prod.appspot.com",
|
|
// messagingSenderId: "253497221485",
|
|
// appId: "1:253497221485:web:3c81c483b94db84b227a64",
|
|
// measurementId: "G-NTWBKG2L0M",
|
|
// });
|
|
|
|
firebase.initializeApp({
|
|
apiKey: "AIzaSyDPLT8GiDHDR1R4nI66Qi0BY1aYviDPioc",
|
|
authDomain: "imex-dev.firebaseapp.com",
|
|
databaseURL: "https://imex-dev.firebaseio.com",
|
|
projectId: "imex-dev",
|
|
storageBucket: "imex-dev.appspot.com",
|
|
messagingSenderId: "759548147434",
|
|
appId: "1:759548147434:web:e8239868a48ceb36700993",
|
|
measurementId: "G-K5XRBVVB4S",
|
|
});
|
|
|
|
const messaging = firebase.messaging();
|
|
|
|
//Handles Background Messages
|
|
messaging.setBackgroundMessageHandler(function (payload) {
|
|
console.log("backgroundMessageHandler", payload);
|
|
const promiseChain = clients
|
|
.matchAll({
|
|
type: "window",
|
|
includeUncontrolled: true,
|
|
})
|
|
.then((windowClients) => {
|
|
for (let i = 0; i < windowClients.length; i++) {
|
|
const windowClient = windowClients[i];
|
|
windowClient.postMessage(payload);
|
|
}
|
|
})
|
|
.then(() => {
|
|
return registration.showNotification(JSON.stringify(payload));
|
|
});
|
|
return promiseChain;
|
|
});
|
|
|
|
//Handles the notification getting clicked.
|
|
self.addEventListener("notificationclick", function (event) {
|
|
// do what you want
|
|
// ...
|
|
console.log("SW notificationclick", event);
|
|
});
|
|
|
|
// self.addEventListener("message", (message) => {
|
|
// console.log("Push from SW", message);
|
|
// // registration.showNotification("Push from SW" + JSON.stringify(message.data));
|
|
// });
|