feat(api): collab 房间管理与 Yjs 帧转发

accept 时按库里的 adminType 复核身份,房间以学生为键。
服务端只按房间转发二进制帧,不解析内容。
老师掉线请求退回排队,学生掉线请求随人清除。

顺带处理三项 Task 2 评审遗留:
- TEACHER_ROLES 去重,handler.ts 改为从 routes/helpers.ts 导入,不再自留一份
- 补全学生排队中断线(尚未进房间)的清理分支,避免陈旧请求卡死在列表里
- 修正 websocket.ts 里一处过期注释:username/adminType 是三种 kind 都会填,
  不是只有 collab 才填

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K1d8B3f4SXJwDvUY625eQd
This commit is contained in:
2026-08-28 02:36:12 -06:00
parent 1db2c49b87
commit b14639d890
4 changed files with 184 additions and 7 deletions

View File

@@ -63,7 +63,7 @@ export interface SubmissionSocketData {
token: string
/** 令牌桶open 时初始化,见 allowMessage */
rate?: { tokens: number; updatedAt: number }
/** 以下两项只有 kind === "collab" 时才填,握手时从会话里读 */
/** 握手时从会话里读,三种 kind 都会填;collab 通道用它判断老师身份、拼 room_open 里的姓名 */
username?: string
adminType?: string
/** 当前所在协作房间的房主学生id见 collab/handler.ts */