12345678910111213141516171819202122232425262728293031323334353637383940 |
- import { WS, WsRequest, WsResponse } from "../net/WS";
- export default class WsM {
- private static _ins: WsM;
- public static get ins(): WsM {
- return WsM._ins || new WsM();
- }
- public async userInfo(): Promise<any> {
- let result = await this.syncRequest(20001, {});
- console.log("userInfo", result);
- return result;
- }
- public async syncRequest(protocolId: number, data: any): Promise<any> {
- return new Promise((resolve, reject) => {
- resolve({});
- return;
- let cb = (msg: WsResponse) => {
- WS.ins.off(protocolId, cb, cb);
- if (msg.success) {
- resolve(msg.data);
- }
- reject(msg.msg);
- };
- WS.ins.on(protocolId, cb, cb);
- WsRequest.create(protocolId).setData(data).send();
- setTimeout(() => {
- WS.ins.off(protocolId, cb, cb);
- // let resp = new WsResponse();
- // resp.success = false;
- // resp.msg = "timeout";
- resolve(null);
- }, 5000);
- });
- }
- }
|