重构NetManager支持MessagePair,新增TSRPCWsClient。

This commit is contained in:
janing
2025-12-18 13:25:04 +08:00
parent c12e439add
commit fb940452db
41 changed files with 976 additions and 681 deletions

View File

@@ -0,0 +1,55 @@
import { NetManager } from '../../Framework/Net/NetManager';
import { MsgReqLogin } from '../../Shared/protocols/MsgReqLogin';
import { MsgReqMove } from '../../Shared/protocols/MsgReqMove';
import { MsgReqSend } from '../../Shared/protocols/MsgReqSend';
import { MsgResLogin } from '../../Shared/protocols/MsgResLogin';
import { MsgResMove } from '../../Shared/protocols/MsgResMove';
import { MsgResSend } from '../../Shared/protocols/MsgResSend';
import { LoginMessagePair } from './Pair/LoginMessagePair';
import { MoveMessagePair } from './Pair/MoveMessagePair';
import { SendMessagePair } from './Pair/SendMessagePair';
/**
* 消息管理器 - 提供类型安全的消息发送方法
*/
export class MsgManager {
private static _instance: MsgManager;
static getInstance(): MsgManager {
if (!this._instance) {
this._instance = new MsgManager();
}
return this._instance;
}
private get netManager(): NetManager {
return NetManager.getInstance();
}
/**
* 发送登录请求
* @param loginData 登录数据
* @returns 登录响应
*/
async login(loginData: MsgReqLogin): Promise<MsgResLogin | null> {
return this.netManager.callMsg(new LoginMessagePair(), loginData);
}
/**
* 发送移动请求
* @param moveData 移动数据
* @returns 移动响应
*/
async move(moveData: MsgReqMove): Promise<MsgResMove | null> {
return this.netManager.callMsg(new MoveMessagePair(), moveData);
}
/**
* 发送消息请求
* @param sendData 发送数据
* @returns 发送响应
*/
async send(sendData: MsgReqSend): Promise<MsgResSend | null> {
return this.netManager.callMsg(new SendMessagePair(), sendData);
}
}