implementation of module and service socket
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { OnGatewayConnection, SubscribeMessage, WebSocketGateway, WebSocketServer } from "@nestjs/websockets";
|
||||
import { Server, Socket } from "socket.io";
|
||||
import { NotificationInterface } from "../notifications/interfaces/notification.interface";
|
||||
import { NotificationInterface } from "../notifications/notification.interface";
|
||||
import { SocketService } from "./socket.service";
|
||||
|
||||
@WebSocketGateway()
|
||||
@@ -30,32 +30,6 @@ export class SocketGateway implements OnGatewayConnection {
|
||||
|
||||
@SubscribeMessage("sendNotificationToClients")
|
||||
handleSendNotification(notificationData: NotificationInterface) {
|
||||
return new Promise(async (resolve) => {
|
||||
const connectedClients = this.server.sockets.sockets;
|
||||
|
||||
if (connectedClients.size === 0) resolve({ status: "failed", message: "Clients not found!" });
|
||||
|
||||
let sent: any = false;
|
||||
|
||||
for (const connectedClient of connectedClients) {
|
||||
if (connectedClient[1].handshake.auth.token == notificationData.telephone_id) {
|
||||
sent = await new Promise((resolve) => {
|
||||
connectedClient[1].timeout(2000).emit("answer", JSON.stringify(notificationData), (err: any) => {
|
||||
if (err) {
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (sent) {
|
||||
resolve({ status: "success", message: "Sent to clients" });
|
||||
} else {
|
||||
resolve({ status: "failed", message: "Not sent to clients" });
|
||||
}
|
||||
});
|
||||
return this.socketService.sendNotificationToClients(this.server, notificationData);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user