Skip to content

Commit

Permalink
[chore] Revert to ws as default wsEngine (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Dec 29, 2017
1 parent d50bf87 commit b1fa020
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ to a single process.
option. If false, no path will be sent, which means browsers will only send the cookie on the engine.io attached path (`/engine.io`).
Set false to not save io cookie on all requests. (`/`)
- `cookieHttpOnly` (`Boolean`): If `true` HttpOnly io cookie cannot be accessed by client-side APIs, such as JavaScript. (`true`) _This option has no effect if `cookie` or `cookiePath` is set to `false`._
- `wsEngine` (`String`): what WebSocket server implementation to use. Specified module must conform to the `ws` interface (see [ws module api docs](https://github.com/websockets/ws/blob/master/doc/ws.md)). Default value is `uws` (see [µWebSockets](https://github.com/uWebSockets/uWebSockets)).
- `wsEngine` (`String`): what WebSocket server implementation to use. Specified module must conform to the `ws` interface (see [ws module api docs](https://github.com/websockets/ws/blob/master/doc/ws.md)). Default value is `ws`. An alternative c++ addon is also available by installing `uws` module.
- `initialPacket` (`Object`): an optional packet which will be concatenated to the handshake packet emitted by Engine.IO.
- `close`
- Closes all clients
Expand Down
16 changes: 5 additions & 11 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Server (opts) {

opts = opts || {};

this.wsEngine = opts.wsEngine || process.env.EIO_WS_ENGINE || 'uws';
this.wsEngine = opts.wsEngine || process.env.EIO_WS_ENGINE || 'ws';
this.pingTimeout = opts.pingTimeout || 60000;
this.pingInterval = opts.pingInterval || 25000;
this.upgradeTimeout = opts.upgradeTimeout || 10000;
Expand Down Expand Up @@ -103,16 +103,10 @@ Server.prototype.init = function () {
if (this.ws) this.ws.close();

var wsModule;
try {
switch (this.wsEngine) {
case 'uws': wsModule = require('uws'); break;
case 'ws': wsModule = require('ws'); break;
default: throw new Error('unknown wsEngine');
}
} catch (ex) {
this.wsEngine = 'ws';
// keep require('ws') as separate expression for packers (browserify, etc)
wsModule = require('ws');
switch (this.wsEngine) {
case 'uws': wsModule = require('uws'); break;
case 'ws': wsModule = require('ws'); break;
default: throw new Error('unknown wsEngine');
}
this.ws = new wsModule.Server({
noServer: true,
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@
"expect.js": "^0.3.1",
"mocha": "^4.0.1",
"s": "0.1.1",
"superagent": "^3.8.1"
},
"optionalDependencies": {
"superagent": "^3.8.1",
"uws": "~9.14.0"
},
"scripts": {
"lint": "eslint lib/ test/ *.js",
"test": "npm run lint && mocha && EIO_WS_ENGINE=ws mocha"
"test": "npm run lint && mocha && EIO_WS_ENGINE=uws mocha"

This comment has been minimized.

Copy link
@artsoroka

artsoroka Jan 7, 2018

If 'ws' was set back as default engine, why tests are run against 'uws'?

This comment has been minimized.

Copy link
@darrachequesne

darrachequesne Feb 28, 2018

Author Member

The first mocha tests against ws, and the second against uws, right?

This comment has been minimized.

Copy link
@artsoroka

artsoroka Mar 20, 2018

Yes, you're right =)

},
"repository": {
"type": "git",
Expand Down

0 comments on commit b1fa020

Please sign in to comment.