ack role, ws syntax, console

This commit is contained in:
Ubuntu 2025-08-04 09:39:20 +05:30
parent e000aac57b
commit 229ee19949

View File

@ -434,6 +434,8 @@ wss.on("connection", (ws) => {
return; return;
} }
console.log("decoded token ----",decoded)
// Fetch hospital_code from hospitals table // Fetch hospital_code from hospitals table
const result = await db.query( const result = await db.query(
"SELECT hospital_code FROM hospitals WHERE id = ?", "SELECT hospital_code FROM hospitals WHERE id = ?",
@ -479,20 +481,20 @@ wss.on("connection", (ws) => {
}); });
}); });
function emitEvent(event, data, userId = null) { // function emitEvent(event, data, userId = null) {
if (userId && userSockets.has(userId)) { // if (userId && userSockets.has(userId)) {
const client = userSockets.get(userId); // const client = userSockets.get(userId);
if (client.readyState === WebSocket.OPEN) { // if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({ event, data })); // client.send(JSON.stringify({ event, data }));
} // }
} else { // } else {
wss.clients.forEach((client) => { // wss.clients.forEach((client) => {
if (client.readyState === WebSocket.OPEN) { // if (client.readyState === WebSocket.OPEN) {
client.send(JSON.stringify({ event, data })); // client.send(JSON.stringify({ event, data }));
} // }
}); // });
} // }
} // }
server.listen(40520, () => { server.listen(40520, () => {
console.log("📡 Secure WebSocket server listening on wss://backend.spurrinai.com:40520"); console.log("📡 Secure WebSocket server listening on wss://backend.spurrinai.com:40520");