refactor: ♻️ 添加 websocket 开启控制,未配置 endpoint 不连接,单例控制 websocket 重复连接

This commit is contained in:
Ray.Hao
2025-04-29 23:37:13 +08:00
parent ea6323084c
commit 142d808a5e
4 changed files with 46 additions and 17 deletions

View File

@@ -24,9 +24,10 @@ function createDictSyncHook() {
// 使用现有的useStomp配置适合字典场景的重连参数
const { isConnected, connect, subscribe, unsubscribe, disconnect } = useStomp({
reconnectDelay: 10000, // 使用更长的重连延迟 - 10秒
connectionTimeout: 15000, // 更长的连接超时时间 - 15秒
useExponentialBackoff: false, // 字典数据不需要指数退避策略
reconnectDelay: 20000, // 字典更新重连时间
connectionTimeout: 15000, // 连接超时阈值
useExponentialBackoff: false, // 使用固定间隔重连策略
maxReconnectAttempts: 3, // 最多重连3次
});
// 存储订阅ID
@@ -101,8 +102,8 @@ function createDictSyncHook() {
const attemptSubscribe = () => {
if (!isConnected.value) {
console.log("等待WebSocket连接建立...");
// 3秒后再次尝试
setTimeout(attemptSubscribe, 3000);
// 10秒后再次尝试
setTimeout(attemptSubscribe, 10000);
return;
}