aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-05-30 01:38:08 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-07-12 01:19:36 +0800
commit0c120cb7a3a7796504e577a99452ea8909989cfc (patch)
treed192465667a56ed0af95366b919ccabe00221b0d /packages
parentcab6829df9063c698f91d2fb03bdbd81999843d1 (diff)
downloaddexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar.gz
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar.bz2
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar.lz
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar.xz
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.tar.zst
dexon-sol-tools-0c120cb7a3a7796504e577a99452ea8909989cfc.zip
Assert that connection is opening before attempting to subscribe
Diffstat (limited to 'packages')
-rw-r--r--packages/connect/src/ws_orderbook_channel.ts11
1 files changed, 2 insertions, 9 deletions
diff --git a/packages/connect/src/ws_orderbook_channel.ts b/packages/connect/src/ws_orderbook_channel.ts
index f90d9ac30..45d1b35d7 100644
--- a/packages/connect/src/ws_orderbook_channel.ts
+++ b/packages/connect/src/ws_orderbook_channel.ts
@@ -51,6 +51,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
public subscribe(subscriptionOpts: OrderbookChannelSubscriptionOpts, handler: OrderbookChannelHandler): void {
assert.isOrderbookChannelSubscriptionOpts('subscriptionOpts', subscriptionOpts);
assert.isOrderbookChannelHandler('handler', handler);
+ assert.assert(this._client.readyState === WebSocket.w3cwebsocket.OPEN, 'WebSocket connection is closed');
const newSubscription: Subscription = {
subscriptionOpts,
handler,
@@ -62,7 +63,7 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
requestId: this._subscriptions.length - 1,
payload: subscriptionOpts,
};
- this._sendMessage(subscribeMessage);
+ this._client.send(JSON.stringify(subscribeMessage));
}
/**
* Close the websocket and stop receiving updates
@@ -71,14 +72,6 @@ export class WebSocketOrderbookChannel implements OrderbookChannel {
this._client.close();
}
/**
- * Send a message to the client if it has been instantiated and it is open
- */
- private _sendMessage(message: any): void {
- if (this._client.readyState === WebSocket.w3cwebsocket.OPEN) {
- this._client.send(JSON.stringify(message));
- }
- }
- /**
* For use in cases where we need to alert all handlers of an error
*/
private _alertAllHandlersToError(error: Error): void {