SocketPlayer.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import PIFS from "../../PIFS";
  2. import MatchView from "../../Views/MatchView";
  3. import GoSocketClient from "../Core/Network/GoSocketClient";
  4. export default class SocketPlayer extends GoSocketClient {
  5. constructor() {
  6. super();
  7. // this.connect("ws://192.168.101.3:11815/DumplingServer");
  8. this.connect("wss://www.9527fun.cn/DumplingServer");
  9. }
  10. protected onLoad() {
  11. console.warn("onLoad");
  12. this.requestEnterRoom();
  13. }
  14. protected onReload() {
  15. console.warn("onReload");
  16. }
  17. protected onDestroy() {
  18. console.warn("onDestroy");
  19. }
  20. protected onMiss() {
  21. console.warn("onMiss");
  22. }
  23. /**通知来自服务端-匹配完成 */
  24. protected onMatchComplete(id, playerInfos, uuid, timestamp) {
  25. console.log("onMatchComplete", {
  26. id: id,
  27. playerInfos: playerInfos,
  28. uuid: uuid,
  29. timestamp: timestamp
  30. });
  31. window.gameSystem.onMatchComplete(id, playerInfos, uuid, timestamp);
  32. PIFS.setMatchPlayerInfos(playerInfos, timestamp);
  33. MatchView.handleMatchSuccess();
  34. }
  35. /**通知来自服务端-游戏开始 */
  36. protected onGameStart() {
  37. console.log("onGameStart");
  38. window.gameSystem.onGameStart();
  39. if (MatchView.Instance) MatchView.Instance.close();
  40. cc.find("Canvas/BgMusic").getComponent(cc.AudioSource).enabled = true;
  41. }
  42. /**通知来自服务端-帧同步 */
  43. protected onFrameSync(frames: any[]) {
  44. window.gameSystem.onFrameSync(frames);
  45. }
  46. private _hasRequestEnterRoom = false;
  47. /**请求匹配进入房间 */
  48. public requestEnterRoom() {
  49. if (!MatchView.isGameInited) return;
  50. if (!this.isValid) return;
  51. if (this._hasRequestEnterRoom) return;
  52. this._hasRequestEnterRoom = true;
  53. console.log("RequestEnterRoom", PIFS.myPlayerInfo.nickname);
  54. this.call("RequestEnterRoom", PIFS.myPlayerInfo)
  55. }
  56. /**上传帧数据 */
  57. public uploadFrames(...frames) {
  58. if (!window.gameSystem.isGameStart) return;
  59. this.call("UploadFrames", frames);
  60. }
  61. }