将join room提前到on_connect
This commit is contained in:
@@ -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)}")
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user