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:
@@ -21,6 +21,12 @@ function initializeSocket(httpServer) {
|
||||
origin: process.env.CORS_ORIGIN || 'http://localhost:8080',
|
||||
credentials: true,
|
||||
},
|
||||
// Ping/pong heartbeat configuration
|
||||
pingInterval: 25000, // Send ping every 25 seconds
|
||||
pingTimeout: 60000, // Wait 60 seconds for pong before considering disconnected
|
||||
// Allow upgrade from polling to websocket
|
||||
transports: ['polling', 'websocket'],
|
||||
allowUpgrades: true,
|
||||
});
|
||||
|
||||
// Authentication middleware for Socket.IO
|
||||
|
||||
Reference in New Issue
Block a user