From 55e322434f2ece911cbb74528a4ef1a33d3ef868 Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Sun, 31 Aug 2025 22:48:53 +0200 Subject: [PATCH] fixed stuff, Null mainly --- src/static/rooms.js | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/static/rooms.js b/src/static/rooms.js index acf830b..6465c02 100644 --- a/src/static/rooms.js +++ b/src/static/rooms.js @@ -320,19 +320,30 @@ function setupPublicRoomsWebSocketHandlers() { } // Auto-setup WebSocket handlers when page loads -function waitForSocketAndSetupHandlers() { - if (typeof socket !== 'undefined' && socket !== null && socket.connected) { +function waitForSocketAndSetupHandlers(retryCount = 0) { + // Check if socket is properly initialized and connected + if (typeof socket !== 'undefined' && socket !== null && typeof socket.connected !== 'undefined' && socket.connected) { setupPublicRoomsWebSocketHandlers(); - } else { - // Check if socket exists but is still connecting - if (typeof socket !== 'undefined' && socket !== null) { - // Socket exists but might not be connected yet - setTimeout(waitForSocketAndSetupHandlers, 100); - } else { - // Socket doesn't exist yet, keep waiting - setTimeout(waitForSocketAndSetupHandlers, 250); - } + console.log('WebSocket handlers setup successfully'); + return; } + + // If we've retried too many times, give up and use HTTP only + if (retryCount > 100) { // 100 * 250ms = 25 seconds max wait + console.warn('Socket failed to initialize after 25 seconds, falling back to HTTP-only mode'); + return; + } + + // Log current socket state for debugging + if (retryCount % 20 === 0) { // Log every 5 seconds + console.log(`Waiting for socket... (attempt ${retryCount + 1})`); + console.log('Socket type:', typeof socket); + console.log('Socket value:', socket); + console.log('Socket.io library loaded:', typeof io !== 'undefined'); + } + + // Continue waiting + setTimeout(() => waitForSocketAndSetupHandlers(retryCount + 1), 250); } // Event listeners for controls