Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add state() to allow users to check the current state of the socket #12

Closed
fwilkerson opened this issue Feb 13, 2018 · 3 comments
Closed

Comments

@fwilkerson
Copy link

Since the underlying web socket is no longer returned, we lost access to some properties. While we can easily track the readyState using the different lifecycle methods, it would be nice to have a quick getter.

self.state= () => {
    return ws.readyState; 
};
@lukeed
Copy link
Owner

lukeed commented Feb 13, 2018

Could you save the ws reference from onopen's Event object?

let _ws;
const ws = new Sockette('...', {
  onopen(e) {
    console.log('>Connected! 🎉');
    _ws = e.target; // saved
  }
});

It will also update the _ws variable on reconnects.

@fwilkerson
Copy link
Author

Yep that'll work just fine and doesn't add to the size of sockette.

@lukeed
Copy link
Owner

lukeed commented Feb 13, 2018

Perfecto~!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants