From 7d3847ac0b00896219ca0a55d41d705bcb544f9e Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Thu, 6 Mar 2025 13:47:40 +0700 Subject: [PATCH] webSocket test --- src/app.ts | 12 ++++++++++++ src/controllers/ReportController.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index fbd6df0d..c8551023 100644 --- a/src/app.ts +++ b/src/app.ts @@ -126,6 +126,18 @@ async function main() { }); }); + wss.clients.forEach((client: any) => { + if (client.readyState === WebSocket.OPEN) { + const message = ""; + console.log("📤 Sending data to client:", message); + client.send(message, (err:any) => { + if (err) { + console.error("❌ Error sending message:", err); + } + }); + } + }); + // ตั้งค่า Express routes app.get('/', (req, res) => { res.send('Hello from Express!'); diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index a33ac005..8e2f2ad4 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -3554,7 +3554,7 @@ export class ReportController extends Controller { // } // }); - // return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); + return new HttpSuccess({ template: "report2", reportName: "report2", data: { data } }); } /**