Added test for sending json to all clients in a namespace.

This commit is contained in:
Guillermo Rauch
2011-05-24 23:55:15 -07:00
parent 60dec3dd83
commit be21ca2f19

View File

@@ -497,6 +497,68 @@ module.exports = {
});
},
'test sending json to all clients in a namespace': function (done) {
var port = ++ports
, cl1 = client(port)
, cl2 = client(port)
, io = create(cl1)
, messages = 0
, connections = 0
, disconnections = 0;
io.configure(function () {
io.set('close timeout', 0);
});
io.sockets.on('connection', function (socket) {
connections++;
if (connections == 2) {
io.sockets.json.send({ a: 'b' });
}
socket.on('disconnect', function () {
disconnections++;
if (disconnections == 2) {
messages.should.eql(2);
cl1.end();
cl2.end();
io.server.close();
done();
}
});
});
cl1.handshake(function (sid) {
var ws1 = websocket(cl1, sid);
ws1.on('message', function (msg) {
msg.should.eql({
type: 'json'
, data: { a: 'b' }
, endpoint: ''
});
messages++;
ws1.finishClose();
});
});
cl2.handshake(function (sid) {
var ws2 = websocket(cl2, sid);
ws2.on('message', function (msg) {
msg.should.eql({
type: 'json'
, data: { a: 'b' }
, endpoint: ''
});
messages++;
ws2.finishClose();
});
});
},
'test emitting to all clients in a namespace': function (done) {
var port = ++ports
, cl1 = client(port)