I’m developing a chat web application using WebSocket and have encountered the issue of unreliable WebSocket connections. To improve reliability, I’m using heartbeat messages to ensure both the client and server are alive. I also implemented receipt messages from the server to the client to confirm that messages are received successfully.
The last feature that I would like to implement is saving messages locally on the client if they are not delivered to the server, allowing the user to resend them once the connection is restored. I’ve seen something similar in WhatsApp.
Could you provide advice or best practices for implementing this feature?
What I expected to happen:
If a message fails to be delivered, it would be saved locally on the client, the user would be notified of the delivery failure, and the user would be allowed to resend the message once the connection is restored. This is similar to the behavior seen in WhatsApp.