update:恢复ws电量通知代码
This commit is contained in:
+22
-4
@@ -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,15 +113,16 @@ 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) {
|
||||
const firstMessage = data.updates[0];
|
||||
if (firstMessage && ENABLE_REALTIME_MESSAGE_LOG) {
|
||||
console.log(
|
||||
"收到 WebSocket 更新",
|
||||
getMessageTypeName(msg.constructor),
|
||||
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) {
|
||||
@@ -119,6 +136,7 @@ function createWebSocket(token, onMessage) {
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
socketTask.onError((err) => {
|
||||
if (socket !== socketTask) return;
|
||||
|
||||
Reference in New Issue
Block a user