ws/socket.io rooms - WIP

This commit is contained in:
Philipinho
2024-05-02 03:14:38 +01:00
parent 4c573b9bc2
commit beb6aa8d18

View File

@ -1,4 +1,5 @@
import {
MessageBody,
OnGatewayConnection,
SubscribeMessage,
WebSocketGateway,
@ -36,6 +37,21 @@ export class WsGateway implements OnGatewayConnection, OnModuleDestroy {
client.broadcast.emit('message', data);
}
@SubscribeMessage('messageToRoom')
handleSendMessageToRoom(@MessageBody() message: any) {
this.server.to(message?.roomId).emit('messageToRoom', message);
}
@SubscribeMessage('join-room')
handleJoinRoom(client: Socket, @MessageBody() roomName: string): void {
client.join(roomName);
}
@SubscribeMessage('leave-room')
handleLeaveRoom(client: Socket, @MessageBody() roomName: string): void {
client.leave(roomName);
}
onModuleDestroy() {
if (this.server) {
this.server.close();