获取某一房间的用户

This commit is contained in:
2026-05-16 22:22:34 +08:00
parent 71efb34795
commit 75884d7b4b
5 changed files with 258 additions and 9 deletions

View File

@@ -7,7 +7,7 @@ import Offer from './offer';
import Answer from './answer';
import Candidate from './candidate';
import { v4 as uuid } from 'uuid';
import { onGetAllConnectionIds } from './websockethandler';
import { onGetAllConnectionIds, onGetOnlineUsers as onGetWsOnlineUsers } from './websockethandler';
import { log, LogLevel } from '../log';
/**
* 断开连接记录类
@@ -1106,6 +1106,66 @@ function getAllConnectionIds(req: Request, res: Response): void {
// 返回JSON响应包含连接ID列表和总数量
res.json({ connectionIds: connectionIds, totalCount: connectionIds.length });
}
/**
* 获取在线WebSocket用户列表
* @param req HTTP请求对象
* @param res HTTP响应对象
*/
/**
* @swagger
* /signaling/users:
* get:
* summary: 获取在线WebSocket用户列表
* description: 获取所有在线WebSocket用户支持按 connectionId 过滤指定房间内的用户
* parameters:
* - in: query
* name: connectionId
* schema:
* type: string
* required: false
* description: 连接ID传入时仅返回该房间内的在线用户
* responses:
* 200:
* description: 成功获取在线用户列表
* content:
* application/json:
* schema:
* type: object
* properties:
* users:
* type: array
* items:
* type: object
* properties:
* connectionId:
* type: string
* description: 所属连接ID
* participantId:
* type: string
* description: 参与者ID
* role:
* type: string
* enum: [host, participant]
* description: 角色
* userId:
* type: string
* description: 用户ID
* name:
* type: string
* description: 用户名称
* avatar:
* type: string
* description: 用户头像URL
* totalCount:
* type: number
* description: 在线用户总数
*/
function getOnlineUsers(req: Request, res: Response): void {
const connectionId = typeof req.query.connectionId === 'string' ? req.query.connectionId : undefined;
const users = onGetWsOnlineUsers(connectionId);
res.json({ users: users, totalCount: users.length });
}
/**
* 导出HTTP处理器函数
*/
@@ -1125,5 +1185,6 @@ export {
postAnswer, // 处理answer信令消息
postCandidate, // 处理candidate信令消息
onGetConnections, // 获取房间和用户信息
getAllConnectionIds // 获取所有连接ID
getAllConnectionIds, // 获取所有连接ID
getOnlineUsers // 获取在线WebSocket用户列表
};