socketIO fix
This commit is contained in:
Binary file not shown.
@@ -52,4 +52,4 @@ init_admin()
|
|||||||
|
|
||||||
# Start the application
|
# Start the application
|
||||||
echo "Starting application..."
|
echo "Starting application..."
|
||||||
exec gunicorn --bind 0.0.0.0:5000 app:app
|
exec gunicorn --worker-class eventlet -w 1 --bind 0.0.0.0:5000 app:app
|
||||||
@@ -7,4 +7,11 @@ from flask_wtf.csrf import CSRFProtect
|
|||||||
db = SQLAlchemy()
|
db = SQLAlchemy()
|
||||||
login_manager = LoginManager()
|
login_manager = LoginManager()
|
||||||
csrf = CSRFProtect()
|
csrf = CSRFProtect()
|
||||||
socketio = SocketIO(cors_allowed_origins="*")
|
socketio = SocketIO(
|
||||||
|
cors_allowed_origins="*",
|
||||||
|
async_mode='threading',
|
||||||
|
logger=True,
|
||||||
|
engineio_logger=True,
|
||||||
|
ping_timeout=60,
|
||||||
|
ping_interval=25
|
||||||
|
)
|
||||||
@@ -10,4 +10,7 @@ python-dotenv==1.0.1
|
|||||||
psycopg2-binary==2.9.9
|
psycopg2-binary==2.9.9
|
||||||
gunicorn==21.2.0
|
gunicorn==21.2.0
|
||||||
Flask-SocketIO==5.3.6
|
Flask-SocketIO==5.3.6
|
||||||
|
python-socketio==5.10.0
|
||||||
|
python-engineio==4.8.0
|
||||||
email_validator==2.1.0.post1
|
email_validator==2.1.0.post1
|
||||||
|
simple-websocket==1.0.0
|
||||||
@@ -399,11 +399,14 @@ if (typeof window.ChatManager === 'undefined') {
|
|||||||
|
|
||||||
// Create socket instance
|
// Create socket instance
|
||||||
socket = io({
|
socket = io({
|
||||||
transports: ['websocket'],
|
transports: ['websocket', 'polling'], // Allow fallback to polling
|
||||||
upgrade: false,
|
upgrade: true, // Enable transport upgrade
|
||||||
reconnection: false,
|
reconnection: true, // Enable reconnection
|
||||||
debug: true,
|
reconnectionAttempts: 5, // Number of reconnection attempts
|
||||||
forceNew: false,
|
reconnectionDelay: 1000, // Delay between reconnection attempts
|
||||||
|
timeout: 20000, // Connection timeout
|
||||||
|
debug: false, // Disable debug in production
|
||||||
|
forceNew: true, // Force new connection
|
||||||
multiplex: false
|
multiplex: false
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -419,20 +422,37 @@ if (typeof window.ChatManager === 'undefined') {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('disconnect', function(reason) {
|
socket.on('connect_error', function(error) {
|
||||||
console.log('Disconnected from conversation:', {
|
console.error('Socket connection error:', error);
|
||||||
reason: reason,
|
|
||||||
socketId: socket.id,
|
|
||||||
connectionState: state.connectionState
|
|
||||||
});
|
|
||||||
state.connectionState.isConnected = false;
|
state.connectionState.isConnected = false;
|
||||||
state.connectionState.hasJoined = false;
|
state.connectionState.hasJoined = false;
|
||||||
state.connectionState.socketId = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('error', function(error) {
|
socket.on('reconnect_attempt', function(attemptNumber) {
|
||||||
console.error('Socket error:', error);
|
console.log('Attempting to reconnect:', attemptNumber);
|
||||||
cleanup();
|
});
|
||||||
|
|
||||||
|
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 = {
|
instance = {
|
||||||
|
|||||||
Reference in New Issue
Block a user