Moved firebase messaging notification handling to messaging generation.
This commit is contained in:
@@ -48,9 +48,18 @@ if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register("/firebase-messaging-sw.js")
|
||||
.then(function (registration) {
|
||||
console.log("**********FCM Registration successful, scope is:", registration.scope);
|
||||
console.log(
|
||||
"**********FCM Registration successful, scope is:",
|
||||
registration.scope
|
||||
);
|
||||
navigator.serviceWorker.addEventListener("message", (event) => {
|
||||
console.log("Handler for Navigator Service Worker.", event);
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.log("**********FCM Service worker registration failed, error:", err);
|
||||
console.log(
|
||||
"**********FCM Service worker registration failed, error:",
|
||||
err
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -61,14 +61,30 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||
analytics.logEvent(eventName, eventParams);
|
||||
};
|
||||
|
||||
messaging.onMessage((payload) => {
|
||||
messaging.onMessage(async (payload) => {
|
||||
console.log("**********UTILS Message received. ", payload);
|
||||
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||
return registration.showNotification(
|
||||
payload.notification.title + "from utils",
|
||||
"[UTIL]" + payload.notification.title,
|
||||
payload.notification
|
||||
);
|
||||
});
|
||||
|
||||
// if (!payload.clientId) return;
|
||||
|
||||
// // Get the client.
|
||||
// const client = await clients.get(payload.clientId);
|
||||
// // Exit early if we don't get the client.
|
||||
// // Eg, if it closed.
|
||||
// if (!client) return;
|
||||
|
||||
// // Send a message to the client.
|
||||
// console.log("Posting to client.");
|
||||
// client.postMessage({
|
||||
// msg: "Hey I just got a fetch from you!",
|
||||
// url: payload.request.url,
|
||||
// });
|
||||
|
||||
// [START_EXCLUDE]
|
||||
// Update the UI to include the received message.
|
||||
//appendMessage(payload);
|
||||
|
||||
Reference in New Issue
Block a user