From cc919b23e314d135846905580cff4c6dd8a238ea Mon Sep 17 00:00:00 2001 From: xudan Date: Fri, 20 Jun 2025 09:03:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96WebSocket=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=EF=BC=8C=E8=B0=83=E6=95=B4=E5=BF=83=E8=B7=B3=E9=97=B4?= =?UTF-8?q?=E9=9A=94=E5=92=8C=E8=B6=85=E6=97=B6=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E6=8F=90=E5=8D=87=E8=BF=9E=E6=8E=A5=E7=A8=B3=E5=AE=9A=E6=80=A7?= =?UTF-8?q?=EF=BC=9B=E6=9B=B4=E6=96=B0=E7=94=BB=E5=B8=83=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E7=BC=A9=E6=94=BE=E6=AF=94=E4=BE=8B=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E6=9B=B4=E7=81=B5=E6=B4=BB=E7=9A=84=E7=BC=A9=E6=94=BE=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/map/constant.ts | 4 ++-- src/services/ws.ts | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/apis/map/constant.ts b/src/apis/map/constant.ts index 0b143f3..f092111 100644 --- a/src/apis/map/constant.ts +++ b/src/apis/map/constant.ts @@ -133,8 +133,8 @@ export const EDITOR_CONFIG: Options = { disableEmptyLine: true, /** 禁用重复线条 - 不允许在同一对点之间创建多条线 */ disableRepeatLine: true, - /** 最小缩放比例 - 画布最小缩放到24% */ - minScale: 0.24, + /** 最小缩放比例 - 画布最小缩放到1% */ + minScale: 0.01, /** 最大缩放比例 - 画布最大缩放到401% */ maxScale: 4.01, /** 缩放步长 - 每次滚轮滚动的缩放幅度(5%) */ diff --git a/src/services/ws.ts b/src/services/ws.ts index bb0c2d8..aa5ad94 100644 --- a/src/services/ws.ts +++ b/src/services/ws.ts @@ -1,10 +1,10 @@ // WebSocket全局配置 const WS_CONFIG = { - heartbeatInterval: 30000, // 30秒心跳间隔 - heartbeatTimeout: 5000, // 心跳响应超时时间(5秒) + heartbeatInterval: 10000, // 30秒心跳间隔 + heartbeatTimeout: 10000, // 心跳响应超时时间(10秒,给服务器更多响应时间) maxReconnectAttempts: 5, // 最大重连次数 - reconnectBaseDelay: 1000, // 重连基础延迟1秒 - maxReconnectDelay: 30000, // 最大重连延迟30秒 + reconnectBaseDelay: 500, // 重连基础延迟0.5秒(更快重连) + maxReconnectDelay: 10000, // 最大重连延迟10秒(减少等待时间) heartbeatMessage: 'ping', // 心跳消息 heartbeatResponseType: 'pong', // 心跳响应类型 }; @@ -38,6 +38,12 @@ class EnhancedWebSocket { console.log(`WebSocket连接已建立: ${this.path}`); this.reconnectAttempts = 0; this.clearReconnectTimer(); + + // 🔧 优化:连接建立后立即发送一次心跳,然后开始定期心跳 + if (this.ws.readyState === WebSocket.OPEN) { + this.ws.send(WS_CONFIG.heartbeatMessage); + this.startHeartbeatTimeout(); + } this.startHeartbeat(); if (this.userOnOpen) { @@ -48,6 +54,9 @@ class EnhancedWebSocket { this.ws.onmessage = (event) => { const messageData = event.data; + // 🔧 优化:收到任何消息都说明连接正常,清除心跳超时检测 + this.clearHeartbeatTimeout(); + // 检查是否为心跳响应(支持字符串和JSON格式) let isHeartbeatResponse = false; @@ -69,8 +78,7 @@ class EnhancedWebSocket { } if (isHeartbeatResponse) { - // 收到心跳响应,清除超时定时器 - this.clearHeartbeatTimeout(); + // 心跳响应,不传递给业务代码 return; }