From 4b0afc77c3abae81403fbff5f22ebae737dc500c Mon Sep 17 00:00:00 2001 From: fkreatovich <51157377+URVL@users.noreply.github.com> Date: Thu, 5 Dec 2024 17:39:08 +0200 Subject: [PATCH] Refactor ping packet handling in WebsocketTransport - Changed PING_PACKET from a Buffer to an object for improved clarity. - Updated the method call from `this.write(PING_PACKET)` to `this.send(PING_PACKET)` to reflect the new structure. This change enhances the readability and maintainability of the code related to pinging in the WebSocket transport layer. --- lib/client.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 56cec5ad..91b9fcb6 100644 --- a/lib/client.js +++ b/lib/client.js @@ -7,7 +7,7 @@ const { MetaWritable, MetaReadable, chunkDecode } = require('./streams.js'); const CALL_TIMEOUT = 7 * 1000; const PING_INTERVAL = 60 * 1000; const RECONNECT_TIMEOUT = 2 * 1000; -const PING_PACKET = Buffer.from('{}'); +const PING_PACKET = {}; const connections = new Set(); @@ -216,7 +216,7 @@ class WebsocketTransport extends Metacom { this.ping = setInterval(() => { if (this.active) { const interval = Date.now() - this.lastActivity; - if (interval > this.pingInterval) this.write(PING_PACKET); + if (interval > this.pingInterval) this.send(PING_PACKET); } }, this.pingInterval);