mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Add test for sending json to a room.
This commit is contained in:
@@ -643,6 +643,88 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test sending json to all clients in a room': function (done) {
|
||||
var port = ++ports
|
||||
, cl1 = client(port)
|
||||
, cl2 = client(port)
|
||||
, cl3 = client(port)
|
||||
, io = create(cl1)
|
||||
, messages = 0
|
||||
, joins = 0
|
||||
, connections = 0
|
||||
, disconnections = 0;
|
||||
|
||||
io.configure(function () {
|
||||
io.set('close timeout', 0);
|
||||
});
|
||||
|
||||
io.sockets.on('connection', function (socket) {
|
||||
connections++;
|
||||
|
||||
if (connections != 3) {
|
||||
socket.join('woot', function () {
|
||||
joins++;
|
||||
|
||||
if (joins == 2) {
|
||||
io.sockets.in('woot').json.send(123);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
disconnections++;
|
||||
|
||||
if (disconnections == 3) {
|
||||
messages.should.eql(2);
|
||||
cl1.end();
|
||||
cl2.end();
|
||||
cl3.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: 123
|
||||
, endpoint: ''
|
||||
});
|
||||
|
||||
messages++;
|
||||
ws1.finishClose();
|
||||
});
|
||||
});
|
||||
|
||||
cl2.handshake(function (sid) {
|
||||
var ws2 = websocket(cl2, sid);
|
||||
ws2.on('message', function (msg) {
|
||||
msg.should.eql({
|
||||
type: 'json'
|
||||
, data: 123
|
||||
, endpoint: ''
|
||||
});
|
||||
|
||||
messages++;
|
||||
ws2.finishClose();
|
||||
});
|
||||
});
|
||||
|
||||
cl3.handshake(function (sid) {
|
||||
var ws3 = websocket(cl2, sid);
|
||||
ws3.on('message', function (msg) {
|
||||
messages++;
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
ws3.finishClose();
|
||||
}, 20);
|
||||
});
|
||||
},
|
||||
|
||||
'test emitting to all clients in a room': function (done) {
|
||||
var port = ++ports
|
||||
, cl1 = client(port)
|
||||
|
||||
Reference in New Issue
Block a user