From afb25635dfffbe1b1c8b1da1e5d803e0297e84fb Mon Sep 17 00:00:00 2001 From: Amirhossein Mahmoodi Date: Mon, 29 Jul 2024 16:27:56 +0330 Subject: [PATCH] update --- src/notifications/notification.service.ts | 4 ++-- src/socket/dto/sendMessage.dto.ts | 4 ++-- src/socket/socket.gateway.ts | 8 ++++---- src/socket/socket.service.ts | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/notifications/notification.service.ts b/src/notifications/notification.service.ts index f690502..35b8e09 100644 --- a/src/notifications/notification.service.ts +++ b/src/notifications/notification.service.ts @@ -10,8 +10,8 @@ export class NotificationService { notificationData: NotificationDto, ): Promise<{ status: number; message: string }> { return await this.socketGateway.handleSendMessage({ - auths: [notificationData.telephone_id], - data: notificationData, + clientsId: [notificationData.telephone_id], + message: JSON.stringify(notificationData), event: 'answer', }); } diff --git a/src/socket/dto/sendMessage.dto.ts b/src/socket/dto/sendMessage.dto.ts index 7eedca5..d1e9eb8 100644 --- a/src/socket/dto/sendMessage.dto.ts +++ b/src/socket/dto/sendMessage.dto.ts @@ -1,5 +1,5 @@ export class SendMessageDto { - auths: string[]; - data: any; + clientsId: string[]; + message: string; event: string; } diff --git a/src/socket/socket.gateway.ts b/src/socket/socket.gateway.ts index 47770af..4524eda 100644 --- a/src/socket/socket.gateway.ts +++ b/src/socket/socket.gateway.ts @@ -32,7 +32,7 @@ export class SocketGateway implements OnGatewayConnection { @SubscribeMessage('sendMessageToClients') async handleSendMessage(sendMessageDto: SendMessageDto) { - const clients = this.getConnectedClients(sendMessageDto.auths); + const clients = this.getConnectedClients(sendMessageDto.clientsId); if (clients.length === 0) { return { status: 0, @@ -42,19 +42,19 @@ export class SocketGateway implements OnGatewayConnection { const result = await this.socketService.sendMessageToClients( clients, - sendMessageDto.data, + sendMessageDto.message, sendMessageDto.event, ); return result; } - getConnectedClients(auths: string[]): Socket[] { + getConnectedClients(clientsId: string[]): Socket[] { const connectedClients = this.server.sockets.sockets; const clients: Socket[] = []; for (const client of connectedClients.values()) { - if (auths.includes(client.handshake.auth.token)) { + if (clientsId.includes(client.handshake.auth.token)) { clients.push(client); } } diff --git a/src/socket/socket.service.ts b/src/socket/socket.service.ts index a690fcf..b5b6190 100644 --- a/src/socket/socket.service.ts +++ b/src/socket/socket.service.ts @@ -19,13 +19,13 @@ export class SocketService { async sendMessageToClients( clients: Socket[], - data: any, + message: string, event: string, ): Promise<{ status: number; message: string }> { const promises = clients.map( (client) => new Promise((resolve) => { - client.timeout(2000).emit(event, JSON.stringify(data), (err: any) => { + client.timeout(2000).emit(event, message, (err: any) => { resolve(!err); }); }),