Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,25 @@ Server.prototype.init = function () {
if (!~this.transports.indexOf('websocket')) return;

if (this.ws) this.ws.close();

var wsModule;
switch (this.wsEngine) {
case 'uws': wsModule = require('uws'); break;
case 'ws': wsModule = require('ws'); break;
case 'uws': {
wsModule = require('uWebSockets.js');
this.ws = new wsModule.App();
break;
}
case 'ws': {
wsModule = require('ws');
this.ws = new wsModule.Server({
noServer: true,
clientTracking: false,
perMessageDeflate: this.perMessageDeflate,
maxPayload: this.maxHttpBufferSize
});
break;
}
default: throw new Error('unknown wsEngine');
}
this.ws = new wsModule.Server({
noServer: true,
clientTracking: false,
perMessageDeflate: this.perMessageDeflate,
maxPayload: this.maxHttpBufferSize
});
};

/**
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@
"dependencies": {
"accepts": "~1.3.4",
"base64id": "1.0.0",
"cookie": "0.3.1",
"debug": "~3.1.0",
"engine.io-parser": "~2.1.0",
"ws": "~6.1.0",
"cookie": "0.3.1"
"uWebSockets.js": "github:uNetworking/uWebSockets.js#v15.10.0",
"ws": "~6.1.0"
},
"devDependencies": {
"babel-eslint": "^8.0.2",
Expand All @@ -45,8 +46,7 @@
"expect.js": "^0.3.1",
"mocha": "^4.0.1",
"s": "0.1.1",
"superagent": "^3.8.1",
"uws": "~9.14.0"
"superagent": "^3.8.1"
},
"scripts": {
"lint": "eslint lib/ test/ *.js",
Expand Down
2 changes: 1 addition & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ describe('server', function () {
describe('wsEngine option', function () {
it('should allow loading of other websocket server implementation like uws', function (done) {
var engine = listen({ allowUpgrades: false, wsEngine: 'uws' }, function (port) {
expect(engine.ws instanceof require('uws').Server).to.be.ok();
expect(engine.ws instanceof require('uWebSockets.js').App).to.be.ok();
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
engine.on('connection', function (conn) {
conn.send('a');
Expand Down