Skip to content

Commit

Permalink
Merge branch 'fix-ws-client-closing' of https://github.com/spaiter/nest
Browse files Browse the repository at this point in the history
… into spaiter-fix-ws-client-closing
  • Loading branch information
kamilmysliwiec committed Oct 17, 2018
2 parents 6dda6c5 + 72a8725 commit 3e9bfff
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/websockets/adapters/ws-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 3e9bfff

Please sign in to comment.