Skip to content

Commit

Permalink
Refactor ping packet handling in WebsocketTransport
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
URVL committed Dec 5, 2024
1 parent 5fa6abe commit 4b0afc7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 4b0afc7

Please sign in to comment.