Testing firebase messaging properties.
This commit is contained in:
@@ -27,36 +27,10 @@ firebase.initializeApp({
|
|||||||
|
|
||||||
const messaging = firebase.messaging();
|
const messaging = firebase.messaging();
|
||||||
|
|
||||||
//Handles Background Messages
|
self.addEventListener("fetch", () => console.log("fetch"));
|
||||||
// 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"));
|
|
||||||
|
|
||||||
messaging.setBackgroundMessageHandler(function (payload) {
|
messaging.setBackgroundMessageHandler(function (payload) {
|
||||||
|
alert();
|
||||||
console.log(
|
console.log(
|
||||||
"**********[firebase-messaging-sw.js] Received background message ",
|
"**********[firebase-messaging-sw.js] Received background message ",
|
||||||
payload
|
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.
|
//Handles the notification getting clicked.
|
||||||
self.addEventListener("notificationclick", function (event) {
|
self.addEventListener("notificationclick", function (event) {
|
||||||
console.log("SW notificationclick", 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) => {
|
messaging.onMessage((payload) => {
|
||||||
console.log("**********UTILS Message received. ", payload);
|
console.log("**********UTILS Message received. ", payload);
|
||||||
|
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||||
|
return registration.showNotification(
|
||||||
|
payload.notification.title + "from utils",
|
||||||
|
payload.notification
|
||||||
|
);
|
||||||
|
});
|
||||||
// [START_EXCLUDE]
|
// [START_EXCLUDE]
|
||||||
// Update the UI to include the received message.
|
// Update the UI to include the received message.
|
||||||
//appendMessage(payload);
|
//appendMessage(payload);
|
||||||
|
|||||||
@@ -35,10 +35,8 @@ app.post("/sendemail", sendEmail.sendEmail);
|
|||||||
app.get("/test", async function (req, res) {
|
app.get("/test", async function (req, res) {
|
||||||
res.status(200).send("OK");
|
res.status(200).send("OK");
|
||||||
});
|
});
|
||||||
|
const test = require("./server/_test/test.js");
|
||||||
app.post("/test", async function (req, res) {
|
app.post("/test", test.testResponse);
|
||||||
res.status(200).send("OK");
|
|
||||||
});
|
|
||||||
|
|
||||||
//Accounting-IIF
|
//Accounting-IIF
|
||||||
const accountingIIF = require("./server/accounting/iif/iif");
|
const accountingIIF = require("./server/accounting/iif/iif");
|
||||||
|
|||||||
72
server/_test/test.js
Normal file
72
server/_test/test.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const admin = require("../firebase/firebase-handler").admin;
|
||||||
|
|
||||||
|
require("dotenv").config({
|
||||||
|
path: path.resolve(
|
||||||
|
process.cwd(),
|
||||||
|
`.env.${process.env.NODE_ENV || "development"}`
|
||||||
|
),
|
||||||
|
});
|
||||||
|
|
||||||
|
exports.testResponse = async (req, res) => {
|
||||||
|
console.log("Test");
|
||||||
|
|
||||||
|
const uniqueTokens = [
|
||||||
|
"f7B-k-ceDNCEAIFYCfhF3M:APA91bEn-xOmUahCBMJBBDqXpVOZJnnb_qhWlo8eOPrIkvFeSc2nqaKd4D8zs3qqZ_VNgS_OhifsetJXcwtczO8N4k3xfDzCyI3i6j6YTUNK56QC-WNmVOLR2C_g-owy7hSvhGhWilZ3",
|
||||||
|
"eNdzsUqRBBZCM8LQKvqk6e:APA91bFgL0VQLf_TooYmHKQ7_b4H--ZmUYCdgiZpT7dxHSyEkpcCHUz33K7sKqgifUk8rMAEhSsHWa0TJgLbOJxWD6lJaGEpXn8G3PbunkJsJCNCA3CprMONylBr9d6hnQ5wnjUX2Gt6",
|
||||||
|
];
|
||||||
|
|
||||||
|
var message = {
|
||||||
|
notification: {
|
||||||
|
title: "Test Notification",
|
||||||
|
body: "Test Body",
|
||||||
|
//click_action: "TEST CLICK ACTION",
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
jobid: "1234",
|
||||||
|
title: "Test Notification",
|
||||||
|
body: "Test Body",
|
||||||
|
},
|
||||||
|
tokens: uniqueTokens,
|
||||||
|
android: {
|
||||||
|
notification: {
|
||||||
|
body: "This is an FCM notification specifically for android.",
|
||||||
|
title: "FCM Notification for Android",
|
||||||
|
//image: "url-to-image",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
webpush: {
|
||||||
|
headers: {
|
||||||
|
// Urgency: "high",
|
||||||
|
},
|
||||||
|
notification: {
|
||||||
|
body: "This is a message from FCM to web",
|
||||||
|
// requireInteraction: "true",
|
||||||
|
// actions: [{ action: "the action - matched in sw", title: "title" }],
|
||||||
|
|
||||||
|
// renotify: true,
|
||||||
|
//tag: "1234",
|
||||||
|
//badge: "/badge-icon.png",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Send a message to the device corresponding to the provided
|
||||||
|
// registration token.
|
||||||
|
admin
|
||||||
|
.messaging()
|
||||||
|
.sendMulticast(message)
|
||||||
|
.then((response) => {
|
||||||
|
// Response is a message ID string.
|
||||||
|
console.log(
|
||||||
|
"[TEST] Successfully sent FCM Broadcast.:",
|
||||||
|
response
|
||||||
|
//JSON.stringify(response)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.log("Error sending message:", error);
|
||||||
|
});
|
||||||
|
|
||||||
|
res.status(200).send("OK");
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user