refactorizacion

This commit is contained in:
2024-04-01 13:55:51 +02:00
parent 5c64b4e147
commit 285761e075
7 changed files with 100 additions and 62 deletions

View File

@@ -19,11 +19,16 @@ export class SalaChatGateway
handleConnection(client: Socket) {
const userId = client.handshake.auth.userId;
const userConectado = this.salaChatService.conectaUsuarioUUID(userId);
if (userConectado){
if (userConectado) {
client.join('chat_general');
client.emit('onConnectRoom',this.salaChatService.listaUsuariosSinPartidas);
client.broadcast.to('chat_general').emit('onUserConnectRoom',userConectado);
}else{
client.emit('onConnectRoom', {
usuarios: this.salaChatService.listaUsuariosSinPartidas,
partidas: this.salaChatService.partidasAbiertas,
});
client.broadcast
.to('chat_general')
.emit('onUserConnectRoom', userConectado);
} else {
client.disconnect();
}
}
@@ -31,8 +36,10 @@ export class SalaChatGateway
handleDisconnect(client: Socket) {
const userId = client.handshake.auth.userId;
const userDesconectado = this.salaChatService.desconectaUsuarioUUID(userId);
if (userDesconectado){
client.broadcast.to('chat_general').emit('onUserDisconnectRoom',userDesconectado);
if (userDesconectado) {
client.broadcast
.to('chat_general')
.emit('onUserDisconnectRoom', userDesconectado);
}
client.leave('chat_general');
}
@@ -42,20 +49,20 @@ export class SalaChatGateway
const userId = client.handshake.auth.userId;
const user = this.salaChatService.getUsuarioUUID(userId);
if (user) {
this.server.to('chat_general').emit('chatMsg', { uuid:userId, msg });
this.server.to('chat_general').emit('chatMsg', { uuid: userId, msg });
} else {
client.disconnect();
}
}
sendBroadcastMsg(msg:string){
this.server.to('chat_general').emit('broadcastMsg',msg);
sendBroadcastMsg(msg: string) {
this.server.to('chat_general').emit('broadcastMsg', msg);
}
@SubscribeMessage('creaPartida')
handleCreaPartida(client: Socket) {
const userId = client.handshake.auth.userId;
const partida= this.salaChatService.creaPartida(userId);
this.server.to('chat_general').emit('on_create_partida',partida);
const partida = this.salaChatService.creaPartida(userId);
this.server.to('chat_general').emit('on_create_partida', partida);
}
}

View File

@@ -19,6 +19,11 @@ export class SalaChatService {
);
}
get partidasAbiertas(){
return this.partidasService.partidasAbiertas;
}
getUsuarioUUID(uuid: string) {
return this.usuariosService.getUsuarioByUUID(uuid);
}