refactor(game): 重构游戏模块并添加WebSocket客户端
- 修改开发环境配置中的代理目标地址 - 移除旧的活动房间状态管理模块 - 移除成都麻将游戏相关的测试用例 - 添加新的游戏动作发送功能 - 实现WebSocket客户端类并支持自动重连 - 添加WebSocket消息处理器注册机制 - 创建游戏相关状态类型定义 - 添加ID生成工具函数 - 移除废弃的游戏相关模块和常量定义 - 添加WebSocket消息结构定义 - 重构游戏状态相关类型定义
This commit is contained in:
13
src/ws/url.ts
Normal file
13
src/ws/url.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
const WS_BASE_URL = import.meta.env.VITE_GAME_WS_URL ?? '/api/v1/ws'
|
||||
|
||||
export function buildWsUrl(token: string): string {
|
||||
const baseUrl = /^wss?:\/\//.test(WS_BASE_URL)
|
||||
? new URL(WS_BASE_URL)
|
||||
: new URL(
|
||||
WS_BASE_URL.startsWith('/') ? WS_BASE_URL : `/${WS_BASE_URL}`,
|
||||
`${window.location.protocol === 'https:' ? 'wss:' : 'ws:'}//${window.location.host}`,
|
||||
)
|
||||
|
||||
baseUrl.searchParams.set('token', token)
|
||||
return baseUrl.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user