mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 09:52:50 +08:00
Rejoin the last channel after an automatic reconnect
A dropped gateway connection reconnected with the original connect
parameters, so everyone landed in the server's default channel again.
The reconnect now aims at the channel the user was in ("/<id>"), with
its cached password if one was entered.
The client log also records why a gateway connection ended: the
WebSocket close code, or the keepalive watchdog firing. Until now a drop
left no trace on the client side.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
1 parent
7d14c3409e
commit
983ce1e105
1 file changed
+16
-2
+16
-2
@@ -8000,14 +8000,17 @@ function AppInner() {
|
|||||||
// detach and run the drop handling right away.
|
// detach and run the drop handling right away.
|
||||||
socket.onmessage = socket.onerror = socket.onclose = null;
|
socket.onmessage = socket.onerror = socket.onclose = null;
|
||||||
socket.close();
|
socket.close();
|
||||||
|
logClient("warning", "Connection", `No keepalive from the gateway for ${KEEPALIVE_TIMEOUT_MS / 1000} s`);
|
||||||
current().onclose();
|
current().onclose();
|
||||||
}, KEEPALIVE_TIMEOUT_MS);
|
}, KEEPALIVE_TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
if (event.data !== KEEPALIVE_MESSAGE) current().onmessage(event);
|
if (event.data !== KEEPALIVE_MESSAGE) current().onmessage(event);
|
||||||
};
|
};
|
||||||
socket.onerror = () => current().onerror();
|
socket.onerror = () => current().onerror();
|
||||||
socket.onclose = () => {
|
socket.onclose = (event) => {
|
||||||
clearTimeout(watchdog);
|
clearTimeout(watchdog);
|
||||||
|
// 1000/1001 are clean closes; 1006 means the link died without a close frame.
|
||||||
|
logClient("info", "Connection", `Gateway connection closed (code ${event.code ?? "?"})`);
|
||||||
current().onclose();
|
current().onclose();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -8113,7 +8116,7 @@ function AppInner() {
|
|||||||
// network blip, or the page coming back from being backgrounded/suspended
|
// network blip, or the page coming back from being backgrounded/suspended
|
||||||
// — without disturbing which tab is active or losing chat/scroll history.
|
// — without disturbing which tab is active or losing chat/scroll history.
|
||||||
const reconnectSession = (sessionId: string) => {
|
const reconnectSession = (sessionId: string) => {
|
||||||
const params = sessionParamsRef.current.get(sessionId);
|
let params = sessionParamsRef.current.get(sessionId);
|
||||||
const rec = sessionsRef.current.get(sessionId);
|
const rec = sessionsRef.current.get(sessionId);
|
||||||
if (!params || !rec) return;
|
if (!params || !rec) return;
|
||||||
// Already open or mid-(re)connect — nothing to do.
|
// Already open or mid-(re)connect — nothing to do.
|
||||||
@@ -8121,6 +8124,17 @@ function AppInner() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Come back in the channel we were in, like the native client does. Kept
|
||||||
|
// in the params so a failed attempt (empty client list) still aims there.
|
||||||
|
const isActive = sessionId === activeSessionIdRef.current;
|
||||||
|
const state = isActive ? { clients, ownClientId } : rec.parked;
|
||||||
|
const lastChannel = state?.clients.find((c) => c.id === state.ownClientId)?.channel;
|
||||||
|
if (lastChannel) {
|
||||||
|
const cachedPassword = isActive ? channelPasswordCacheRef.current.get(lastChannel) : undefined;
|
||||||
|
params = { ...params, defaultChannel: `/${lastChannel}`, channelPassword: cachedPassword ?? params.channelPassword };
|
||||||
|
sessionParamsRef.current.set(sessionId, params);
|
||||||
|
}
|
||||||
|
|
||||||
logClient("info", "Connection", `Reconnecting to ${params.host}…`);
|
logClient("info", "Connection", `Reconnecting to ${params.host}…`);
|
||||||
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
const socket = DEMO_MODE ? new DemoSocket() : new WebSocket(GATEWAY_URL);
|
||||||
rec.socket = socket;
|
rec.socket = socket;
|
||||||
|
|||||||
Reference in new issue
Block a user