diff options
author | Brandon Millman <brandon.millman@gmail.com> | 2018-02-16 23:48:15 +0800 |
---|---|---|
committer | Brandon Millman <brandon.millman@gmail.com> | 2018-02-16 23:48:15 +0800 |
commit | 6d818c25c7d88a297a11bb983b52bd08ac7b856d (patch) | |
tree | fe3c8efe8348b6ffdf135cc7e31c0b7e0e4889f8 /packages/connect/src/ws_orderbook_channel.ts | |
parent | c4bcf24640a6fafa214e37543df90f3df36a301f (diff) | |
download | dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.gz dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.bz2 dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.lz dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.xz dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.zst dexon-0x-contracts-6d818c25c7d88a297a11bb983b52bd08ac7b856d.zip |
Add an enforced minimum for the heartbeat interval
Diffstat (limited to 'packages/connect/src/ws_orderbook_channel.ts')
-rw-r--r-- | packages/connect/src/ws_orderbook_channel.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts index 564e8686b..607749e86 100644 --- a/packages/connect/src/ws_orderbook_channel.ts +++ b/packages/connect/src/ws_orderbook_channel.ts @@ -16,6 +16,7 @@ import { import { orderbookChannelMessageParser } from './utils/orderbook_channel_message_parser'; const DEFAULT_HEARTBEAT_INTERVAL_MS = 15000; +const MINIMUM_HEARTBEAT_INTERVAL_MS = 10; /** * This class includes all the functionality related to interacting with a websocket endpoint @@ -104,10 +105,19 @@ export class WebSocketOrderbookChannel implements OrderbookChannel { } else { this._client.on(WebsocketClientEventType.Connect, connection => { this._connectionIfExists = connection; - if (this._heartbeatIntervalMs !== 0) { + if (this._heartbeatIntervalMs >= MINIMUM_HEARTBEAT_INTERVAL_MS) { this._heartbeatTimerIfExists = setInterval(() => { connection.ping(''); }, this._heartbeatIntervalMs); + } else { + callback( + new Error( + `Heartbeat interval is ${ + this._heartbeatIntervalMs + }ms which is less than the required minimum of ${MINIMUM_HEARTBEAT_INTERVAL_MS}ms`, + ), + undefined, + ); } callback(undefined, this._connectionIfExists); }); |