refactorizacion
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,11 @@ export class SalaChatService {
|
||||
);
|
||||
}
|
||||
|
||||
get partidasAbiertas(){
|
||||
return this.partidasService.partidasAbiertas;
|
||||
}
|
||||
|
||||
|
||||
getUsuarioUUID(uuid: string) {
|
||||
return this.usuariosService.getUsuarioByUUID(uuid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user