Skip to content

Commit de1e206

Browse files
committed
Merge pull request webtorrent#150 from feross/fix-148
Fix "Error: listener must be a function"
2 parents a09c51d + fafbb25 commit de1e206

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

server.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,19 @@ Server.prototype._onWebSocketClose = function (socket) {
713713
socket.peerId = null
714714
socket.infoHashes = null
715715

716-
socket.removeListener('message', socket.onMessageBound)
716+
if (typeof socket.onMessageBound === 'function') {
717+
socket.removeListener('message', socket.onMessageBound)
718+
}
717719
socket.onMessageBound = null
718720

719-
socket.removeListener('error', socket.onErrorBound)
721+
if (typeof socket.onErrorBound === 'function') {
722+
socket.removeListener('error', socket.onErrorBound)
723+
}
720724
socket.onErrorBound = null
721725

722-
socket.removeListener('close', socket.onCloseBound)
726+
if (typeof socket.onCloseBound === 'function') {
727+
socket.removeListener('close', socket.onCloseBound)
728+
}
723729
socket.onCloseBound = null
724730
}
725731

0 commit comments

Comments
 (0)