squidGame/tgx-games-client/assets/module_basic/scripts/NetUtil.ts

35 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2025-02-07 10:49:34 +08:00
import { WECHAT } from 'cc/env';
import { WsClient as WsClient_Browser } from 'tsrpc-browser';
import { WsClient as WsClient_Miniapp } from 'tsrpc-miniapp';
import { ServiceType, serviceProto } from '../shared/protocols/serviceProto_public';
/** 网络请求相关 */
export class NetUtil {
private static _globalErrorFilters = {};
static addErrorFilter(error: string, cb: Function, target?: any) {
this._globalErrorFilters[error] = { cb: cb, target: target };
}
/** World Server */
static createWebsocketClient(serverUrl: string): WsClient_Browser<ServiceType> | WsClient_Miniapp<ServiceType> {
let client = new (WECHAT ? WsClient_Miniapp : WsClient_Browser)(serviceProto, {
server: serverUrl,
heartbeat: {
interval: 5000,
timeout: 5000
},
// json: true,
logger: console,
logMsg: false
});
// FLOWS
// TODO
return client;
}
}
(window as any).NetUtil = NetUtil;