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

Provide http server port directly from _server #1294

Merged
merged 10 commits into from
Feb 5, 2018
Merged
8 changes: 8 additions & 0 deletions lib/websocket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ class WebSocketServer extends EventEmitter {

cb(ws);
}

/**
* Upgrade the connection to WebSocket.
* @public
*/
port () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of thoughts:

  1. It's probably better to call this address and return this._server.address(). This will handle the case where the HTTP server is closed.
  2. WebSocketServer could be initialized in noServer mode. In this case this._server is null. What should we return? Returning null doesn't make sense as it's possible that the external server is actually bound and listening for connections. Throwing an error is probably the best option.

Copy link
Contributor Author

@tnuanchuay tnuanchuay Feb 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood. Thank for the guide. :)

return this._server.address().port;
}
}

module.exports = WebSocketServer;
Expand Down