Skip to content

Commit

Permalink
Merge pull request #885 from websockets/remove/path-registry
Browse files Browse the repository at this point in the history
Remove path registry
  • Loading branch information
3rd-Eden authored Nov 9, 2016
2 parents e1a2475 + 2fc1965 commit 8eb551e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 80 deletions.
17 changes: 0 additions & 17 deletions lib/WebSocketServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,6 @@ function WebSocketServer (options, callback) {
this._closeServer = () => this._server && this._server.close();
} else if (options.server) {
this._server = options.server;
if (options.path) {
// take note of the path, to avoid collisions when multiple websocket servers are
// listening on the same http server
if (this._server._webSocketPaths && options.server._webSocketPaths[options.path]) {
throw new Error('two instances of WebSocketServer cannot listen on the same http server path');
}
if (!this._server._webSocketPaths) this._server._webSocketPaths = {};
this._server._webSocketPaths[options.path] = 1;
}
}

if (this._server) {
Expand Down Expand Up @@ -127,14 +118,6 @@ WebSocketServer.prototype.close = function (callback) {
}
}

// remove path descriptor, if any
if (this.path && this._server._webSocketPaths) {
delete this._server._webSocketPaths[this.path];
if (Object.keys(this._server._webSocketPaths).length === 0) {
delete this._server._webSocketPaths;
}
}

// close the http server if it was internally created
try {
if (this._closeServer !== undefined) {
Expand Down
63 changes: 0 additions & 63 deletions test/WebSocketServer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,48 +109,6 @@ describe('WebSocketServer', function () {
});
});

it('can have two different instances listening on the same http server with two different paths', function (done) {
const server = http.createServer();

server.listen(++port, () => {
const wss1 = new WebSocketServer({ server, path: '/wss1' });
const wss2 = new WebSocketServer({ server, path: '/wss2' });
let doneCount = 0;

wss1.on('connection', (client) => {
wss1.close();
if (++doneCount === 2) {
server.close(done);
}
});

wss2.on('connection', (client) => {
wss2.close();
if (++doneCount === 2) {
server.close(done);
}
});

/* eslint-disable no-unused-vars */
const ws1 = new WebSocket(`ws://localhost:${port}/wss1`);
const ws2 = new WebSocket(`ws://localhost:${port}/wss2?foo=1`);
/* eslint-enable no-unused-vars */
});
});

it('cannot have two different instances listening on the same http server with the same path', function (done) {
const server = http.createServer();
const wss1 = new WebSocketServer({ server: server, path: '/wss1' });

try {
// eslint-disable-next-line no-unused-vars
const wss2 = new WebSocketServer({ server: server, path: '/wss1' });
} catch (e) {
wss1.close();
done();
}
});

it('will not crash when it receives an unhandled opcode', function (done) {
const wss = new WebSocketServer({ port: 8080 });

Expand Down Expand Up @@ -229,27 +187,6 @@ describe('WebSocketServer', function () {
server.close(done);
});
});

it('cleans up websocket data on a precreated server', function (done) {
const server = http.createServer();

server.listen(++port, () => {
const wss1 = new WebSocketServer({ server, path: '/wss1' });
const wss2 = new WebSocketServer({ server, path: '/wss2' });

assert.strictEqual(typeof server._webSocketPaths, 'object');
assert.strictEqual(Object.keys(server._webSocketPaths).length, 2);

wss1.close();

assert.strictEqual(Object.keys(server._webSocketPaths).length, 1);

wss2.close();

assert.strictEqual(typeof server._webSocketPaths, 'undefined');
server.close(done);
});
});
});

describe('#clients', function () {
Expand Down

0 comments on commit 8eb551e

Please sign in to comment.