代码优化

This commit is contained in:
kron
2025-06-05 17:43:22 +08:00
parent 18fb0ee7d4
commit 219fdc54ad
5 changed files with 18 additions and 13 deletions

View File

@@ -21,8 +21,9 @@ function createWebSocket(token, onMessage) {
});
// 关闭处理
uni.onSocketClose(() => {
console.log("WebSocket 已关闭");
uni.onSocketClose((result) => {
console.log("WebSocket 已关闭", result);
stopHeartbeat();
});
// 启动心跳
@@ -44,9 +45,11 @@ function startHeartbeat() {
heartbeatInterval = setInterval(() => {
if (socket && uni.sendSocketMessage) {
console.log("ping");
uni.sendSocketMessage({
data: "ping",
data: {
event: "ping",
data: {},
},
fail: (err) => {
console.error("发送心跳失败", err);
},