import { SubscribeMessage , WebSocketGateway , WebSocketServer , MessageBody , WsResponse , } from '@nestjs/websockets' ; import { Server } from 'socket.io' ; import { Observable , from } from 'rxjs' ; import { map } from 'rxjs/operators' ; @ WebSocketGateway ( ) export class EventsGateway { @ WebSocketServer ( ) server : Server ; @ SubscribeMessage ( 'message' ) handleMessage ( client , payload ) { return 'Hello world!' ; } @ SubscribeMessage ( 'events' ) findAll ( @ MessageBody ( ) data ) { return from ( [ 1 , 2 , 3 ] ) . pipe ( map ( item => ( { event : 'events' , data : item } ) ) ) ; } @ SubscribeMessage ( 'identity' ) async identity ( @ MessageBody ( ) data ) { return data ; } }