From 3344826fb98265b8f471624de90e5ebb0fcb1d01 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 7 Mar 2025 12:36:03 +0700 Subject: [PATCH] ws test --- src/controllers/ProfileController.ts | 16 ++++++++++----- src/services/webSocket.ts | 30 ++++++++++++++-------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index eb2937d8..6baff7d5 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -77,6 +77,9 @@ import { ProfileActposition } from "../entities/ProfileActposition"; import { ProfileDuty } from "../entities/ProfileDuty"; import { ProfileAssessment } from "../entities/ProfileAssessment"; import { ProfileAbility } from "../entities/ProfileAbility"; + +import { sendWebSocket } from "../services/webSocket"; + @Route("api/v1/org/profile") @Tags("Profile") @Security("bearerAuth") @@ -1643,12 +1646,15 @@ export class ProfileController extends Controller { profileAbility, otherIncome }; - - return new HttpSuccess({ - template: "new_kk1", + const metaData = { template: "new_kk1", reportName: "docx-report", - data: data, - }); + data: data}; + sendWebSocket(metaData) + // return new HttpSuccess({ + // template: "new_kk1", + // reportName: "docx-report", + // data: data, + // }); } /** diff --git a/src/services/webSocket.ts b/src/services/webSocket.ts index 23062aba..5dd006f0 100644 --- a/src/services/webSocket.ts +++ b/src/services/webSocket.ts @@ -1,16 +1,16 @@ -// import { WebSocket } from "ws"; -// import { wss } from "../app"; +import { WebSocket } from "ws"; +import { wss } from "../app"; -// 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); -// } -// }); -// } -// }); -// } \ No newline at end of file +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); + } + }); + } + }); +} \ No newline at end of file