细节调整

This commit is contained in:
kron
2025-06-19 21:03:33 +08:00
parent 595a9802e2
commit 35d544003d
14 changed files with 97 additions and 38 deletions

View File

@@ -13,19 +13,21 @@ const RECONNECT_CONFIG = {
/**
* 建立 WebSocket 连接
*/
function createWebSocket(token, onMessage) {
function createWebSocket(token, onUpdate, onMessage) {
const url = `wss://api.shelingxingqiu.com/socket?authorization=${token}`;
socket = uni.connectSocket({
url,
success: () => {
console.log("websocket 连接成功");
onUpdate(true);
reconnectCount = 0; // 重置重连次数
},
});
// 接收消息
uni.onSocketMessage((res) => {
if (onMessage) onMessage(res.data);
const data = JSON.parse(res.data);
if (onMessage) onMessage(data.data.updates);
});
// 错误处理
@@ -36,6 +38,7 @@ function createWebSocket(token, onMessage) {
uni.onSocketClose((result) => {
console.log("WebSocket 已关闭", result);
onUpdate(false);
stopHeartbeat();
reconnect(token, onMessage);
});