From fd6be25ba5af0c0f2c033b2aa9ea1b15e6cd3677 Mon Sep 17 00:00:00 2001 From: zhangyibo95 <690096405@qq.com> Date: Wed, 23 Sep 2026 14:22:57 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E6=81=A2=E5=A4=8Dws=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E9=80=9A=E7=9F=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/websocket.js | 58 +++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/websocket.js b/src/websocket.js index 4614bd9..e709cd5 100644 --- a/src/websocket.js +++ b/src/websocket.js @@ -87,6 +87,22 @@ function createWebSocket(token, onMessage) { const { data, event, code, timestamp } = response || {}; if (event === "pong") return; + const passthroughEvents = [ + "/addons/shoot/battery", + "/addons/shoot/otaProgress", + "/addons/shoot/otaResult", + ]; + if (passthroughEvents.includes(event)) { + if ( + (code == null || Number(code) === 0) && + onMessage && + data && + typeof data === "object" + ) { + onMessage({ event, data, code, timestamp }); + } + return; + } if (!data || typeof data !== "object") return; if (data.type) { if (ENABLE_REALTIME_MESSAGE_LOG) { @@ -97,27 +113,29 @@ function createWebSocket(token, onMessage) { } if (!Array.isArray(data.updates)) return; if (onMessage) onMessage(data.updates); - const msg = data.updates[0]; - if (msg) { - if (ENABLE_REALTIME_MESSAGE_LOG) { - console.log( - "收到 WebSocket 更新", - getMessageTypeName(msg.constructor), - { updateCount: data.updates.length } - ); - } - 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", true); - } else if (msg.constructor === MESSAGETYPES.DeviceOffline) { - uni.$emit("update-online", false); - } else if (msg.constructor === MESSAGETYPES.DeviceCharging) { - uni.$emit("device-charging"); - } + const firstMessage = data.updates[0]; + if (firstMessage && ENABLE_REALTIME_MESSAGE_LOG) { + console.log( + "收到 WebSocket 更新", + getMessageTypeName(firstMessage.constructor), + { updateCount: data.updates.length } + ); } + data.updates.forEach((msg) => { + if (msg) { + 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", true); + } else if (msg.constructor === MESSAGETYPES.DeviceOffline) { + uni.$emit("update-online", false); + } else if (msg.constructor === MESSAGETYPES.DeviceCharging) { + uni.$emit("device-charging"); + } + } + }); }); socketTask.onError((err) => {