From 6e2b4225d5bb82560c8b19c5b81bc99ba685f468 Mon Sep 17 00:00:00 2001 From: David Janes Date: Mon, 4 May 2015 06:11:26 -0400 Subject: [PATCH] stop null referencing error --- lib/client.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/client.js b/lib/client.js index 4fd93af..03e0f4b 100644 --- a/lib/client.js +++ b/lib/client.js @@ -50,10 +50,14 @@ Client.prototype.connect = function(options, callback) { function onclose() { debug('connection closed'); - self.ps.removeListener('packet', onpacket); - self.socket.removeListener('error', onerror); - self.socket = null; - self.ps = null; + if (self.ps) { + self.ps.removeListener('packet', onpacket); + self.ps = null; + } + if (self.socket) { + self.socket.removeListener('error', onerror); + self.socket = null; + } self.emit('close'); } @@ -130,4 +134,4 @@ Client.prototype.createChannel = function(sourceId, destinationId, namespace, en return new Channel(this, sourceId, destinationId, namespace, encoding); }; -module.exports = Client; \ No newline at end of file +module.exports = Client;