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 _socket to stream #1689

Closed
robertsLando opened this issue Feb 7, 2020 · 7 comments
Closed

Add _socket to stream #1689

robertsLando opened this issue Feb 7, 2020 · 7 comments

Comments

@robertsLando
Copy link

When using createWebSocketStream the duplex returned doesn't have any _socket property. Is it possible to add it?

moscajs/aedes#413

@robertsLando robertsLando changed the title [feat] Add socket to stream Add socket to stream Feb 7, 2020
@robertsLando robertsLando changed the title Add socket to stream Add _socket to stream Feb 7, 2020
@lpinca
Copy link
Member

lpinca commented Feb 7, 2020

I prefer not. The user should not mess with the internal {net,tls}.Socket. You can get it from the WebSocket object if you really need it, before passing the WebSocket object to createWebSocketStream(). On the client you need to wait for the 'open' event.

@robertsLando
Copy link
Author

@lpinca This is how I'm doing it now, I moved to ws from websocket-stream and in websocket-stream I also had that property in the duplex.

@lpinca
Copy link
Member

lpinca commented Feb 7, 2020

Why you need to access the internal socket?

@robertsLando
Copy link
Author

robertsLando commented Feb 7, 2020

To be able to get informations about connection details (remoteIp, ipFamily etc..) from the stream

@lpinca
Copy link
Member

lpinca commented Feb 7, 2020

You can grab that info from the http.IncomingMessage object that is emitted when the 'connection' event is emitted.

wss.on('connection', function(ws, request) {
  // `request` has all the data including the socket itself.
});

https://github.com/websockets/ws#how-to-get-the-ip-address-of-the-client

@robertsLando
Copy link
Author

@lpinca Yes that is how I'm doing it right now, It's not a problem I was just asking if maybe it could be possibile and useful to others add that _socket property to the stream

@lpinca
Copy link
Member

lpinca commented Feb 7, 2020

No thanks, _socket is "private" for good reasons. See also #1688.

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