PushMsgM.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { Hall } from "../../prefab/hall/Hall";
  2. import { RewardLayer } from "../../prefab/layer/RewardLayer";
  3. import { TipsLayer } from "../../prefab/layer/TipsLayer";
  4. import { LinkGameConfirmLayer } from "../../prefab/play/LinkGameConfirmLayer";
  5. import UserM, { GoodInfo } from "../api/UserM";
  6. import WsM from "../api/WsM";
  7. import { WS, WsResponse } from "../net/WS";
  8. import Utils from "../utils/Utils";
  9. import EV, { EV_TYPE } from "./EV";
  10. import ItemsM from "./ItemsM";
  11. import { Tips } from "./Tips";
  12. export class RewardGoods {
  13. changeList: GoodInfo[];
  14. goodList: GoodInfo[];
  15. }
  16. export class BindGameUserInfo {
  17. userId: string;
  18. userName: string;
  19. wallet: string;
  20. }
  21. export class BindGameConfirmInfo {
  22. gameId: number;
  23. userList: BindGameUserInfo[];
  24. }
  25. export default class PushMsgM {
  26. private static _ins: PushMsgM = null;
  27. public static get ins(): PushMsgM {
  28. return (PushMsgM._ins ??= new PushMsgM());
  29. }
  30. init() {
  31. WS.ins.on(10001, this.onRechargeSuccess, this);
  32. WS.ins.on(10002, this.onBindGameConfirm, this);
  33. WS.ins.on(10003, this.onRefreshUserData, this);
  34. WS.ins.on(10004, this.onRewardGoods, this);
  35. WS.ins.on(10005, this.OnJoinFamilySuccess, this);
  36. WS.ins.on(10006, this.OnFamilyKickedMe, this);
  37. WS.ins.on(401, this.OnUserTokenError, this);
  38. }
  39. onBindGameConfirm(msg: WsResponse) {
  40. let data = msg.data as BindGameConfirmInfo;
  41. if (!data) {
  42. return;
  43. }
  44. if (!data.userList || data.userList.length == 0) {
  45. TipsLayer.showConfirm("", "This code is not valid");
  46. return;
  47. }
  48. LinkGameConfirmLayer.show(data);
  49. }
  50. async OnJoinFamilySuccess(msg: WsResponse) {
  51. await UserM.ins.refreshInfo();
  52. await TipsLayer.showConfirm(
  53. "",
  54. Utils.setI18nLabel("Family.JoinFamilySuccess")
  55. );
  56. EV.ins.emit(EV_TYPE.FAMILY_STATUS_UPDATE);
  57. Hall.ins.switchPage(Hall.PageFamily);
  58. }
  59. async OnFamilyKickedMe(msg: WsResponse) {
  60. let result = await TipsLayer.showConfirm(
  61. "",
  62. Utils.setI18nLabel("Family.KickedMe")
  63. );
  64. await UserM.ins.refreshInfo();
  65. EV.ins.emit(EV_TYPE.FAMILY_STATUS_UPDATE);
  66. }
  67. OnUserTokenError(msg: WsResponse) {
  68. console.warn("OnUserTokenError", msg);
  69. window.location.reload();
  70. }
  71. onRefreshUserData(msg: WsResponse) {
  72. console.warn("onRefreshUserData", msg);
  73. UserM.ins.refreshData();
  74. }
  75. onRechargeSuccess(msg: WsResponse) {
  76. console.warn("onRechargeSuccess", msg);
  77. console.warn("changeList", msg.data.changeList);
  78. ItemsM.ins.itemChange(msg.data.changeList, msg.data.goodList);
  79. }
  80. onRewardGoods(msg: WsResponse) {
  81. console.warn("onRewardGoods", msg);
  82. let data = msg.data as RewardGoods;
  83. // UserM.ins.refreshGoods(data.goodList);
  84. // RewardLayer.show(data.changeList);
  85. ItemsM.ins.itemChange(data.changeList, data.goodList);
  86. }
  87. }