[RFC] Reconnection #4510
-
Currently, a message that is broadcast while the client is disconnected is lost for that particular client. Idea 💡 : handle the reconnection of that client, and send the messages that were broadcast during its disconnection (up to a given delay) Suggested APIHere is how it could work: Server io.on("connection", (socket) => {
// socket.reconnection = true;
// socket.id, socket.rooms and socket.data are restored
}); Client socket.on("connect", () => {
// socket.reconnection = true;
});
socket.on("<event>", () => {
// receive all events that were sent during the disconnection
}); Suggested implementationHow it could be implemented:
Questions
It could be interesting to include it in the core because some adapters (like the one based on MongoDB) already store the messages temporarily, so in that case it is quite easy to implement. Compatibility with existing adapters:
We only add a few fields (the private session ID in the What do you think? Update: this feature was implemented in version 4.6.0: https://socket.io/docs/v4/connection-state-recovery |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I like the reconnection idea. It doesn't just apply for broadcast but to one-on-one connection too. Someone answered it yesterday suggesting using room to handle it, which brings me to this discussion to see if socket.io comes up with any new idea. And I saw this, what a coincidence! |
Beta Was this translation helpful? Give feedback.
-
I wouldn't count on messages previously sent to linger around in case someone reconnects... rather on connection I'd send the whole current state as if it was a new connection rather than a reconnection; which should include whatever change the missed message would have had..... |
Beta Was this translation helpful? Give feedback.
-
For future readers: This feature was implemented in version 4.6.0: https://socket.io/docs/v4/connection-state-recovery |
Beta Was this translation helpful? Give feedback.
For future readers:
This feature was implemented in version 4.6.0: https://socket.io/docs/v4/connection-state-recovery