我现在有这个设置昵称和房间的代码:
io.sockets.on('connection', function(client){
var Room = "";
client.on("setNickAndRoom", function(nick, fn){
client.join(nick.room);
Room = nick.room;
client.broadcast.to(Room).emit('count', "Connected:" + " " + count);
fn({msg :"Connected:" + " " + count});
});
我想知道如何让多少人连接到特定的聊天室......比如 Room.length
客户端 :
function Chat(){
this.socket = null;
this.Nickname = "";
this.Room = "";
var synched = $('#syncUp');
this.Connect = function(nick, room){
socket = io.connect('http://vybeing.com:8080');
Nickname = nick;
Room = room;
//conectarse
socket.on('connect',function (data) {
socket.emit('setNickAndRoom', {nick: nick, room: room}, function(response){
$("#connection").html("<p>" + response.msg + "</p>");
});
});
}
我找到了这个,但它给出了未定义的:
count = io.rooms[Room].length;