hrms-api-org/src/services/webSocket.ts

16 lines
497 B
TypeScript
Raw Normal View History

2025-03-07 12:04:23 +07:00
import { WebSocket } from "ws";
import { wss } from "../app";
2025-03-06 18:25:27 +07:00
2025-03-07 12:04:23 +07:00
export async function sendWebSocket(data:any){
wss.clients.forEach((client: any) => {
if (client.readyState === WebSocket.OPEN) {
const message = JSON.stringify(data);
console.log("📤 Sending data to client:", message);
client.send(message, (err:any) => {
if (err) {
console.error("❌ Error sending message:", err);
}
});
}
});
}