socketio / socket.io-client-swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement Connection State Recovery

ricardopereira opened this issue · comments

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: socketio/socket.io@54d5ee0

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.