0

Express.io obviously combines socket.io and express for node.js. I'm trying however to find a way to get the # of sockets currently in a room and I can't find the right way to do it.

The code i've tried:

app.io.room('room').broadcast.length > 0 

at first i thought this was the answer, but it turns out it just gives me the length of all sockets (at least i think that's what it's giving me).

or

app.io.socket.sockets.clients('room') 

sockets doesn't exist on socket. I tried this one based off of the way to do it with socket.io alone.

Looking at : getting how many people are in a chat room in socket.io

It seems like it is easy to do with socket.io, I just can't seem to find it in express.io

Edit:

I've tried:

console.log(app.io.sockets.in(room).length);
console.log(express.io.sockets.in(room).length);

first one = undefined

second one = error (Cannot call method 'in' of undefined)

Community
  • 1
  • 1
silkcom
  • 492
  • 1
  • 5
  • 14

1 Answers1

0

This seems to work:

app.io.sockets.clients('room').length
robertklep
  • 198,204
  • 35
  • 394
  • 381