fix: 修复销毁websocket后还有心跳检测的问题

This commit is contained in:
zoujing 2025-09-23 20:30:48 +08:00
parent 8720c43570
commit 86c87b2cc4
2 changed files with 574 additions and 577 deletions

View File

@ -388,6 +388,7 @@ const initHandler = () => {
if (!appStore.hasToken) return; if (!appStore.hasToken) return;
loadRecentConversation(); loadRecentConversation();
///loadConversationMsgList(); ///loadConversationMsgList();
initTypewriterManager();
initWebSocket(); initWebSocket();
}; };
@ -395,8 +396,6 @@ onMounted(() => {
try { try {
getMainPageData(); getMainPageData();
addNoticeListener(); addNoticeListener();
initTypewriterManager();
// tokensocket // tokensocket
initHandler(); initHandler();
} catch (error) { } catch (error) {

View File

@ -121,8 +121,7 @@ export class WebSocketManager {
this.connectionState = false; this.connectionState = false;
this._safeCallCallback("onError", { this._safeCallCallback("onError", {
type: "CONNECTION_ERROR", type: "CONNECTION_ERROR",
message: message: "uni.connectSocket返回的SocketTask对象无效",
"uni.connectSocket返回的SocketTask对象无效",
originalError: null, originalError: null,
}); });
this.scheduleReconnect(); this.scheduleReconnect();
@ -427,9 +426,7 @@ export class WebSocketManager {
} }
if (this.reconnectAttempts >= this.maxReconnectAttempts) { if (this.reconnectAttempts >= this.maxReconnectAttempts) {
console.error( console.error(`达到最大重连次数(${this.maxReconnectAttempts}),停止重连`);
`达到最大重连次数(${this.maxReconnectAttempts}),停止重连`
);
this.connectionState = false; this.connectionState = false;
this.isConnecting = false; this.isConnecting = false;
@ -573,6 +570,7 @@ export class WebSocketManager {
*/ */
close() { close() {
this.stopHeartbeat(); this.stopHeartbeat();
this.resetConnectionState();
// 清理重连定时器 // 清理重连定时器
TimerUtils.clearTimer(this.reconnectTimer); TimerUtils.clearTimer(this.reconnectTimer);