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

@@ -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