Skip to content

Commit a1c0e87

Browse files
authored
Merge pull request #86 from tiagosiebler/heartbeatdisable
feat(v3.0.4): implement mechanism to disable heartbeat
2 parents 97019be + f97e782 commit a1c0e87

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bitget-api",
3-
"version": "3.0.3",
3+
"version": "3.0.4",
44
"description": "Complete Node.js & JavaScript SDK for Bitget V1-V3 REST APIs & WebSockets, with TypeScript & end-to-end tests.",
55
"scripts": {
66
"test": "jest",

src/types/websockets/ws-general.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export interface WSClientConfigurableOptions {
186186
/** Define a recv window when preparing a private websocket signature. This is in milliseconds, so 5000 == 5 seconds */
187187
recvWindow?: number;
188188

189-
// Disable ping/pong ws heartbeat mechanism (not recommended) // TODO:
189+
// Disable ping/pong ws heartbeat mechanism (not recommended)
190190
disableHeartbeat?: boolean;
191191

192192
/** How often to check if the connection is alive */

src/util/BaseWSClient.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -864,11 +864,13 @@ export abstract class BaseWebsocketClient<
864864

865865
this.setWsState(wsKey, WsConnectionStateEnum.CONNECTED);
866866

867-
this.logger.trace('Enabled ping timer', { ...WS_LOGGER_CATEGORY, wsKey });
868-
this.wsStore.get(wsKey, true)!.activePingTimer = setInterval(
869-
() => this.ping(wsKey),
870-
this.options.pingInterval,
871-
);
867+
if (!this.options.disableHeartbeat) {
868+
this.logger.trace('Enabled ping timer', { ...WS_LOGGER_CATEGORY, wsKey });
869+
this.wsStore.get(wsKey, true)!.activePingTimer = setInterval(
870+
() => this.ping(wsKey),
871+
this.options.pingInterval,
872+
);
873+
}
872874

873875
// Resolve & cleanup deferred "connection attempt in progress" promise
874876
try {

src/util/websocket-util.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export function safeTerminateWs(
270270

271271
return false;
272272
}
273+
273274
/**
274275
* Users can conveniently pass topics as strings or objects (object has topic name + optional params).
275276
*

0 commit comments

Comments
 (0)