lundi 31 août 2020

How could a client know if new messages are there for it for a web based chat app?

I am developing a chat app using NodeJS as backend and using MongoDB. I had designed the database for storing messages between every clients. But just then, I have no idea how the client could be notified of new messages.

If a client logs in, the client can send an API request to get the most recent messages. But if the client stays logged in, and new messages are delivered that are meant for this client, the server records them in the database but cannot notify it until it requests for it(either by reloading the page or some other way). How could this be accomplished?

I was thinking of constantly polling the server for new messages, but wouldn't that be a lot of requests? I hope there could be some better ways to implement this. I'm relatively new to web development and this is my first project.




Aucun commentaire:

Enregistrer un commentaire