diff --git a/app.py b/app.py index 8667bd3..8cd3c46 100644 --- a/app.py +++ b/app.py @@ -17,7 +17,16 @@ from datetime import datetime import sys app = Flask(__name__) -socketio = SocketIO(app, cors_allowed_origins="*", ping_timeout=30, ping_interval=5, max_http_buffer_size=50 * 1024 * 1024) +socketio = SocketIO( + app, + cors_allowed_origins="*", + ping_timeout=30, + ping_interval=5, + max_http_buffer_size=50 * 1024 * 1024, + async_mode='threading', # 使用threading模式提高兼容性 + engineio_logger=True, # 启用引擎日志,便于调试 + logger=True # 启用Socket.IO日志 +) # 添加配置文件路径 CONFIG_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config') diff --git a/static/js/main.js b/static/js/main.js index 917b240..a821e2a 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -117,18 +117,30 @@ class SnapSolver { initializeConnection() { try { - this.socket = io(window.location.origin, { + // 添加日志以便调试 + console.log('尝试连接WebSocket服务器...'); + + // 确保在Safari上使用完整的URL + const socketUrl = window.location.protocol === 'https:' + ? `${window.location.origin}` + : window.location.origin; + + console.log('WebSocket连接URL:', socketUrl); + + this.socket = io(socketUrl, { reconnection: true, reconnectionAttempts: 5, reconnectionDelay: 1000, reconnectionDelayMax: 5000, timeout: 20000, - autoConnect: true + autoConnect: true, + transports: ['websocket', 'polling'] // 明确指定传输方式,增加兼容性 }); this.socket.on('connect', () => { console.log('Connected to server'); this.updateConnectionStatus('已连接', true); + this.captureBtn.disabled = false; }); this.socket.on('disconnect', () => { diff --git a/templates/index.html b/templates/index.html index b9a7f1e..ebbd208 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,11 +3,22 @@ + + + + Snap Solver + @@ -296,13 +307,17 @@