WebSocket provides a bi-directional communication like a human being talks. The client can send data to the server and the server can send data to the client anytime. But wh
(send a id with the request and wait for a reponse with the same id until a timeout period)
I created a lib that does exactly that, called WebSocketR2 (where R2 means Request Response): https://github.com/ModernEdgeSoftware/WebSocketR2
It also handles reconnecting to the server if a connection is lost, which could be helpful if you are doing web sockets through a load balancer.
The final result is you can implement callbacks on the web socket send function like this:
var request = {
action: "login",
params: {
username: "test",
password: "password"
}
};
ws.send(request, function(response){
console.log(response)
});