ws/socket.io rooms - WIP
This commit is contained in:
parent
4c573b9bc2
commit
beb6aa8d18
1 changed files with 16 additions and 0 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
MessageBody,
|
||||||
OnGatewayConnection,
|
OnGatewayConnection,
|
||||||
SubscribeMessage,
|
SubscribeMessage,
|
||||||
WebSocketGateway,
|
WebSocketGateway,
|
||||||
|
|
@ -36,6 +37,21 @@ export class WsGateway implements OnGatewayConnection, OnModuleDestroy {
|
||||||
client.broadcast.emit('message', data);
|
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() {
|
onModuleDestroy() {
|
||||||
if (this.server) {
|
if (this.server) {
|
||||||
this.server.close();
|
this.server.close();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue