Home > Software design >  how to get socket ids of all users in specific room
how to get socket ids of all users in specific room

Time:12-27

I want to get all user socket ids in room using room name.

i have tried below code but it didnt worked.

io.in(room).clients((err , clients) => {
    // must have got clients  array of socket ids , currently available in given room
});

CodePudding user response:

fetchSockets will return all the socket instances

const sockets = await io.in(roomName).fetchSockets();
const socketIds = sockets.map(socket => socket.id);
  • Related