mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-02 17:32:50 +08:00
gateway: idle timeout applies to sockets opened after a change
Each socket keeps the IDLE_TIMEOUT_MINUTES it was told in its hello. Raising it from 0 in the admin panel used to drop already connected pages after a few minutes without asking, since they never learned they have to send "active". 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
958095fbf4
commit
9c67471b49
1 file changed
+8
-4
@@ -626,6 +626,10 @@ interface HeartbeatState {
|
||||
isAlive: boolean;
|
||||
/** Last "active" message (user input in the page) or connect. */
|
||||
lastActive: number;
|
||||
/** Idle timeout this socket was told in its hello. A later change in the
|
||||
* admin panel applies to new sockets only: older pages don't know they
|
||||
* must send "active" and would be dropped without being asked. */
|
||||
idleMs: number;
|
||||
}
|
||||
|
||||
/** IDLE_TIMEOUT_MINUTES in ms, 0 = off. Read per check, the admin panel changes it live. */
|
||||
@@ -656,8 +660,7 @@ const heartbeatTimer = setInterval(() => {
|
||||
socket.terminate();
|
||||
continue;
|
||||
}
|
||||
const idleMs = idleTimeoutMs();
|
||||
if (idleMs > 0 && Date.now() - state.lastActive > idleMs + IDLE_GRACE_MS) {
|
||||
if (state.idleMs > 0 && Date.now() - state.lastActive > state.idleMs + IDLE_GRACE_MS) {
|
||||
// Close handler disconnects the TS session; the message tells the page
|
||||
// this was deliberate, so it doesn't auto-reconnect.
|
||||
socket.send('{"type":"idleTimeout"}');
|
||||
@@ -748,16 +751,17 @@ wss.on("connection", (socket: WebSocket, req: IncomingMessage) => {
|
||||
// pulled, so the browser must not assume a feature exists just because it
|
||||
// knows about it. A gateway without "hello" (before v0.15) supports the
|
||||
// v0.14 feature set, streaming included; anything newer gets a name here.
|
||||
const idleMs = idleTimeoutMs();
|
||||
socket.send(
|
||||
JSON.stringify({
|
||||
type: "hello",
|
||||
features: gatewayFeatures(),
|
||||
iceServers: turnServers(),
|
||||
idleTimeoutMinutes: idleTimeoutMs() / 60_000,
|
||||
idleTimeoutMinutes: idleMs / 60_000,
|
||||
}),
|
||||
);
|
||||
|
||||
heartbeats.set(socket, { isAlive: true, lastActive: Date.now() });
|
||||
heartbeats.set(socket, { isAlive: true, lastActive: Date.now(), idleMs });
|
||||
socket.on("pong", () => {
|
||||
const state = heartbeats.get(socket);
|
||||
if (state) state.isAlive = true;
|
||||
|
||||
Reference in new issue
Block a user