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:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user