From 455ed409df54dfef00d84696903c1babee200443 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 6 Mar 2025 11:04:40 +0700 Subject: [PATCH] webSocket test --- src/controllers/ReportController.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index 214a33b5..24c95b6b 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -32,8 +32,8 @@ import { viewRegistryOfficer } from "../entities/view/viewRegistryOfficer"; import { viewRegistryEmployee } from "../entities/view/viewRegistryEmployee"; import { EmployeeTempPosMaster } from "../entities/EmployeeTempPosMaster"; -// import { WebSocket } from "ws"; -// import { wss } from "../app"; +import { WebSocket } from "ws"; +import { wss } from "../app"; @Route("api/v1/org/report") @Tags("Report") @@ -3542,19 +3542,19 @@ export class ReportController extends Controller { } // console.log(">>",data); - // wss.clients.forEach((client: any) => { - // if (client.readyState === WebSocket.OPEN) { - // const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); - // console.log("📤 Sending data to client:", message); - // client.send(message, (err:any) => { - // if (err) { - // console.error("❌ Error sending message:", err); - // } - // }); - // } - // }); + wss.clients.forEach((client: any) => { + if (client.readyState === WebSocket.OPEN) { + const message = JSON.stringify({ template: "report2", reportName: "report2", data: { data } }); + console.log("📤 Sending data to client:", message); + client.send(message, (err:any) => { + if (err) { + console.error("❌ Error sending message:", err); + } + }); + } + }); - return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /**