aboutsummaryrefslogtreecommitdiffstats
path: root/packages/connect
diff options
context:
space:
mode:
Diffstat (limited to 'packages/connect')
-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 {