lukeed / sockette

The cutest little WebSocket wrapper! 🧦
MIT License
2.45k stars 81 forks source link

Added `getStatus` method that returns a status of the websocket #22

Closed albert-nowak closed 6 years ago

albert-nowak commented 6 years ago

This PR adds an extra method that returns status code of the WebSocket.

lukeed commented 6 years ago

Hi, thank you so much! 🙏

I'm sorry to say though, that I'm actually not interested in adding methods like these to the library. It's roughly a 10% increase in size, and it's just a getter. The library should be limited to reconnecting support & that's it imo.

Instead, we can do this:

let ws;
let socket = new Sockette('...', {
  onopen(ev) {
    ws = ev.target; // always updates
  }
});

// elsewhere
ws.readyState;

Achieves the same & only adds 10 bytes to what's likely already there.

Closing this, but I do really appreciate it 🥇

albert-nowak commented 6 years ago

Cool! TBH didn't know that I can access socket state via ev.target 👍

lukeed commented 6 years ago

Yeah! It's kinda sneaky haha, but makes sense once you remember that that's how all EventListeners work 😅 You can access the native ws on any event handler~