tapd相关修改更新
This commit is contained in:
@@ -32,6 +32,7 @@ class WebsocketUtil {
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('WebSocket连接失败', error);
|
||||
uni.$emit('is-socket-open', true)
|
||||
this.reconnect();
|
||||
}
|
||||
});
|
||||
@@ -42,10 +43,12 @@ class WebsocketUtil {
|
||||
// 连接成功后启动心跳和消息监听
|
||||
this.startHeartbeat();
|
||||
this.listenForMessages();
|
||||
uni.$emit('is-socket-open', true)
|
||||
|
||||
});
|
||||
this.socketTask.onError((res) => {
|
||||
console.log('WebSocket连接失败!==',res);
|
||||
uni.$emit('is-socket-open', false)
|
||||
this.reconnect();
|
||||
});
|
||||
// 注意:这里的 onClose 监听器应该放在 uni.connectSocket 调用之后
|
||||
@@ -93,7 +96,7 @@ class WebsocketUtil {
|
||||
const { data } = res;
|
||||
this.messageCallbacks.forEach(callback => callback(data.toString())); // 假设 data 是字符串或可转换为字符串
|
||||
});
|
||||
this.send("WebSocket连接正常");
|
||||
// this.send("WebSocket连接正常");
|
||||
} else {
|
||||
console.error('WebSocket 连接尚未建立,无法监听消息');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user