Skip to content

Commit

Permalink
Merge e3b9122 into 8d62307
Browse files Browse the repository at this point in the history
  • Loading branch information
tannineo committed Jul 9, 2018
2 parents 8d62307 + e3b9122 commit 637e09d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/websockets/interfaces/nest-gateway.interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface NestGateway {
afterInit?: (server: any) => void;
handleConnection?: (client: any) => void;
handleConnection?: (client: any, ...rest: any[]) => void;
handleDisconnect?: (client: any) => void;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface OnGatewayConnection<T = any> {
handleConnection(client: T);
handleConnection(client: T, ...rest: any[]);
}
2 changes: 1 addition & 1 deletion packages/websockets/test/web-sockets-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('WebSocketsController', () => {
).to.be.a('function');
});
it('should call "next" method of connection object with expected argument', () => {
expect(nextSpy.calledWith(client)).to.be.true;
expect(nextSpy.calledWith([client])).to.be.true;
});
it('should call "subscribeMessages" with expected arguments', () => {
expect(subscribeMessages.calledWith(handlers, client, gateway)).to.be
Expand Down
13 changes: 8 additions & 5 deletions packages/websockets/web-sockets-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ export class WebSocketsController {
connection: Subject<any>,
) {
const adapter = this.config.getIoAdapter();
return client => {
connection.next(client);
return (client, ...rest) => {
// here different websocket implements may have different args
// `ws` will have two args applied to this callback
connection.next([client, ...rest]);

context.subscribeMessages(messageHandlers, client, instance);

const disconnectHook = adapter.bindClientDisconnect;
Expand All @@ -121,9 +124,9 @@ export class WebSocketsController {

public subscribeConnectionEvent(instance: NestGateway, event: Subject<any>) {
if (instance.handleConnection) {
event
.pipe(distinctUntilChanged())
.subscribe(instance.handleConnection.bind(instance));
event.pipe(distinctUntilChanged()).subscribe((args: any[]) => {
instance.handleConnection.bind(instance)(...args);
});
}
}

Expand Down

0 comments on commit 637e09d

Please sign in to comment.