添加开始游戏前,进行连接检测
This commit is contained in:
20
src/util.js
20
src/util.js
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user