From 06d866004e11ec00a3ea5fc60fb118856ba0a8fa Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Sun, 19 Apr 2020 08:55:54 +0200 Subject: [PATCH] Revert "[minor] Throw an error on invalid usage" This reverts commit 364126620bf3fe4e6e0042d3b74ec53b5ccbbb08. --- lib/websocket-server.js | 11 ----------- test/websocket-server.test.js | 31 +++++++------------------------ 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/lib/websocket-server.js b/lib/websocket-server.js index 882c19486..e3701a040 100644 --- a/lib/websocket-server.js +++ b/lib/websocket-server.js @@ -10,7 +10,6 @@ const { format, parse } = require('./extension'); const { GUID } = require('./constants'); const keyRegex = /^[+/0-9A-Za-z]{22}==$/; -const kUsedByWebSocketServer = Symbol('kUsedByWebSocketServer'); /** * Class representing a WebSocket server. @@ -83,14 +82,6 @@ class WebSocketServer extends EventEmitter { } if (this._server) { - if (this._server[kUsedByWebSocketServer]) { - throw new Error( - 'The HTTP/S server is already being used by another WebSocket server' - ); - } else { - this._server[kUsedByWebSocketServer] = true; - } - this._removeListeners = addListeners(this._server, { listening: this.emit.bind(this, 'listening'), error: this.emit.bind(this, 'error'), @@ -144,8 +135,6 @@ class WebSocketServer extends EventEmitter { const server = this._server; if (server) { - server[kUsedByWebSocketServer] = false; - this._removeListeners(); this._removeListeners = this._server = null; diff --git a/test/websocket-server.test.js b/test/websocket-server.test.js index 7503010a2..e862b61d9 100644 --- a/test/websocket-server.test.js +++ b/test/websocket-server.test.js @@ -18,22 +18,11 @@ describe('WebSocketServer', () => { assert.throws(() => new WebSocket.Server()); }); - describe('options', () => { - it('throws an error if no `port` or `server` option is specified', () => { - assert.throws(() => new WebSocket.Server({})); - }); - - it('throws an error if the server is already being used', () => { - const server = http.createServer(); - - new WebSocket.Server({ server }); - - assert.throws( - () => new WebSocket.Server({ server }), - /^Error: The HTTP\/S server is already being used by another WebSocket server$/ - ); - }); + it('throws an error if no port or server is specified', () => { + assert.throws(() => new WebSocket.Server({})); + }); + describe('options', () => { it('exposes options passed to constructor', (done) => { const wss = new WebSocket.Server({ port: 0 }, () => { assert.strictEqual(wss.options.port, 0); @@ -237,21 +226,15 @@ describe('WebSocketServer', () => { it('cleans event handlers on precreated server', (done) => { const server = http.createServer(); - const wss1 = new WebSocket.Server({ server }); + const wss = new WebSocket.Server({ server }); server.listen(0, () => { - wss1.close(() => { + wss.close(() => { assert.strictEqual(server.listenerCount('listening'), 0); assert.strictEqual(server.listenerCount('upgrade'), 0); assert.strictEqual(server.listenerCount('error'), 0); - // Check that no error is thrown if `server` is resued now as there - // are no other `WebSocketServer`s using it. - const wss2 = new WebSocket.Server({ server }); - - wss2.close(() => { - server.close(done); - }); + server.close(done); }); }); });