Compare commits

..

No commits in common. "96b9eac4f7c9f388865fffea1a4aa2a05a5ddb0d" and "768882cacc59b4cc114cb3d29aebef0dba7eb8ef" have entirely different histories.

1 changed files with 4 additions and 16 deletions

View File

@ -6,18 +6,15 @@ import {
import { Logger } from '@nestjs/common';
import {
OnGatewayConnection,
OnGatewayDisconnect,
OnGatewayInit,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
} from '@nestjs/websockets';
import { Server } from 'http';
import { AppService } from './app.service';
import { Server, Socket } from 'socket.io';
@WebSocketGateway(4001)
export class AppGateway
implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect {
export class AppGateway implements OnGatewayConnection {
@WebSocketServer()
wss: Server;
@ -25,21 +22,12 @@ export class AppGateway
constructor(private appService: AppService) {}
afterInit(server: Server) {
this.logger.log('Initialized...');
}
handleConnection(client: Socket, ...args: any[]) {
this.logger.log(`Client connected: ${client.id}`);
handleConnection(client: any, ...args: any[]) {
client.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());
}
handleDisconnect(client: Socket) {
this.logger.log(`Client disconnected: ${client.id}`);
}
@SubscribeMessage(MESSAGE_TO_SERVER)
handleMessage(client: Socket, payload: Message): void {
handleMessage(client: any, payload: Message): void {
this.logger.log(payload);
this.appService.addMessage(payload);
this.wss.emit(MESSAGE_TO_CLIENT, this.appService.getMessages());