Roadmap for v3
Problem
This list is open to suggestions! - [ ] Improve the documentation That is obviously the major pain point of the project. - [x] Reverse the direction of the ping-pong mechanism Currently the client emits a `ping` and waits for a `pong` from the server, relying on `setTimeout()` to check whether the connection is still alive or not. But there are reports of throttled timers on the browser side, which may trigger random disconnections. A solution would be that the `ping` is emitted from the server to the client, but that is a breaking change which will also break other client implementations.. Related: https://github.com/socketio/socket.io/issues/5082 - [x] Update the source code to ES6 in every project - [x] Migrate to webpack 4 (or another bundler, if need be) - [ ] Remove the sticky-session requirement when using multiple nodes - [ ] Default to websocket, and use XHR polling as fallback Currently polling is established first, and then upgraded to websocket if possible. - [x] Make the `generateId` method asynchronous This one is also a breaking change. Related: https://github.com/socketio/engine.io/pull/535 - [ ] Update the Typescript bindings, if need be - [ ] Triage issues No release date for now, as I'm not sure how much time I will be able to dedicate to those points in the following weeks. But any help is welcome!
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Enhance Socket.io Connection Stability and Documentation
The current implementation relies on a client-initiated ping-pong mechanism, which can lead to unreliable connection checks due to browser throttling of timers. Additionally, the documentation lacks clarity, making it difficult for users to understand the setup and usage of the library.
Awaiting Verification
Be the first to verify this fix
- 1
Implement Server-Initiated Ping
Change the ping mechanism to be server-initiated to improve connection reliability. This will require updating the client to listen for pings from the server and respond accordingly. Note that this is a breaking change and will require updates to client implementations.
javascriptsocket.on('ping', () => { socket.emit('pong'); }); - 2
Remove Sticky-Session Requirement
Refactor the session management to eliminate the need for sticky sessions when using multiple nodes. This can be achieved by implementing a shared session store or using a distributed cache mechanism.
javascript// Example of using Redis for session storage const sessionStore = new RedisStore(); app.use(session({ store: sessionStore })); - 3
Default to WebSocket for Connections
Modify the connection logic to default to WebSocket instead of XHR polling. This change will enhance performance and reduce latency. Ensure that fallback mechanisms are in place for environments where WebSocket is not supported.
javascriptconst socket = io({ transports: ['websocket', 'polling'] }); - 4
Update Documentation
Revise the existing documentation to provide clear instructions on the new connection mechanisms, breaking changes, and examples of usage. This should include a dedicated section for migration from previous versions.
markdown// Example documentation snippet ## Migration to v3 - Change client ping mechanism to listen for server pings. - Update session management to remove sticky-session requirement. - 5
Update TypeScript Bindings
Review and update the TypeScript bindings to ensure compatibility with the latest changes, especially regarding the asynchronous `generateId` method and the new connection defaults.
typescript// Example TypeScript type update export type GenerateId = () => Promise<string>;
Validation
To confirm the fix worked, test the connection stability by simulating network conditions and observing the behavior of the ping-pong mechanism. Additionally, review the updated documentation for clarity and completeness. Ensure that all client implementations are updated and functioning correctly with the new server-initiated pings.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep