update:提交我的设备改版

This commit is contained in:
2026-09-17 18:23:41 +08:00
parent 46cbd37102
commit b060d8f987
50 changed files with 897 additions and 590 deletions
+23 -6
View File
@@ -77,17 +77,33 @@ function createWebSocket(token, onMessage) {
socketTask.onMessage((res) => {
if (socket !== socketTask) return;
const { data, event } = JSON.parse(res.data);
let response;
try {
response = JSON.parse(res.data);
} catch (err) {
console.error("WebSocket 消息解析失败", err);
return;
}
const { data, event, code, timestamp } = response || {};
if (event === "pong") return;
if (data.type) {
if (event === "/addons/shoot/battery") {
if ((code == null || Number(code) === 0) && onMessage && data && typeof data === "object") {
onMessage({ event, data, code, timestamp });
}
return;
}
if (data?.type) {
if (ENABLE_REALTIME_MESSAGE_LOG) {
console.log("收到 WebSocket 消息", getMessageTypeName(data.type));
}
if (onMessage) onMessage({ ...(data.data || {}), type: data.type });
return;
}
if (onMessage && data.updates) onMessage(data.updates);
const msg = data.updates[0];
const updates = Array.isArray(data?.updates) ? data.updates : [];
if (!updates.length) return;
if (onMessage) onMessage(updates);
const msg = updates[0];
if (msg) {
if (ENABLE_REALTIME_MESSAGE_LOG) {
console.log(
@@ -101,9 +117,9 @@ function createWebSocket(token, onMessage) {
} else if (msg.constructor === MESSAGETYPES.LvlUpdate) {
uni.setStorageSync("latestLvl", msg.lvl);
} else if (msg.constructor === MESSAGETYPES.DeviceOnline) {
uni.$emit("update-online");
uni.$emit("update-online", true);
} else if (msg.constructor === MESSAGETYPES.DeviceOffline) {
uni.$emit("update-online");
uni.$emit("update-online", false);
} else if (msg.constructor === MESSAGETYPES.DeviceCharging) {
uni.$emit("device-charging");
}
@@ -121,6 +137,7 @@ function createWebSocket(token, onMessage) {
stopHeartbeat();
socket = null;
isConnecting = false;
uni.$emit("shoot-socket-disconnected");
if (manualClose || kickedOut) return;
await handleUnexpectedClose(onMessage);