Files
18xchat/assets/Scripts/chat18x/network/services/ChatService.ts
T

44 lines
1.4 KiB
TypeScript
Raw Normal View History

2025-08-29 16:39:41 +08:00
// assets/Scripts/services/logic/ChatService.ts
2025-08-27 17:33:51 +08:00
import type { ApiResponse } from "../client/types";
2025-08-29 16:39:41 +08:00
import proto from "db://assets/Scripts/proto/proto.pb.js";
import type { IChatService } from "./IChatService";
import { HttpChatService } from "./HttpChatService";
import { MockChatService } from "./MockChatService";
2025-08-27 17:33:51 +08:00
2025-08-29 16:39:41 +08:00
// 模拟开关
2025-09-10 17:37:24 +08:00
const USE_MOCK = false;
2025-08-29 16:39:41 +08:00
export class ChatService implements IChatService {
2025-08-27 17:33:51 +08:00
private static _I: ChatService | null = null;
public static get I(): ChatService {
if (!ChatService._I) ChatService._I = new ChatService();
return ChatService._I;
}
2025-08-29 16:39:41 +08:00
private impl: IChatService;
private constructor() {
this.impl = USE_MOCK ? new MockChatService() : new HttpChatService();
}
/** 运行期动态切换 */
public switch(useMock: boolean) {
this.impl = useMock ? new MockChatService() : new HttpChatService();
}
2025-09-08 19:44:45 +08:00
// 上报聊天数据
public async reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>> {
return this.impl.reqChatMsg(req);
2025-08-27 17:33:51 +08:00
}
2025-09-08 19:44:45 +08:00
// 获取聊天数据
public async reqGetChatMsg(req: proto.cs.ICSGetChatMsgReq): Promise<ApiResponse<proto.cs.ICSGetChatMsgRes>> {
return this.impl.reqGetChatMsg(req);
}
// 获取技师聊天次数
public async reqChatCountData(req: proto.cs.ICSGetChatRemainCountReq): Promise<ApiResponse<proto.cs.ICSGetChatRemainCountRes>> {
return this.impl.reqChatCountData(req);
}
2025-08-27 17:33:51 +08:00
}