It has been some time now working on integration of Refinitiv WebSocket's API and our core banking system, so far I am able to connect to the WebSocket without issues, I can as well send messages successfully, the challenge I am having is that, after I sent the message, I want to be able to log the response as we get response when testing with postman, I am not able to get that response, I find this weird because if we have an error on our request payload(Message) I am able to get that response logged and the error message of why the request does not go through. Can you maybe help me out on this? Below is the code snipet;
const connectWebSocket = async () => {
const protocol = process.env.RDP_WEBSOCKET_PROTOCOL;
const server = process.env.RDP_WEBSOCKET_SERVER;
const port = process.env.RDP_WEBSOCKET_PORT;
const securityProtocol = process.env.RDP_SEC_PROTOCOL;
try {
const RDP_WEB_SOCKET_URL = `${protocol}://${server}:${port}/WebSocket`;
const wsUrl = RDP_WEB_SOCKET_URL;
const service = process.env.REALTIME_SERVICE;
const message = {
ID: 4,
Streaming: false,
Key: {
Service: service,
Name: "LSL=",
},
};
const ws = new WebSocket(wsUrl, securityProtocol);
ws.on("open", () => {
console.log("WebSocket connection established.");
// Send your message as JSON
ws.send(JSON.stringify(message), () => {
console.log("Message sent to WebSocket server:", JSON.stringify(message));
});
});
ws.on("message", (data) => {
const message = data.toString();
try {
const parsedMessage = JSON.parse(message);
console.log("Received message from server:", parsedMessage);
} catch (error) {
console.error("Error parsing message:", error);
}
});
ws.on("close", (code, reason) => {
console.log(
`WebSocket connection closed with code ${code}. Reason: ${reason}`
);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
} catch (error) {
console.error(
"Error occurred while establishing WebSocket connection:",
error
);
}
};