fix(web): treat server clean close as session end without reconnect
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -111,6 +111,7 @@ export function useProcessWebSocket(
|
|||||||
const reconnectTimeoutRef = useRef<number | null>(null);
|
const reconnectTimeoutRef = useRef<number | null>(null);
|
||||||
const intentionalCloseRef = useRef(false);
|
const intentionalCloseRef = useRef(false);
|
||||||
const lastFrameWasExitRef = useRef(false);
|
const lastFrameWasExitRef = useRef(false);
|
||||||
|
const serverCleanCloseRef = useRef(false);
|
||||||
const callbacksRef = useRef(new Set<(data: string) => void>());
|
const callbacksRef = useRef(new Set<(data: string) => void>());
|
||||||
|
|
||||||
const clearReconnectTimeout = useCallback(() => {
|
const clearReconnectTimeout = useCallback(() => {
|
||||||
@@ -157,6 +158,7 @@ export function useProcessWebSocket(
|
|||||||
ws.onopen = () => {
|
ws.onopen = () => {
|
||||||
reconnectAttemptsRef.current = 0;
|
reconnectAttemptsRef.current = 0;
|
||||||
lastFrameWasExitRef.current = false;
|
lastFrameWasExitRef.current = false;
|
||||||
|
serverCleanCloseRef.current = false;
|
||||||
setStatus("open");
|
setStatus("open");
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -171,9 +173,19 @@ export function useProcessWebSocket(
|
|||||||
callbacksRef.current.forEach((cb) => cb(data));
|
callbacksRef.current.forEach((cb) => cb(data));
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = () => {
|
ws.onclose = (event) => {
|
||||||
socketRef.current = null;
|
socketRef.current = null;
|
||||||
if (intentionalCloseRef.current || lastFrameWasExitRef.current) {
|
if (
|
||||||
|
(event.code === 1000 || event.code === 1001) &&
|
||||||
|
!intentionalCloseRef.current
|
||||||
|
) {
|
||||||
|
serverCleanCloseRef.current = true;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
intentionalCloseRef.current ||
|
||||||
|
lastFrameWasExitRef.current ||
|
||||||
|
serverCleanCloseRef.current
|
||||||
|
) {
|
||||||
setStatus("closed");
|
setStatus("closed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user