mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-01 08:52:51 +08:00
Compare commits
1
Commits
v0.16.0-beta.19
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c67471b49 |
@@ -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