import { SubscribeMessage , WebSocketGateway , OnGatewayInit , WebSocketServer , OnGatewayConnection , OnGatewayDisconnect } from '@nestjs/websockets' ; import { Logger } from '@nestjs/common' ; import { Socket , Server } from 'socket.io' ; @ WebSocketGateway ( ) export class ChatsGateway implements OnGatewayInit , OnGatewayConnection , OnGatewayDisconnect { @ WebSocketServer ( ) server : Server ; private logger : Logger = new Logger ( 'AppGateway' ) ; @ SubscribeMessage ( 'msgToServer' ) handleMessage ( client , payload ) { this . server . emit ( 'msgToClient' , payload ) ; } afterInit ( server ) { this . logger . log ( 'Init' ) ; } handleDisconnect ( client ) { this . logger . log ( `Client disconnected: ${ client . id }` ) ; } handleConnection ( client , ... args ) { this . logger . log ( `Client connected: ${ client . id }` ) ; } }