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