mirror of
https://github.com/Moepchi/webspeak3.git
synced 2026-12-03 01:42:50 +08:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c67471b49 |
@@ -626,6 +626,10 @@ interface HeartbeatState {
|
|||||||
isAlive: boolean;
|
isAlive: boolean;
|
||||||
/** Last "active" message (user input in the page) or connect. */
|
/** Last "active" message (user input in the page) or connect. */
|
||||||
lastActive: number;
|
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. */
|
/** 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();
|
socket.terminate();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const idleMs = idleTimeoutMs();
|
if (state.idleMs > 0 && Date.now() - state.lastActive > state.idleMs + IDLE_GRACE_MS) {
|
||||||
if (idleMs > 0 && Date.now() - state.lastActive > idleMs + IDLE_GRACE_MS) {
|
|
||||||
// Close handler disconnects the TS session; the message tells the page
|
// Close handler disconnects the TS session; the message tells the page
|
||||||
// this was deliberate, so it doesn't auto-reconnect.
|
// this was deliberate, so it doesn't auto-reconnect.
|
||||||
socket.send('{"type":"idleTimeout"}');
|
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
|
// 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
|
// knows about it. A gateway without "hello" (before v0.15) supports the
|
||||||
// v0.14 feature set, streaming included; anything newer gets a name here.
|
// v0.14 feature set, streaming included; anything newer gets a name here.
|
||||||
|
const idleMs = idleTimeoutMs();
|
||||||
socket.send(
|
socket.send(
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
type: "hello",
|
type: "hello",
|
||||||
features: gatewayFeatures(),
|
features: gatewayFeatures(),
|
||||||
iceServers: turnServers(),
|
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", () => {
|
socket.on("pong", () => {
|
||||||
const state = heartbeats.get(socket);
|
const state = heartbeats.get(socket);
|
||||||
if (state) state.isAlive = true;
|
if (state) state.isAlive = true;
|
||||||
|
|||||||
Reference in new issue
Block a user