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

Access underlying socket object #43

Closed
evanshortiss opened this issue Mar 5, 2019 · 3 comments
Closed

Access underlying socket object #43

evanshortiss opened this issue Mar 5, 2019 · 3 comments
Labels

Comments

@evanshortiss
Copy link

In an application I'm working on I'd like to check that the socket has flushed data. This can be done using socket.bufferedAmount according to this SO post

Could this library support a function to check this, or simply expose the underlying socket object for these use cases, e.g:

const ws = new Sockette('ws://localhost:3000', {
  timeout: 5e3,
  maxAttempts: 10,
  onopen: e => console.log('Connected!', e),
  onmessage: e => console.log('Received:', e),
  onreconnect: e => console.log('Reconnecting...', e),
  onmaximum: e => console.log('Stop Attempting!', e),
  onclose: e => console.log('Closed!', e),
  onerror: e => console.log('Error:', e)
});

// access underlying socket
ws.socket.bufferedAmount
@lukeed lukeed added the question label Mar 5, 2019
@lukeed
Copy link
Owner

lukeed commented Mar 5, 2019

Hey, you were so close 😉

The underlying socket is available to any & all event handlers. The WebSocket is an event emitter, so the current, up-to-date WebSocket instance is always available as ev.target. You can save that reference and do whatever you'd like with it!

There are a few examples scattered across the issues; #12 (comment), #31 (comment), and #18

Hope that helps!

@lukeed lukeed closed this as completed Mar 5, 2019
@evanshortiss
Copy link
Author

Man I need to RTFM next time and not just the Example code. Thanks! 👍

@lukeed
Copy link
Owner

lukeed commented Mar 5, 2019

No worries!

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

No branches or pull requests

2 participants