Add connection status component and improve socket reconnection handling
All checks were successful
Publish Docker image / Push Docker image to Docker Hub (push) Successful in 2m20s

This commit is contained in:
2025-05-14 20:10:46 +02:00
parent f2712bdcec
commit 301e08b6e6
9 changed files with 651 additions and 106 deletions

View File

@ -73,9 +73,9 @@ io.on('connection', (socket) => {
});
// Attempt to reconnect to a lobby
socket.on('reconnect_to_lobby', ({ lobbyId, playerName }, callback) => {
socket.on('reconnect_to_lobby', ({ lobbyId, playerName, lastKnownState }, callback) => {
try {
const result = gameManager.handleReconnect(socket.id, lobbyId, playerName);
const result = gameManager.handleReconnect(socket.id, lobbyId, playerName, lastKnownState);
if (result.error) {
if (callback) callback(result);
@ -337,7 +337,7 @@ io.on('connection', (socket) => {
}
});
// Handle disconnection
// Handle player disconnection
socket.on('disconnect', () => {
try {
const result = gameManager.handleDisconnect(socket.id);
@ -355,6 +355,13 @@ io.on('connection', (socket) => {
console.error('Error handling disconnect:', error);
}
});
// Simple ping handler to help with connection testing
socket.on('ping', (callback) => {
if (callback && typeof callback === 'function') {
callback({ success: true, timestamp: Date.now() });
}
});
});
server.on('error', (error) => {