It works if the message, send code is wrapped within open function. Is that correct?
// Code from README.md client.ts
// Throws error: Websocket is not open: state 0 (CONNECTING)
ws.on("open", function() {
console.log("ws connected!");
});
ws.on("message", function (message: string) {
console.log(message);
});
ws.send("something");
// Working code for client.ts
ws.on("open", function () {
console.log("ws connected!");
ws.on("message", function (message: string) {
console.log(message);
});
ws.send("something");
});
It works if the
message
,send
code is wrapped withinopen
function. Is that correct?