Testing firebase messaging properties.
This commit is contained in:
@@ -27,36 +27,10 @@ firebase.initializeApp({
|
||||
|
||||
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];
|
||||
// console.log("[fbmsw] Posting Paylout to window client.");
|
||||
// windowClient.postMessage(payload);
|
||||
// }
|
||||
// })
|
||||
// .then(() => {
|
||||
// console.log("[fbmsw] Showing notification.");
|
||||
// return registration.showNotification(JSON.stringify(payload));
|
||||
// });
|
||||
// return promiseChain;
|
||||
// });
|
||||
|
||||
// messaging.onMessage((payload) => {
|
||||
// console.log("Message received. ", payload);
|
||||
// // ...
|
||||
// });
|
||||
|
||||
self.addEventListener('fetch',() => console.log("fetch"));
|
||||
self.addEventListener("fetch", () => console.log("fetch"));
|
||||
|
||||
messaging.setBackgroundMessageHandler(function (payload) {
|
||||
alert();
|
||||
console.log(
|
||||
"**********[firebase-messaging-sw.js] Received background message ",
|
||||
payload
|
||||
@@ -74,30 +48,15 @@ messaging.setBackgroundMessageHandler(function (payload) {
|
||||
);
|
||||
});
|
||||
|
||||
// self.addEventListener("message", (message) => {
|
||||
// const { payload } = message.data.firebaseMessaging;
|
||||
|
||||
// navigator.serviceWorker.getRegistration().then((registration) =>
|
||||
// registration.showNotification(payload.notification.title, {
|
||||
// body: payload.notification.body + "FROM SW",
|
||||
// icon: "logo240.png",
|
||||
// badge: "logo240.png",
|
||||
// actions: [
|
||||
// {
|
||||
// action: "respond",
|
||||
// title: "Respond",
|
||||
// },
|
||||
// ],
|
||||
// })
|
||||
// );
|
||||
// });
|
||||
|
||||
//Handles the notification getting clicked.
|
||||
self.addEventListener("notificationclick", function (event) {
|
||||
console.log("SW notificationclick", event);
|
||||
// event.notification.close();
|
||||
if (event.action === "archive") {
|
||||
// Archive action was clicked
|
||||
archiveEmail();
|
||||
} else {
|
||||
// Main body of notification was clicked
|
||||
clients.openWindow("/inbox");
|
||||
}
|
||||
});
|
||||
|
||||
// self.addEventListener("message", (message) => {
|
||||
// console.log("Push from SW", message);
|
||||
// // registration.showNotification("Push from SW" + JSON.stringify(message.data));
|
||||
// });
|
||||
|
||||
@@ -63,6 +63,12 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||
|
||||
messaging.onMessage((payload) => {
|
||||
console.log("**********UTILS Message received. ", payload);
|
||||
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||
return registration.showNotification(
|
||||
payload.notification.title + "from utils",
|
||||
payload.notification
|
||||
);
|
||||
});
|
||||
// [START_EXCLUDE]
|
||||
// Update the UI to include the received message.
|
||||
//appendMessage(payload);
|
||||
|
||||
Reference in New Issue
Block a user