Better typing of message handler

master
Kevin C. Coram 2020-10-12 12:09:02 -04:00
parent 768882cacc
commit 2ef8c15f63
Signed by: kevin
GPG Key ID: 0E64ECB9EDE572A3
1 changed files with 3 additions and 3 deletions

View File

@ -10,8 +10,8 @@ import {
WebSocketGateway, WebSocketGateway,
WebSocketServer, WebSocketServer,
} from '@nestjs/websockets'; } from '@nestjs/websockets';
import { Server } from 'http';
import { AppService } from './app.service'; import { AppService } from './app.service';
import { Server,Socket } from 'socket.io';
@WebSocketGateway(4001) @WebSocketGateway(4001)
export class AppGateway implements OnGatewayConnection { export class AppGateway implements OnGatewayConnection {
@ -22,12 +22,12 @@ export class AppGateway implements OnGatewayConnection {
constructor(private appService: AppService) {} constructor(private appService: AppService) {}
handleConnection(client: any, ...args: any[]) { handleConnection(client: Socket, ...args: any[]) {
client.emit(MESSAGE_TO_CLIENT, this.appService.getMessages()); client.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
} }
@SubscribeMessage(MESSAGE_TO_SERVER) @SubscribeMessage(MESSAGE_TO_SERVER)
handleMessage(client: any, payload: Message): void { handleMessage(client: Socket, payload: Message): void {
this.logger.log(payload); this.logger.log(payload);
this.appService.addMessage(payload); this.appService.addMessage(payload);
this.wss.emit(MESSAGE_TO_CLIENT, this.appService.getMessages()); this.wss.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());