feat: 添加房间详情和 WebSocket 消息类型定义

This commit is contained in:
2026-06-23 11:08:58 +08:00
parent 0383572d39
commit 205b60711a

View File

@@ -65,6 +65,8 @@ export interface RoomItem {
mode: string
/** 房主昵称 */
creatorName: string
/** 是否允许观战 */
allowSpectate: boolean
}
/** 获取游戏列表 — 无请求参数 */
@@ -99,6 +101,8 @@ export interface CreateRoomRequest {
stakes: number
/** 最大玩家数 */
maxPlayers: number
/** 是否允许观战 */
allowSpectate?: boolean
}
/** 创建房间响应 */
@@ -106,3 +110,75 @@ export interface CreateRoomResponse {
/** 新建的房间信息 */
room: RoomItem
}
/** 房间详情(进入房间页时的初始快照) */
export interface RoomDetailResponse {
roomId: string
name: string
gameId: string
gameIcon: string
gameName: string
maxPlayers: number
mode: string
stakes: number
status: RoomStatus
creatorId: string
creatorName: string
allowSpectate: boolean
players: RoomPlayerDetail[]
/** 棋盘状态(对局中才有) */
boardState?: number[][]
/** 当前轮到谁userIdnull 表示未开始 */
currentTurn?: string
/** 走棋记录 */
moves?: MoveItem[]
}
/** 房间内玩家详情(含座位号和准备状态) */
export interface RoomPlayerDetail {
userId: string
avatar: string
nickname: string
seatNumber: number
ready: boolean
}
/** 走棋记录项 */
export interface MoveItem {
moveIndex: number
playerId: string
row: number
col: number
}
/** WebSocket 消息通用封装 */
export interface WsMessage<T = unknown> {
type: string
data: T
}
/** WebSocket 上行消息类型 */
export type WsInboundType =
| 'place_stone'
| 'chat'
| 'ready'
| 'resign'
| 'draw_request'
| 'draw_response'
| 'leave'
| 'start'
/** WebSocket 下行消息类型 */
export type WsOutboundType =
| 'board_sync'
| 'move'
| 'turn_change'
| 'chat_broadcast'
| 'game_over'
| 'player_join'
| 'player_leave'
| 'ready_change'
| 'spectator_join'
| 'spectator_leave'
| 'move_history'
| 'error'