refactor(websocket): 优化计时器类型声明,避免使用 any 类型
This commit is contained in:
@@ -41,9 +41,9 @@ export function useStomp(options: UseStompOptions = {}) {
|
|||||||
// 重连尝试次数
|
// 重连尝试次数
|
||||||
const reconnectCount = ref(0);
|
const reconnectCount = ref(0);
|
||||||
// 重连计时器
|
// 重连计时器
|
||||||
let reconnectTimer: any = null;
|
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
// 连接超时计时器
|
// 连接超时计时器
|
||||||
let connectionTimeoutTimer: any = null;
|
let connectionTimeoutTimer: ReturnType<typeof setTimeout> | null = null;
|
||||||
// 存储所有订阅
|
// 存储所有订阅
|
||||||
const subscriptions = new Map<string, StompSubscription>();
|
const subscriptions = new Map<string, StompSubscription>();
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ export function useStomp(options: UseStompOptions = {}) {
|
|||||||
isConnected.value = true;
|
isConnected.value = true;
|
||||||
isConnecting = false;
|
isConnecting = false;
|
||||||
reconnectCount.value = 0;
|
reconnectCount.value = 0;
|
||||||
clearTimeout(connectionTimeoutTimer);
|
if (connectionTimeoutTimer) clearTimeout(connectionTimeoutTimer);
|
||||||
clearTimeout(reconnectTimer);
|
if (reconnectTimer) clearTimeout(reconnectTimer);
|
||||||
console.log("WebSocket连接已建立");
|
console.log("WebSocket连接已建立");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ export function useStomp(options: UseStompOptions = {}) {
|
|||||||
isConnecting = true;
|
isConnecting = true;
|
||||||
|
|
||||||
// 设置连接超时
|
// 设置连接超时
|
||||||
clearTimeout(connectionTimeoutTimer);
|
if (connectionTimeoutTimer) clearTimeout(connectionTimeoutTimer);
|
||||||
connectionTimeoutTimer = setTimeout(() => {
|
connectionTimeoutTimer = setTimeout(() => {
|
||||||
if (!isConnected.value && isConnecting) {
|
if (!isConnected.value && isConnecting) {
|
||||||
console.warn("WebSocket连接超时");
|
console.warn("WebSocket连接超时");
|
||||||
|
|||||||
Reference in New Issue
Block a user