IO-1551 Refactor messaging.
This commit is contained in:
@@ -2,8 +2,7 @@ import { getAnalytics, logEvent } from "firebase/analytics";
|
||||
import { initializeApp } from "firebase/app";
|
||||
import { getAuth, updatePassword, updateProfile } from "firebase/auth";
|
||||
import { getFirestore } from "firebase/firestore";
|
||||
import { tracker } from "../App/App.container";
|
||||
//import { getMessaging } from "firebase/messaging";
|
||||
import { getMessaging, getToken, onMessage } from "firebase/messaging";
|
||||
import { store } from "../redux/store";
|
||||
|
||||
const config = JSON.parse(process.env.REACT_APP_FIREBASE_CONFIG);
|
||||
@@ -40,17 +39,34 @@ export const updateCurrentPassword = async (password) => {
|
||||
return updatePassword(currentUser, password);
|
||||
};
|
||||
|
||||
//let messaging;
|
||||
// try {
|
||||
// messaging = getMessaging();
|
||||
// // Project Settings => Cloud Messaging => Web Push certificates
|
||||
// messaging.usePublicVapidKey(process.env.REACT_APP_FIREBASE_PUBLIC_VAPID_KEY);
|
||||
// console.log("[FCM UTIL] FCM initialized successfully.");
|
||||
// } catch {
|
||||
// console.log("[FCM UTIL] Firebase Messaging is likely unsupported.");
|
||||
// }
|
||||
export const messaging = getMessaging();
|
||||
|
||||
// export { messaging };
|
||||
export const requestForToken = () => {
|
||||
return getToken(messaging, {
|
||||
vapidKey: process.env.REACT_APP_FIREBASE_PUBLIC_VAPID_KEY,
|
||||
})
|
||||
.then((currentToken) => {
|
||||
if (currentToken) {
|
||||
console.log("current token for client: ", currentToken);
|
||||
// Perform any other necessary action with the token
|
||||
} else {
|
||||
// Show permission request UI
|
||||
console.log(
|
||||
"No registration token available. Request permission to generate one."
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log("An error occurred while retrieving token. ", err);
|
||||
});
|
||||
};
|
||||
export const onMessageListener = () =>
|
||||
new Promise((resolve) => {
|
||||
onMessage(messaging, (payload) => {
|
||||
console.log("Inbound FCM Message", payload);
|
||||
resolve(payload);
|
||||
});
|
||||
});
|
||||
|
||||
export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||
const state = stateProp || store.getState();
|
||||
@@ -70,9 +86,6 @@ export const logImEXEvent = (eventName, additionalParams, stateProp = null) => {
|
||||
// eventParams
|
||||
// );
|
||||
logEvent(analytics, eventName, eventParams);
|
||||
|
||||
//Log event to OpenReplay server.
|
||||
tracker.event(eventName, eventParams);
|
||||
};
|
||||
|
||||
// if (messaging) {
|
||||
|
||||
Reference in New Issue
Block a user