ws reconnect
This commit is contained in:
parent
14f611e796
commit
19d020faec
@ -113,16 +113,25 @@ export function WSProvider({ children }: MapProviderProps) {
|
||||
|
||||
// 监听订阅状态变化
|
||||
useEffect(() => {
|
||||
if (loading && wsStatus !== WsStatus.CONNECTING) {
|
||||
setWsStatus(WsStatus.CONNECTING);
|
||||
if (loading) {
|
||||
// 只在第一次加载时设置为 connecting,避免覆盖 WebSocket 的实际状态
|
||||
if (connectionState.status === 'disconnected') {
|
||||
setWsStatus(WsStatus.CONNECTING);
|
||||
}
|
||||
} else if (error && !loading) {
|
||||
if (isOnline) {
|
||||
console.error('WebSocket subscription error:', error);
|
||||
if (isOnline && connectionState.status !== 'reconnecting') {
|
||||
setTimeout(() => {
|
||||
restart();
|
||||
}, 5000);
|
||||
}
|
||||
} else if (!loading && !error && data) {
|
||||
// 确保在有数据时状态是 connected
|
||||
if (wsStatus !== WsStatus.CONNECTED) {
|
||||
setWsStatus(WsStatus.CONNECTED);
|
||||
}
|
||||
}
|
||||
}, [loading, error, isOnline, restart, wsStatus]);
|
||||
}, [loading, error, data, isOnline, restart, wsStatus, connectionState.status]);
|
||||
|
||||
const forceReconnect = () => {
|
||||
Sentry.startSpan({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user