socket.on('new-notification', function(data) {
let room_id = data.room_id;
var receiver_id = data.receiver_id;
var booking_request_id = data.booking_request_id;
var message = {
to: notification_payload,
collapse_key: 'green',
notification: {
title: 'Tittle',
body: "New message from User",
icon: site_url + 'assets/icons/icon- 72x72.png',
sound: 'default',
url: redirect_url,
},
data: {
title: 'Tittle',
body: "New message from User",
icon: site_url + 'assets/icons/icon- 72x72.png',
sound: 'default',
url: redirect_url,
}
};
fcm.send(message, function(err, response) {
if (err) {
console.log("Something has gone wrong!");
} else {
console.log("Successfully sent with response: ", response);
}
});
}
});
}
else {
}
}
});
});
我有一个 Angular PWA,它使用 Socket.io Node 和 express 服务器进行实时消息传递,并使用 Firebase Cloud Messaging 推送通知。消息传递工作正常,但问题是当用户离开应用程序时,他们将无法接收通知,而只能在积极使用应用程序时接收。我的假设是当用户离开应用程序时 Socket io 正在断开连接。那么即使应用程序在后台运行,有什么方法可以确保套接字保持活动状态。我附上了我的通知片段。对你的帮助表示感谢