fixed stuff, Null mainly
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user