update:优化性能问题
This commit is contained in:
+17
-10
@@ -8,6 +8,13 @@ let manualClose = false;
|
||||
let checkingSession = false;
|
||||
let kickedOut = false;
|
||||
let isConnecting = false;
|
||||
const ENABLE_REALTIME_MESSAGE_LOG = (() => {
|
||||
try {
|
||||
return uni.getAccountInfoSync().miniProgram.envVersion !== "release";
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
function createWebSocket(token, onMessage) {
|
||||
if (!token) return;
|
||||
@@ -73,22 +80,22 @@ function createWebSocket(token, onMessage) {
|
||||
const { data, event } = JSON.parse(res.data);
|
||||
if (event === "pong") return;
|
||||
if (data.type) {
|
||||
console.log(
|
||||
"收到 WebSocket 消息",
|
||||
getMessageTypeName(data.type),
|
||||
data.data
|
||||
);
|
||||
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];
|
||||
if (msg) {
|
||||
console.log(
|
||||
"收到 WebSocket 更新",
|
||||
getMessageTypeName(msg.constructor),
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user