Skip to content

Commit 4b0afc7

Browse files
committed
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.
1 parent 5fa6abe commit 4b0afc7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { MetaWritable, MetaReadable, chunkDecode } = require('./streams.js');
77
const CALL_TIMEOUT = 7 * 1000;
88
const PING_INTERVAL = 60 * 1000;
99
const RECONNECT_TIMEOUT = 2 * 1000;
10-
const PING_PACKET = Buffer.from('{}');
10+
const PING_PACKET = {};
1111

1212
const connections = new Set();
1313

@@ -216,7 +216,7 @@ class WebsocketTransport extends Metacom {
216216
this.ping = setInterval(() => {
217217
if (this.active) {
218218
const interval = Date.now() - this.lastActivity;
219-
if (interval > this.pingInterval) this.write(PING_PACKET);
219+
if (interval > this.pingInterval) this.send(PING_PACKET);
220220
}
221221
}, this.pingInterval);
222222

0 commit comments

Comments
 (0)