fixed stuff, Null mainly

This commit is contained in:
2025-08-31 22:48:53 +02:00
parent 14da03f8d3
commit 55e322434f

View File

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