From 5b8180b48e90be7089a46dba399f3e34103889f8 Mon Sep 17 00:00:00 2001 From: CakeCN Date: Thu, 8 Jan 2026 20:50:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86join=20room=E6=8F=90=E5=89=8D=E5=88=B0?= =?UTF-8?q?on=5Fconnect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Html/apps/sockets/namespaces.py | 10 ++++++++-- Html/apps/static/js/chatbox.js | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Html/apps/sockets/namespaces.py b/Html/apps/sockets/namespaces.py index 75323fa..6a5c2c6 100644 --- a/Html/apps/sockets/namespaces.py +++ b/Html/apps/sockets/namespaces.py @@ -63,6 +63,13 @@ class VSCodeNamespace(Namespace): class AgentNamespace(Namespace): + def on_connect(self): + # 获取前端连接时传递的 query 参数 + user_uuid = request.args.get('user_uuid') + folder = request.args.get('folder') + print(f'Agent client connected with user_uuid: {user_uuid}, folder: {folder}') + join_room(user_id, namespace='/agent') + def _load_learning_progress(self, chatmanager, user_id, course_id, chapter_name, lesson_name, continue_learn): """加载并恢复用户学习进度 @@ -120,7 +127,6 @@ class AgentNamespace(Namespace): chapter_name = data['chapter_name'] user_id = uuid2username[user_uuid] session['user_uuid'] = user_uuid - join_room(user_uuid, namespace='/agent') # 将该用户加入以user_id为名的room print(f'User connected with session user_uuid: {user_uuid}') user_uuid2chatmanager = ex["user_uuid2chatmanager"] @@ -286,4 +292,4 @@ class AgentNamespace(Namespace): leave_room(uuid, namespace='/agent') self.app.logger.info("VSCode client disconnected") - self.app.logger.info(f"Disconnect reason: {str(data)}") + self.app.logger.info(f"Disconnect reason: {str(data)}") \ No newline at end of file diff --git a/Html/apps/static/js/chatbox.js b/Html/apps/static/js/chatbox.js index 5e665bb..1801818 100644 --- a/Html/apps/static/js/chatbox.js +++ b/Html/apps/static/js/chatbox.js @@ -75,6 +75,8 @@ document.addEventListener('DOMContentLoaded', function () { folder: data.folder } }); + console.log('Connecting to WebSocket server at wss://${host}/agent'); + console.log(data); // 初始化聊天消息管理器 chatManager = new ChatMessageManager();