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 | |
parent | c4bcf24640a6fafa214e37543df90f3df36a301f (diff) | |
download | dexon-sol-tools-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.gz dexon-sol-tools-6d818c25c7d88a297a11bb983b52bd08ac7b856d.tar.zst dexon-sol-tools-6d818c25c7d88a297a11bb983b52bd08ac7b856d.zip |
Add an enforced minimum for the heartbeat interval
Diffstat (limited to 'packages/connect')
-rw-r--r-- | packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts | 5 | ||||
-rw-r--r-- | packages/connect/src/ws_orderbook_channel.ts | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts b/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts index 2e9987e63..81c0cac9c 100644 --- a/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts +++ b/packages/connect/src/schemas/websocket_orderbook_channel_config_schema.ts @@ -2,6 +2,9 @@ export const webSocketOrderbookChannelConfigSchema = { id: '/WebSocketOrderbookChannelConfig', type: 'object', properties: { - heartbeatIntervalMs: { type: 'number' }, + heartbeatIntervalMs: { + type: 'number', + minimum: 10, + }, }, }; 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); }); |