socketio / socket.io-client-java

Full-featured Socket.IO Client Library for Java, which is compatible with Socket.IO v1.0 and later.
https://socketio.github.io/socket.io-client-java/installation.html
Other
5.31k stars 969 forks source link

Implement Connection State Recovery #763

Open ricardopereira opened 5 months ago

ricardopereira commented 5 months ago

Is your feature request related to a problem? Please describe. Yes, the problem arises when mobile applications experience temporary network disconnections. Currently, the library doesn't support the connection state recovery feature that was introduced in the Socket.io JavaScript library version. This leads to a loss of vital connection state, which can degrade the user experience in mobile apps that rely on real-time communications.

Describe the solution you'd like I suggest implementing the connection state recovery feature that is present in the JavaScript library. This feature allows a client to reconnect after a temporary disconnection and seamlessly restore its previous state, including id, rooms, data, and missed packets. Reference: https://github.com/socketio/socket.io/commit/54d5ee05a684371191e207b8089f09fc24eb5107

Describe alternatives you've considered In the absence of this feature, we've considered developing custom mechanisms to handle reconnection and state restoration, but this requires significant effort and is not as reliable or standardized as having the functionality built directly into the library.

Additional context This feature is already implemented in the JavaScript version of the library. Here's an example of how the feature is used in JavaScript:

import { Server } from "socket.io";

const io = new Server({
  connectionStateRecovery: {
    // default values
    maxDisconnectionDuration: 2 * 60 * 1000,
    skipMiddlewares: true,
  },
});

io.on("connection", (socket) => {
  console.log(socket.recovered); // whether the state was recovered or not
});

Having this feature in the mobile libraries would align them with the web version and provide a consistent and reliable user experience across all platforms.