添加开始游戏前,进行连接检测

This commit is contained in:
kron
2025-06-28 22:44:30 +08:00
parent 77691c411a
commit 21b3e38ff0
9 changed files with 41 additions and 21 deletions

View File

@@ -1,3 +1,23 @@
import websocket from "@/websocket";
export const checkConnection = () => {
uni.sendSocketMessage({
data: JSON.stringify({ event: "ping", data: {} }),
fail: () => {
const token = uni.getStorageSync("token");
if (!token) return;
uni.showToast({
title: "连接中...",
icon: "none",
});
// 如果发送失败,说明连接已断开,需要重新连接
websocket.createWebSocket(token, (content) => {
uni.$emit("socket-inbox", content);
});
},
});
};
export const debounce = (fn, delay = 300) => {
let timer = null;
return async (...args) => {