WsM.ts 990 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { WS, WsRequest, WsResponse } from "../net/WS";
  2. export default class WsM {
  3. private static _ins: WsM;
  4. public static get ins(): WsM {
  5. return WsM._ins || new WsM();
  6. }
  7. public async userInfo(): Promise<any> {
  8. let result = await this.syncRequest(20001, {});
  9. console.log("userInfo", result);
  10. return result;
  11. }
  12. public async syncRequest(protocolId: number, data: any): Promise<any> {
  13. return new Promise((resolve, reject) => {
  14. resolve({});
  15. return;
  16. let cb = (msg: WsResponse) => {
  17. WS.ins.off(protocolId, cb, cb);
  18. if (msg.success) {
  19. resolve(msg.data);
  20. }
  21. reject(msg.msg);
  22. };
  23. WS.ins.on(protocolId, cb, cb);
  24. WsRequest.create(protocolId).setData(data).send();
  25. setTimeout(() => {
  26. WS.ins.off(protocolId, cb, cb);
  27. // let resp = new WsResponse();
  28. // resp.success = false;
  29. // resp.msg = "timeout";
  30. resolve(null);
  31. }, 5000);
  32. });
  33. }
  34. }