fix: 优化WebSocket配置,调整心跳间隔和超时时间,提升连接稳定性;更新画布最小缩放比例,确保更灵活的缩放体验

This commit is contained in:
xudan 2025-06-20 09:03:15 +08:00
parent 534befd88b
commit cc919b23e3
2 changed files with 16 additions and 8 deletions

View File

@ -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% */

View File

@ -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;
}