Skip to content

Commit

Permalink
Merge pull request #13 from willyboy/master
Browse files Browse the repository at this point in the history
Fix connectionCount
  • Loading branch information
rexxars committed Dec 11, 2016
2 parents aa40300 + 69ff5ef commit 9300f58
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/sse-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ SseChannel.prototype.addClient = function(req, res, callback) {

// Add the connection to our pool
this.connections.push(res);
this.connectionCount++;
//It would be preferable to not expose this.connectionCount at all and force users to use getConnectionCount
//However, this PR should be backwards compatible. Maybe add a deprecation message?
this.connectionCount = this.connections.length;

// When the client disconnects, remove the client
var removeClient = this.removeClient.bind(this, res);
Expand Down Expand Up @@ -144,7 +146,7 @@ SseChannel.prototype.addClient = function(req, res, callback) {
*/
SseChannel.prototype.removeClient = function(res) {
pull(this.connections, res);
this.connectionCount--;
this.connectionCount = this.connections.length;

this.emit('disconnect', this, res);
};
Expand All @@ -155,7 +157,7 @@ SseChannel.prototype.removeClient = function(res) {
* @return {Number} Number of active connections
*/
SseChannel.prototype.getConnectionCount = function() {
return this.connectionCount;
return this.connections.length;
};

/**
Expand Down

0 comments on commit 9300f58

Please sign in to comment.