From 75ac7ac0f86054a78a102f546ae5453cf27bcfaf Mon Sep 17 00:00:00 2001 From: moyin <244344649@qq.com> Date: Fri, 9 Jan 2026 17:45:51 +0800 Subject: [PATCH] =?UTF-8?q?websocket=EF=BC=9A=E7=BB=9F=E4=B8=80WebSocket?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为CleanWebSocketGateway添加/game路径配置 - 支持通过环境变量WEBSOCKET_PORT配置端口 - 移除ZulipWebSocketGateway的模块引用 - 统一使用CleanWebSocketGateway作为唯一WebSocket网关 - 更新模块注释,反映当前架构 --- src/business/zulip/clean_websocket.gateway.ts | 9 ++++++--- src/business/zulip/zulip.module.ts | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/business/zulip/clean_websocket.gateway.ts b/src/business/zulip/clean_websocket.gateway.ts index 91e7524..f679dcf 100644 --- a/src/business/zulip/clean_websocket.gateway.ts +++ b/src/business/zulip/clean_websocket.gateway.ts @@ -31,9 +31,12 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy { ) {} async onModuleInit() { - const port = 3001; + const port = process.env.WEBSOCKET_PORT ? parseInt(process.env.WEBSOCKET_PORT) : 3001; - this.server = new WebSocket.Server({ port }); + this.server = new WebSocket.Server({ + port, + path: '/game' // 统一使用 /game 路径 + }); this.server.on('connection', (ws: ExtendedWebSocket) => { ws.id = this.generateClientId(); @@ -71,7 +74,7 @@ export class CleanWebSocketGateway implements OnModuleInit, OnModuleDestroy { }); }); - this.logger.log(`WebSocket服务器启动成功,端口: ${port}`); + this.logger.log(`WebSocket服务器启动成功,端口: ${port},路径: /game`); } async onModuleDestroy() { diff --git a/src/business/zulip/zulip.module.ts b/src/business/zulip/zulip.module.ts index 091129c..c29fbbe 100644 --- a/src/business/zulip/zulip.module.ts +++ b/src/business/zulip/zulip.module.ts @@ -14,7 +14,7 @@ * * 业务服务: * - ZulipService: 主协调服务,处理登录、消息发送等核心业务流程 - * - ZulipWebSocketGateway: WebSocket统一网关,处理客户端连接 + * - CleanWebSocketGateway: WebSocket统一网关,处理客户端连接 * - SessionManagerService: 会话状态管理和业务逻辑 * - MessageFilterService: 消息过滤和业务规则控制 * @@ -43,7 +43,6 @@ */ import { Module } from '@nestjs/common'; -import { ZulipWebSocketGateway } from './zulip_websocket.gateway'; import { CleanWebSocketGateway } from './clean_websocket.gateway'; import { ZulipService } from './zulip.service'; import { SessionManagerService } from './services/session_manager.service'; @@ -52,6 +51,8 @@ import { ZulipEventProcessorService } from './services/zulip_event_processor.ser import { SessionCleanupService } from './services/session_cleanup.service'; import { ChatController } from './chat.controller'; import { WebSocketDocsController } from './websocket_docs.controller'; +import { WebSocketOpenApiController } from './websocket_openapi.controller'; +import { WebSocketTestController } from './websocket_test.controller'; import { ZulipAccountsController } from './zulip_accounts.controller'; import { ZulipCoreModule } from '../../core/zulip_core/zulip_core.module'; import { ZulipAccountsModule } from '../../core/db/zulip_accounts/zulip_accounts.module'; @@ -94,6 +95,10 @@ import { AuthModule } from '../auth/auth.module'; ChatController, // WebSocket API文档控制器 WebSocketDocsController, + // WebSocket OpenAPI规范控制器 + WebSocketOpenApiController, + // WebSocket测试页面控制器 + WebSocketTestController, // Zulip账号关联管理控制器 ZulipAccountsController, ],