forked from datawhale/whale-town-end
websocket:统一WebSocket网关配置
- 为CleanWebSocketGateway添加/game路径配置 - 支持通过环境变量WEBSOCKET_PORT配置端口 - 移除ZulipWebSocketGateway的模块引用 - 统一使用CleanWebSocketGateway作为唯一WebSocket网关 - 更新模块注释,反映当前架构
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user