现在我正在使用socket.io 1.7.3并尝试在客房中获取客户列表。
参考一些代码,我写了下面的代码,
var clientlist = getAllRoomMembers('room0');
console.log('clientlist:'+clientlist);
function getAllRoomMembers(room, _nsp) {
var roomMembers = [];
var nsp = (typeof _nsp !== 'string') ? '/' : _nsp;
for( var member in io.of('/').adapter.rooms[room] ) {
roomMembers.push(member);
}
return roomMembers;
}
但是当客户加入房间时,控制台会在下方返回,
clientlist:sockets,length,add,del
你知道为什么会这样吗?
谢谢!