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 | WsClient_Miniapp { 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;