fix(socket): improve connection stability with heartbeat and auto-reconnect

- Backend: Add pingInterval (25s) and pingTimeout (60s) for better keep-alive
- Frontend: Increase reconnection attempts to Infinity (keep trying forever)
- Frontend: Add reconnect event handlers to rejoin rooms after reconnection
- Frontend: Check initial connection state when reusing socket instance
This commit is contained in:
Radosław Gierwiało
2025-11-21 21:53:51 +01:00
parent 78280ca8d8
commit 8a369c1fc4
4 changed files with 60 additions and 9 deletions

View File

@@ -26,9 +26,17 @@ export function connectSocket() {
auth: {
token,
},
// Reconnection settings
reconnection: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000,
reconnectionAttempts: Infinity, // Keep trying forever
reconnectionDelay: 1000, // Start with 1 second delay
reconnectionDelayMax: 5000, // Max 5 seconds between attempts
randomizationFactor: 0.5, // Add some randomness to prevent thundering herd
// Timeout settings
timeout: 20000, // 20 seconds connection timeout
// Transport settings - prefer websocket but start with polling for reliability
transports: ['polling', 'websocket'],
upgrade: true,
});
socket.on('connect', () => {