Comparing version 0.4.3 to 0.4.4
@@ -37,2 +37,4 @@ var MuxDemux = require('mux-demux'), | ||
}); | ||
return stream; | ||
}; | ||
@@ -39,0 +41,0 @@ |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"engines": { | ||
@@ -13,0 +13,0 @@ "node": ">= 0.8.x < 0.9.0" |
14
room.js
@@ -169,2 +169,6 @@ var debug = require('debug')('chat-room'), | ||
// increment the count of streams for this connection | ||
connection.streams = (connection.streams || 0) + 1; | ||
// handle close events | ||
stream.on('close', function() { | ||
@@ -174,3 +178,11 @@ debug('stream closed - decoupling message handler'); | ||
// TODO: check the count of streams and if 0, remove the connection | ||
// decrement the streams count | ||
if (connection.streams) { | ||
connection.streams -= 1; | ||
} | ||
// if we have no streams connected, then remove the connection | ||
if (! connection.streams) { | ||
room.connections.remove(id); | ||
} | ||
}); | ||
@@ -177,0 +189,0 @@ |
@@ -32,13 +32,15 @@ var assert = require('assert'), | ||
it('should be able to capture messages coming via the connected stream', function(done) { | ||
var client = chat.client(connections[0]); | ||
var client = chat.client(room.connect()); | ||
client.once('data', function(msg) { | ||
assert.equal(msg.data, 'hello'); | ||
assert.equal(msg.cid, connections[0].id); | ||
client.once('data', function handleMessage(msg) { | ||
if (msg.data === 'hello') { | ||
room.removeListener('message', handleMessage); | ||
done(); | ||
} | ||
}); | ||
done(); | ||
client.identify({ nick: randomName().replace(/\s/g, '') }).on('ready', function() { | ||
client.write('hello'); | ||
}); | ||
client.write('hello'); | ||
}); | ||
}); |
30916
18
758