From 09d8e7b3da1d5bbab0e7b1fe5124a62a5b813b1f Mon Sep 17 00:00:00 2001 From: kron Date: Fri, 6 Feb 2026 14:00:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/constants.js | 1 + src/websocket.js | 82 ++++++++++++++++++++++++++---------------------- 2 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/constants.js b/src/constants.js index ff65e93..ee917e3 100644 --- a/src/constants.js +++ b/src/constants.js @@ -37,6 +37,7 @@ export const MESSAGETYPESV2 = { ShootResult: 4, NewRound: 5, BattleEnd: 6, + halfRest: 7, }; export const topThreeColors = ["#FFD947", "#D2D2D2", "#FFA515"]; diff --git a/src/websocket.js b/src/websocket.js index e07d642..dec794b 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -14,7 +14,7 @@ function createWebSocket(token, onMessage) { switch (envVersion) { case "develop": // 开发版 - // url = "ws://192.168.1.242:8000/socket"; + // url = "ws://192.168.1.30:8000/socket"; url = "wss://apitest.shelingxingqiu.com/socket"; break; case "trial": // 体验版 @@ -45,44 +45,50 @@ function createWebSocket(token, onMessage) { // 接收消息 uni.onSocketMessage((res) => { - const data = JSON.parse(res.data); - if (data.event === "pong" || !data.data.updates) return; - if (onMessage) onMessage(data.data.updates); - const msg = data.data.updates[0]; - if (!msg) return; - console.log("收到消息:", getMessageTypeName(msg.constructor), msg); - if (msg.constructor === MESSAGETYPES.BackToGame) { - const pages = getCurrentPages(); - const currentPage = pages[pages.length - 1]; - if ( - currentPage.route === "pages/battle-room" || - currentPage.route === "pages/team-battle" || - currentPage.route === "pages/melee-match" - ) { - return; + const { data, event } = JSON.parse(res.data); + if (event === "pong") return; + if (data.type && data.data) { + console.log("收到消息:", getMessageTypeName(data.type), data.data); + if (onMessage) onMessage({ ...data.data, type: data.type }); + return; + } + if (onMessage && data.updates) onMessage(data.updates); + const msg = data.updates[0]; + if (msg) { + console.log("收到消息:", getMessageTypeName(msg.constructor), msg); + if (msg.constructor === MESSAGETYPES.BackToGame) { + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + if ( + currentPage.route === "pages/battle-room" || + currentPage.route === "pages/team-battle" || + currentPage.route === "pages/melee-match" + ) { + return; + } + const { battleInfo } = msg; + uni.setStorageSync("current-battle", battleInfo); + // console.log("----battleInfo", battleInfo); + if (battleInfo.config.mode === 1) { + uni.navigateTo({ + url: `/pages/team-battle?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`, + }); + } else if (battleInfo.config.mode === 2) { + uni.navigateTo({ + url: `/pages/melee-match?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`, + }); + } + } else if (msg.constructor === MESSAGETYPES.MatchOver) { + uni.$emit("game-over"); + } else if (msg.constructor === MESSAGETYPES.RankUpdate) { + uni.setStorageSync("latestRank", msg.lvl); + } else if (msg.constructor === MESSAGETYPES.LvlUpdate) { + uni.setStorageSync("latestLvl", msg.lvl); + } else if (msg.constructor === MESSAGETYPES.DeviceOnline) { + uni.$emit("update-online"); + } else if (msg.constructor === MESSAGETYPES.DeviceOffline) { + uni.$emit("update-online"); } - const { battleInfo } = msg; - uni.setStorageSync("current-battle", battleInfo); - // console.log("----battleInfo", battleInfo); - if (battleInfo.config.mode === 1) { - uni.navigateTo({ - url: `/pages/team-battle?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`, - }); - } else if (battleInfo.config.mode === 2) { - uni.navigateTo({ - url: `/pages/melee-match?battleId=${battleInfo.id}&gameMode=${battleInfo.config.battleMode}`, - }); - } - } else if (msg.constructor === MESSAGETYPES.MatchOver) { - uni.$emit("game-over"); - } else if (msg.constructor === MESSAGETYPES.RankUpdate) { - uni.setStorageSync("latestRank", msg.lvl); - } else if (msg.constructor === MESSAGETYPES.LvlUpdate) { - uni.setStorageSync("latestLvl", msg.lvl); - } else if (msg.constructor === MESSAGETYPES.DeviceOnline) { - uni.$emit("update-online"); - } else if (msg.constructor === MESSAGETYPES.DeviceOffline) { - uni.$emit("update-online"); } });