update ip address to company's

This commit is contained in:
2025-10-27 15:47:04 +08:00
parent aacbe5c31c
commit 9ede603c9f
2 changed files with 26 additions and 9 deletions

View File

@@ -96,9 +96,15 @@ export const useEventNotifications = (options = {}) => {
if (alreadyConnected) {
// 如果已经连接,直接更新状态
console.log('[useEventNotifications DEBUG] Socket已连接直接更新状态');
logger.info('useEventNotifications', 'Socket already connected, updating state immediately');
setIsConnected(true);
// 验证状态更新
setTimeout(() => {
console.log('[useEventNotifications DEBUG] 1秒后验证状态更新 - isConnected应该为true');
}, 1000);
} else {
// 否则建立新连接
console.log('[useEventNotifications DEBUG] Socket未连接开始连接...');
socketService.connect();
}
@@ -164,14 +170,25 @@ export const useEventNotifications = (options = {}) => {
socketService.off('disconnect', handleDisconnect);
socketService.off('connect_error', handleConnectError);
// 断开连接
console.log('[useEventNotifications DEBUG] 断开 WebSocket 连接...');
socketService.disconnect();
// 注意:不断开连接
// socketService 是全局单例,可能被多个组件使用
// 断开连接会影响其他组件,所以只移除监听器和取消订阅
console.log('[useEventNotifications DEBUG] ⚠️ 保持连接socketService是全局单例');
// socketService.disconnect(); // 注释掉,不主动断开
console.log('[useEventNotifications DEBUG] ========== 清理完成 ==========\n');
};
}, [eventType, importance, enabled]); // 移除 onNewEvent 依赖
// 监控 isConnected 状态变化(调试用)
useEffect(() => {
console.log('[useEventNotifications DEBUG] ========== isConnected 状态变化 ==========');
console.log('[useEventNotifications DEBUG] isConnected:', isConnected);
console.log('[useEventNotifications DEBUG] ===========================================');
}, [isConnected]);
console.log('[useEventNotifications DEBUG] Hook返回值 - isConnected:', isConnected);
return {
newEvent, // 最新收到的事件
isConnected, // WebSocket 连接状态