update
This commit is contained in:
@@ -10,8 +10,8 @@ export class NotificationService {
|
|||||||
notificationData: NotificationDto,
|
notificationData: NotificationDto,
|
||||||
): Promise<{ status: number; message: string }> {
|
): Promise<{ status: number; message: string }> {
|
||||||
return await this.socketGateway.handleSendMessage({
|
return await this.socketGateway.handleSendMessage({
|
||||||
auths: [notificationData.telephone_id],
|
clientsId: [notificationData.telephone_id],
|
||||||
data: notificationData,
|
message: JSON.stringify(notificationData),
|
||||||
event: 'answer',
|
event: 'answer',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export class SendMessageDto {
|
export class SendMessageDto {
|
||||||
auths: string[];
|
clientsId: string[];
|
||||||
data: any;
|
message: string;
|
||||||
event: string;
|
event: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class SocketGateway implements OnGatewayConnection {
|
|||||||
|
|
||||||
@SubscribeMessage('sendMessageToClients')
|
@SubscribeMessage('sendMessageToClients')
|
||||||
async handleSendMessage(sendMessageDto: SendMessageDto) {
|
async handleSendMessage(sendMessageDto: SendMessageDto) {
|
||||||
const clients = this.getConnectedClients(sendMessageDto.auths);
|
const clients = this.getConnectedClients(sendMessageDto.clientsId);
|
||||||
if (clients.length === 0) {
|
if (clients.length === 0) {
|
||||||
return {
|
return {
|
||||||
status: 0,
|
status: 0,
|
||||||
@@ -42,19 +42,19 @@ export class SocketGateway implements OnGatewayConnection {
|
|||||||
|
|
||||||
const result = await this.socketService.sendMessageToClients(
|
const result = await this.socketService.sendMessageToClients(
|
||||||
clients,
|
clients,
|
||||||
sendMessageDto.data,
|
sendMessageDto.message,
|
||||||
sendMessageDto.event,
|
sendMessageDto.event,
|
||||||
);
|
);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
getConnectedClients(auths: string[]): Socket[] {
|
getConnectedClients(clientsId: string[]): Socket[] {
|
||||||
const connectedClients = this.server.sockets.sockets;
|
const connectedClients = this.server.sockets.sockets;
|
||||||
const clients: Socket[] = [];
|
const clients: Socket[] = [];
|
||||||
|
|
||||||
for (const client of connectedClients.values()) {
|
for (const client of connectedClients.values()) {
|
||||||
if (auths.includes(client.handshake.auth.token)) {
|
if (clientsId.includes(client.handshake.auth.token)) {
|
||||||
clients.push(client);
|
clients.push(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,13 +19,13 @@ export class SocketService {
|
|||||||
|
|
||||||
async sendMessageToClients(
|
async sendMessageToClients(
|
||||||
clients: Socket[],
|
clients: Socket[],
|
||||||
data: any,
|
message: string,
|
||||||
event: string,
|
event: string,
|
||||||
): Promise<{ status: number; message: string }> {
|
): Promise<{ status: number; message: string }> {
|
||||||
const promises = clients.map(
|
const promises = clients.map(
|
||||||
(client) =>
|
(client) =>
|
||||||
new Promise<boolean>((resolve) => {
|
new Promise<boolean>((resolve) => {
|
||||||
client.timeout(2000).emit(event, JSON.stringify(data), (err: any) => {
|
client.timeout(2000).emit(event, message, (err: any) => {
|
||||||
resolve(!err);
|
resolve(!err);
|
||||||
});
|
});
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user