socketIO fix

This commit is contained in:
2025-05-27 15:29:31 +02:00
parent 5bb37da909
commit c2c03efe9e
5 changed files with 48 additions and 18 deletions

View File

@@ -399,11 +399,14 @@ if (typeof window.ChatManager === 'undefined') {
// Create socket instance
socket = io({
transports: ['websocket'],
upgrade: false,
reconnection: false,
debug: true,
forceNew: false,
transports: ['websocket', 'polling'], // Allow fallback to polling
upgrade: true, // Enable transport upgrade
reconnection: true, // Enable reconnection
reconnectionAttempts: 5, // Number of reconnection attempts
reconnectionDelay: 1000, // Delay between reconnection attempts
timeout: 20000, // Connection timeout
debug: false, // Disable debug in production
forceNew: true, // Force new connection
multiplex: false
});
@@ -419,20 +422,37 @@ if (typeof window.ChatManager === 'undefined') {
});
});
socket.on('disconnect', function(reason) {
console.log('Disconnected from conversation:', {
reason: reason,
socketId: socket.id,
connectionState: state.connectionState
});
socket.on('connect_error', function(error) {
console.error('Socket connection error:', error);
state.connectionState.isConnected = false;
state.connectionState.hasJoined = false;
state.connectionState.socketId = null;
});
socket.on('error', function(error) {
console.error('Socket error:', error);
cleanup();
socket.on('reconnect_attempt', function(attemptNumber) {
console.log('Attempting to reconnect:', attemptNumber);
});
socket.on('reconnect', function(attemptNumber) {
console.log('Reconnected after', attemptNumber, 'attempts');
state.connectionState.isConnected = true;
// Rejoin the conversation room after reconnection
if (!state.connectionState.hasJoined) {
socket.emit('join_conversation', {
conversation_id: conversationId,
timestamp: new Date().toISOString(),
socketId: socket.id
});
state.connectionState.hasJoined = true;
}
});
socket.on('reconnect_error', function(error) {
console.error('Reconnection error:', error);
});
socket.on('reconnect_failed', function() {
console.error('Failed to reconnect');
alert('Connection lost. Please refresh the page.');
});
instance = {