Update conversation.html
This commit is contained in:
@@ -403,7 +403,7 @@ if (typeof window.ChatManager === 'undefined') {
|
||||
// Create socket instance
|
||||
socket = io(window.location.origin, {
|
||||
path: '/socket.io/',
|
||||
transports: ['websocket', 'polling'],
|
||||
transports: ['polling', 'websocket'],
|
||||
upgrade: true,
|
||||
reconnection: true,
|
||||
reconnectionAttempts: Infinity,
|
||||
@@ -417,7 +417,10 @@ if (typeof window.ChatManager === 'undefined') {
|
||||
pingInterval: 25000,
|
||||
upgradeTimeout: 10000,
|
||||
rememberUpgrade: true,
|
||||
rejectUnauthorized: false
|
||||
rejectUnauthorized: false,
|
||||
extraHeaders: {
|
||||
'X-Forwarded-Proto': 'https'
|
||||
}
|
||||
});
|
||||
|
||||
// Set up socket event handlers
|
||||
@@ -428,7 +431,8 @@ if (typeof window.ChatManager === 'undefined') {
|
||||
console.log('Socket connected:', {
|
||||
attempt: state.connectionState.connectionAttempts,
|
||||
socketId: socket.id,
|
||||
existingSocketId: state.connectionState.socketId
|
||||
existingSocketId: state.connectionState.socketId,
|
||||
transport: socket.io.engine.transport.name
|
||||
});
|
||||
|
||||
// Always rejoin the room on connect
|
||||
@@ -445,15 +449,20 @@ if (typeof window.ChatManager === 'undefined') {
|
||||
console.log('Disconnected from conversation:', {
|
||||
reason: reason,
|
||||
socketId: socket.id,
|
||||
connectionState: state.connectionState
|
||||
connectionState: state.connectionState,
|
||||
transport: socket.io.engine?.transport?.name
|
||||
});
|
||||
state.connectionState.isConnected = false;
|
||||
state.connectionState.socketId = null;
|
||||
// Don't set hasJoined to false to maintain room membership
|
||||
});
|
||||
|
||||
socket.on('connect_error', function(error) {
|
||||
console.error('Connection error:', error);
|
||||
// Try to reconnect with polling if websocket fails
|
||||
if (socket.io.engine?.transport?.name === 'websocket') {
|
||||
console.log('WebSocket failed, falling back to polling');
|
||||
socket.io.opts.transports = ['polling'];
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('error', function(error) {
|
||||
@@ -465,11 +474,23 @@ if (typeof window.ChatManager === 'undefined') {
|
||||
if (socket.connected) {
|
||||
socket.emit('heartbeat', {
|
||||
timestamp: new Date().toISOString(),
|
||||
socketId: socket.id
|
||||
socketId: socket.id,
|
||||
transport: socket.io.engine.transport.name
|
||||
});
|
||||
}
|
||||
}, 15000);
|
||||
|
||||
// Handle transport upgrade
|
||||
socket.io.engine.on('upgrade', function() {
|
||||
console.log('Transport upgraded to:', socket.io.engine.transport.name);
|
||||
});
|
||||
|
||||
socket.io.engine.on('upgradeError', function(err) {
|
||||
console.error('Transport upgrade error:', err);
|
||||
// Fall back to polling
|
||||
socket.io.opts.transports = ['polling'];
|
||||
});
|
||||
|
||||
instance = {
|
||||
socket: socket,
|
||||
state: state,
|
||||
|
||||
Reference in New Issue
Block a user