diff --git a/lib/transport.js b/lib/transport.js index 43f91057..6f0cff5c 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -76,7 +76,7 @@ Transport.prototype.handleRequest = function (req) { this.log.debug('publishing that', this.id, 'connected'); this.store.publish('open:' + this.id, function () { - self.store.once('open:' + this.id, function () { + self.store.once('open:' + self.id, function () { self.log.debug('request for existing session connection change'); self.close(); self.clearTimeouts(); @@ -94,7 +94,7 @@ Transport.prototype.handleRequest = function (req) { self.onForcedDisconnect(); }); - this.store.once('heartbeat-clear:' + this.id, function () { + this.store.on('heartbeat-clear:' + this.id, function () { self.clearHeartbeatTimeout(); self.setHeartbeatInterval(); }); @@ -103,6 +103,7 @@ Transport.prototype.handleRequest = function (req) { // add a handler only once per socket this.socket.setNoDelay(true); this.socket.on('end', this.onSocketEnd.bind(this)); + this.socket.on('close', this.onSocketEnd.bind(this)); this.socket.on('error', this.onSocketError.bind(this)); this.onSocketConnect(); this.socket.__ioHandler = true; @@ -125,7 +126,7 @@ Transport.prototype.onSocketConnect = function () { }; */ Transport.prototype.onSocketEnd = function () { - this.onClose(); + this.close(); }; /** @@ -434,7 +435,7 @@ Transport.prototype.subscribe = function () { self.payload(payload.map(function (packet) { return parser.encodePacket(packet); })); - } else { + } else { self.write(packet); } });