Skip to content

Commit

Permalink
Revert "[minor] Set the flag to detect invalid API usage only when ne…
Browse files Browse the repository at this point in the history
…eded"

This reverts commit 91b5173.
  • Loading branch information
lpinca committed Apr 22, 2020
1 parent 1a501d5 commit c56d4ec
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/websocket-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,18 @@ class WebSocketServer extends EventEmitter {
callback
);
} else if (options.server) {
if (options.server[kUsedByWebSocketServer]) {
this._server = options.server;
}

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;
}

options.server[kUsedByWebSocketServer] = true;
this._server = options.server;
}

if (this._server) {
this._removeListeners = addListeners(this._server, {
listening: this.emit.bind(this, 'listening'),
error: this.emit.bind(this, 'error'),
Expand Down Expand Up @@ -143,6 +144,8 @@ class WebSocketServer extends EventEmitter {
const server = this._server;

if (server) {
server[kUsedByWebSocketServer] = false;

this._removeListeners();
this._removeListeners = this._server = null;

Expand All @@ -153,8 +156,6 @@ class WebSocketServer extends EventEmitter {
server.close(() => this.emit('close'));
return;
}

delete server[kUsedByWebSocketServer];
}

process.nextTick(emitClose, this);
Expand Down

0 comments on commit c56d4ec

Please sign in to comment.