在socket.io的聊天室中获取多少人

我现在有这段代码设置了缺口和余地:

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;

回答:

如果您使用的版本<1,

var clients = io.sockets.clients(nick.room); // all users from room

以上是 在socket.io的聊天室中获取多少人 的全部内容, 来源链接: utcz.com/qa/419834.html

回到顶部