44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
// assets/Scripts/services/logic/ChatService.ts
|
|
import type { ApiResponse } from "../client/types";
|
|
import proto from "db://assets/Scripts/proto/proto.pb.js";
|
|
import type { IChatService } from "./IChatService";
|
|
import { HttpChatService } from "./HttpChatService";
|
|
import { MockChatService } from "./MockChatService";
|
|
|
|
// 模拟开关
|
|
const USE_MOCK = false;
|
|
|
|
export class ChatService implements IChatService {
|
|
private static _I: ChatService | null = null;
|
|
public static get I(): ChatService {
|
|
if (!ChatService._I) ChatService._I = new ChatService();
|
|
return ChatService._I;
|
|
}
|
|
|
|
private impl: IChatService;
|
|
|
|
private constructor() {
|
|
this.impl = USE_MOCK ? new MockChatService() : new HttpChatService();
|
|
}
|
|
|
|
/** 运行期动态切换 */
|
|
public switch(useMock: boolean) {
|
|
this.impl = useMock ? new MockChatService() : new HttpChatService();
|
|
}
|
|
|
|
// 上报聊天数据
|
|
public async reqChatMsg(req: proto.cs.ICSChatMsgReq): Promise<ApiResponse<proto.cs.ICSChatMsgRes>> {
|
|
return this.impl.reqChatMsg(req);
|
|
}
|
|
|
|
// 获取聊天数据
|
|
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);
|
|
}
|
|
}
|