admin管理员组文章数量:1386760
I am working on application in which notification delivery is too important, not only the delivery but also about the status of it, like it is received by the end user or not?
I do have some in my mind to do it with FCM and websockets, like i will send a notification with FCM and when the front end (Mobile App) will receive it, it will emit an event to tell us it is received, but i think it is not the most reliable way, it does not provide 100% or near 100% accuracy.
I want to ask if any one have some in mind, please let me know, really appreciated!
I am working on application in which notification delivery is too important, not only the delivery but also about the status of it, like it is received by the end user or not?
I do have some in my mind to do it with FCM and websockets, like i will send a notification with FCM and when the front end (Mobile App) will receive it, it will emit an event to tell us it is received, but i think it is not the most reliable way, it does not provide 100% or near 100% accuracy.
I want to ask if any one have some in mind, please let me know, really appreciated!
Share Improve this question asked Mar 17 at 8:01 Faraz AliFaraz Ali 931 silver badge6 bronze badges 1- Have you ever seen a "mark as read" button/link on a notification? That's the only way to guarantee that the user saw (or at least acknowledged) the notification. – Frank van Puffelen Commented Mar 17 at 11:59
1 Answer
Reset to default 1use acknowledged functionality from socket.io, where callback event emits: Acknowledgement
socket.on("sendNotification", async (data, callback) => {
try {
// Sending the notification logic
callback({ status: "ok" }); // Notification acknowledged
} catch (error) {
callback({ status: "error", error: error.message });
}
});
//logic on server
const sendWithRetry = (notification, retries = 3) => {
let attempts = 0;
const send = () => {
attempts++;
socket.emit("sendNotification", notification, (response) => {
if (response.status === "ok" || attempts >= retries) {
console.log("Notification handled:", response);
} else {
setTimeout(send, 1000);
}
});
};
send();
};
本文标签:
版权声明:本文标题:node.js - How to ensure the notification delivery and know if the notification was recieved by the end user? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744574219a2613524.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论