Skip to content

Commit

Permalink
fix(platform-ws): trigger client disconnected hook #2226
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed May 19, 2019
1 parent d6b31c3 commit fc40f21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/platform-ws/adapters/ws-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ export class WsAdapter extends AbstractWsAdapter {
handlers: MessageMappingProperties[],
transform: (data: any) => Observable<any>,
) {
const close$ = fromEvent(client, CLOSE_EVENT).pipe(share(), first());
const close$ = fromEvent(client, CLOSE_EVENT).pipe(
share(),
first(),
);
const source$ = fromEvent(client, 'message').pipe(
mergeMap(data =>
this.bindMessageHandler(data, handlers, transform).pipe(
Expand Down Expand Up @@ -97,4 +100,8 @@ export class WsAdapter extends AbstractWsAdapter {
server.on(ERROR_EVENT, (err: any) => this.logger.error(err));
return server;
}

public bindClientDisconnect(client: any, callback: Function) {
client.on(CLOSE_EVENT, callback);
}
}
1 change: 1 addition & 0 deletions sample/03-microservices/src/math/math.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Transport } from '@nestjs/common/enums/transport.enum';
import { ClientsModule } from '@nestjs/microservices';
import { MATH_SERVICE } from './math.constants';
import { MathController } from './math.controller';

@Module({
imports: [
ClientsModule.register([{ name: MATH_SERVICE, transport: Transport.TCP }]),
Expand Down

0 comments on commit fc40f21

Please sign in to comment.