update:恢复ws电量通知代码

This commit is contained in:
2026-09-23 14:22:57 +08:00
parent bad3c8ff9a
commit fd6be25ba5
+22 -4
View File
@@ -87,6 +87,22 @@ function createWebSocket(token, onMessage) {
const { data, event, code, timestamp } = response || {}; const { data, event, code, timestamp } = response || {};
if (event === "pong") return; 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 || typeof data !== "object") return;
if (data.type) { if (data.type) {
if (ENABLE_REALTIME_MESSAGE_LOG) { if (ENABLE_REALTIME_MESSAGE_LOG) {
@@ -97,15 +113,16 @@ function createWebSocket(token, onMessage) {
} }
if (!Array.isArray(data.updates)) return; if (!Array.isArray(data.updates)) return;
if (onMessage) onMessage(data.updates); if (onMessage) onMessage(data.updates);
const msg = data.updates[0]; const firstMessage = data.updates[0];
if (msg) { if (firstMessage && ENABLE_REALTIME_MESSAGE_LOG) {
if (ENABLE_REALTIME_MESSAGE_LOG) {
console.log( console.log(
"收到 WebSocket 更新", "收到 WebSocket 更新",
getMessageTypeName(msg.constructor), getMessageTypeName(firstMessage.constructor),
{ updateCount: data.updates.length } { updateCount: data.updates.length }
); );
} }
data.updates.forEach((msg) => {
if (msg) {
if (msg.constructor === MESSAGETYPES.RankUpdate) { if (msg.constructor === MESSAGETYPES.RankUpdate) {
uni.setStorageSync("latestRank", msg.lvl); uni.setStorageSync("latestRank", msg.lvl);
} else if (msg.constructor === MESSAGETYPES.LvlUpdate) { } else if (msg.constructor === MESSAGETYPES.LvlUpdate) {
@@ -119,6 +136,7 @@ function createWebSocket(token, onMessage) {
} }
} }
}); });
});
socketTask.onError((err) => { socketTask.onError((err) => {
if (socket !== socketTask) return; if (socket !== socketTask) return;