Skip to content

Commit b1fa020

Browse files
[chore] Revert to ws as default wsEngine (#550)
Related: - socketio/socket.io#2956 - socketio/socket.io#3100 Fixes #536 Fixes #516 Fixes #474
1 parent d50bf87 commit b1fa020

File tree

3 files changed

+8
-16
lines changed

3 files changed

+8
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ to a single process.
226226
option. If false, no path will be sent, which means browsers will only send the cookie on the engine.io attached path (`/engine.io`).
227227
Set false to not save io cookie on all requests. (`/`)
228228
- `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`._
229-
- `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)).
229+
- `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.
230230
- `initialPacket` (`Object`): an optional packet which will be concatenated to the handshake packet emitted by Engine.IO.
231231
- `close`
232232
- Closes all clients

lib/server.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function Server (opts) {
3636

3737
opts = opts || {};
3838

39-
this.wsEngine = opts.wsEngine || process.env.EIO_WS_ENGINE || 'uws';
39+
this.wsEngine = opts.wsEngine || process.env.EIO_WS_ENGINE || 'ws';
4040
this.pingTimeout = opts.pingTimeout || 60000;
4141
this.pingInterval = opts.pingInterval || 25000;
4242
this.upgradeTimeout = opts.upgradeTimeout || 10000;
@@ -103,16 +103,10 @@ Server.prototype.init = function () {
103103
if (this.ws) this.ws.close();
104104

105105
var wsModule;
106-
try {
107-
switch (this.wsEngine) {
108-
case 'uws': wsModule = require('uws'); break;
109-
case 'ws': wsModule = require('ws'); break;
110-
default: throw new Error('unknown wsEngine');
111-
}
112-
} catch (ex) {
113-
this.wsEngine = 'ws';
114-
// keep require('ws') as separate expression for packers (browserify, etc)
115-
wsModule = require('ws');
106+
switch (this.wsEngine) {
107+
case 'uws': wsModule = require('uws'); break;
108+
case 'ws': wsModule = require('ws'); break;
109+
default: throw new Error('unknown wsEngine');
116110
}
117111
this.ws = new wsModule.Server({
118112
noServer: true,

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@
4545
"expect.js": "^0.3.1",
4646
"mocha": "^4.0.1",
4747
"s": "0.1.1",
48-
"superagent": "^3.8.1"
49-
},
50-
"optionalDependencies": {
48+
"superagent": "^3.8.1",
5149
"uws": "~9.14.0"
5250
},
5351
"scripts": {
5452
"lint": "eslint lib/ test/ *.js",
55-
"test": "npm run lint && mocha && EIO_WS_ENGINE=ws mocha"
53+
"test": "npm run lint && mocha && EIO_WS_ENGINE=uws mocha"
5654
},
5755
"repository": {
5856
"type": "git",

0 commit comments

Comments
 (0)