From 72a8725b2121a729081d6f117c7c84905038df64 Mon Sep 17 00:00:00 2001 From: anonanonimus Date: Wed, 10 Oct 2018 18:18:58 +0500 Subject: [PATCH] websockets(bug) send message to client only in open state sending messages to ws client only if it in open state no breaking changes --- packages/websockets/adapters/ws-adapter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/websockets/adapters/ws-adapter.ts b/packages/websockets/adapters/ws-adapter.ts index 3983d1d92a0..dd7451e0d80 100644 --- a/packages/websockets/adapters/ws-adapter.ts +++ b/packages/websockets/adapters/ws-adapter.ts @@ -14,6 +14,13 @@ import { MessageMappingProperties } from '../gateway-metadata-explorer'; let wsPackage: any = {}; +enum READY_STATE { + CONNECTING_STATE = 0, + OPEN_STATE = 1, + CLOSING_STATE = 2, + CLOSED_STATE = 3, +} + export class WsAdapter implements WebSocketAdapter { protected readonly logger = new Logger(WsAdapter.name); protected readonly httpServer: Server; @@ -72,7 +79,11 @@ export class WsAdapter implements WebSocketAdapter { ), takeUntil(close$), ); - source$.subscribe(response => client.send(JSON.stringify(response))); + source$.subscribe(response => { + if (client.readyState === READY_STATE.OPEN_STATE) { + client.send(JSON.stringify(response)); + } + }); } public bindMessageHandler(