diff --git a/packages/server/index.ts b/packages/server/index.ts index acbf484..5955eb1 100644 --- a/packages/server/index.ts +++ b/packages/server/index.ts @@ -39,7 +39,7 @@ const clients = new Map(); console.log(`Starting WebSocket server ...`); -console.log("Server configuration:", config); +console.log('Server configuration:', config); wss.on('connection', (ws) => { @@ -105,17 +105,29 @@ wss.on('connection', (ws) => { // check if recipient exists and is connected if (recipientWs && recipientWs.readyState === WebSocket.OPEN) { + const timestamp = new Date().toISOString(); + // The recipient is connected. Forward the message. const forwardMessage = { type: MessageType.receive_hl7v2, payload: { message: message, - timestamp: new Date().toISOString(), + timestamp: timestamp, }, } as Message; recipientWs.send(JSON.stringify(forwardMessage)); console.log(`Forwarded message to ${recipientId}`); + const ackMessage = { + type: MessageType.delivery_success, + payload: { + message: message, + timestamp: timestamp, + }, + }; + ws.send(JSON.stringify(ackMessage)); + console.log(`Sent acknowledgment to ${stationId}`); + } else { // The recipient is not connected or not found.