diff --git a/README.md b/README.md index c52a1595e..d7fd075ea 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/server.js b/lib/server.js index 0e3f53c0e..4d6ec0272 100644 --- a/lib/server.js +++ b/lib/server.js @@ -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; @@ -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, diff --git a/package.json b/package.json index 61415d84d..e442b7fd4 100644 --- a/package.json +++ b/package.json @@ -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" }, "repository": { "type": "git",