update:恢复ws电量通知代码
This commit is contained in:
+38
-20
@@ -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,27 +113,29 @@ 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(firstMessage.constructor),
|
||||||
getMessageTypeName(msg.constructor),
|
{ updateCount: data.updates.length }
|
||||||
{ 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");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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) => {
|
socketTask.onError((err) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user