summaryrefslogtreecommitdiff
path: root/packages/backend/src
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-06-09 17:07:57 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2023-06-09 17:07:57 +0900
commit6182a1cb2c80cce573a17193e9309fbbbce3b08c (patch)
tree18fb22b8aa452e788f1e08a9ea4930bf6cda53d8 /packages/backend/src
parentchore (diff)
downloadsharkey-6182a1cb2c80cce573a17193e9309fbbbce3b08c.tar.gz
sharkey-6182a1cb2c80cce573a17193e9309fbbbce3b08c.tar.bz2
sharkey-6182a1cb2c80cce573a17193e9309fbbbce3b08c.zip
enhance(backend): WebSocketのPing/Pongをプロトコル制御フレームの物で判別する
Resolve #10969
Diffstat (limited to 'packages/backend/src')
-rw-r--r--packages/backend/src/server/api/StreamingApiServerService.ts11
1 files changed, 5 insertions, 6 deletions
diff --git a/packages/backend/src/server/api/StreamingApiServerService.ts b/packages/backend/src/server/api/StreamingApiServerService.ts
index 2e554c9ad1..d1394d6d76 100644
--- a/packages/backend/src/server/api/StreamingApiServerService.ts
+++ b/packages/backend/src/server/api/StreamingApiServerService.ts
@@ -132,11 +132,8 @@ export class StreamingApiServerService {
if (userUpdateIntervalId) clearInterval(userUpdateIntervalId);
});
- connection.on('message', async (data) => {
+ connection.on('pong', () => {
this.#connections.set(connection, Date.now());
- if (data.toString() === 'ping') {
- connection.send('pong');
- }
});
});
@@ -144,12 +141,14 @@ export class StreamingApiServerService {
this.#cleanConnectionsIntervalId = setInterval(() => {
const now = Date.now();
for (const [connection, lastActive] of this.#connections.entries()) {
- if (now - lastActive > 1000 * 60 * 5) {
+ if (now - lastActive > 1000 * 60 * 2) {
connection.terminate();
this.#connections.delete(connection);
+ } else {
+ connection.ping();
}
}
- }, 1000 * 60 * 5);
+ }, 1000 * 60);
}
@bindThis