I'm trying to count the total number of users in a specific room and broadcast it to all the people in that room.
Here is what I have but I get an error:
var clients = io.sockets.clients(cc.lowerCase(data.roomname)).length;
io.sockets.in(cc.lowerCase(data.roomname)).emit('updatetotal', { total: clients });
ERROR:
TypeError: Object #<Namespace> has no method 'clients'
Thanks.
Since socket.io 1.0 its API was significantly changed so the old code might not work.
To get the number of clients in a room you can use this function:
or more laconically:
This function takes two agruments:
roomName
namespace
(optional) default ='/'
To send message to users of this room only use
.to
method: