File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change 1- import { SubscribeMessage , WebSocketGateway } from '@nestjs/websockets' ;
1+ import { ZodPipe } from '@/shared/pipes/zod.pipe' ;
2+ import {
3+ ConnectedSocket ,
4+ MessageBody ,
5+ SubscribeMessage ,
6+ WebSocketGateway ,
7+ } from '@nestjs/websockets' ;
28import { Socket } from 'socket.io' ;
9+ import { z } from 'zod' ;
10+
11+ const joinRoomSchema = z . string ( ) ;
12+ const leaveRoomSchema = z . string ( ) ;
313
414@WebSocketGateway ( )
515export class RoomsGateway {
616 @SubscribeMessage ( 'join' )
7- join ( client : Socket , room : string ) : string [ ] {
17+ join (
18+ @ConnectedSocket ( ) client : Socket ,
19+ @MessageBody ( new ZodPipe ( joinRoomSchema ) )
20+ room : z . infer < typeof joinRoomSchema > ,
21+ ) : string [ ] {
822 client . join ( room ) ;
923 return Array . from ( client . rooms ) ;
1024 }
1125
1226 @SubscribeMessage ( 'leave' )
13- leave ( client : Socket , room : string ) : string [ ] {
27+ leave (
28+ @ConnectedSocket ( ) client : Socket ,
29+ @MessageBody ( new ZodPipe ( leaveRoomSchema ) )
30+ room : z . infer < typeof leaveRoomSchema > ,
31+ ) : string [ ] {
1432 client . leave ( room ) ;
1533 return Array . from ( client . rooms ) ;
1634 }
You can’t perform that action at this time.
0 commit comments