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 intentionalCloseRef = useRef(false);
|
||||
const lastFrameWasExitRef = useRef(false);
|
||||
const serverCleanCloseRef = useRef(false);
|
||||
const callbacksRef = useRef(new Set<(data: string) => void>());
|
||||
|
||||
const clearReconnectTimeout = useCallback(() => {
|
||||
@@ -157,6 +158,7 @@ export function useProcessWebSocket(
|
||||
ws.onopen = () => {
|
||||
reconnectAttemptsRef.current = 0;
|
||||
lastFrameWasExitRef.current = false;
|
||||
serverCleanCloseRef.current = false;
|
||||
setStatus("open");
|
||||
};
|
||||
|
||||
@@ -171,9 +173,19 @@ export function useProcessWebSocket(
|
||||
callbacksRef.current.forEach((cb) => cb(data));
|
||||
};
|
||||
|
||||
ws.onclose = () => {
|
||||
ws.onclose = (event) => {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user