ryo-ma / deno-websocket

🦕 A simple WebSocket library like ws of node.js library for deno
https://deno.land/x/websocket
MIT License
152 stars 17 forks source link

Websocket is not open: state 0 (CONNECTING) for client.ts #26

Closed borsemayur2 closed 2 years ago

borsemayur2 commented 3 years ago

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");
});
ryo-ma commented 2 years ago

Good catch!

ryo-ma commented 2 years ago

I have fixed it.