代码优化
This commit is contained in:
@@ -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);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user