M
M
mishell_trickster2018-09-13 16:34:02
Node.js
mishell_trickster, 2018-09-13 16:34:02

How to disable all room clients in socket.io?

Hello. I have two rooms with clients. The namespace is the standard "/".
I need to turn off one room with clients entirely, or turn off clients one by one knowing their id.
Here is what I have at the moment

// Получаю объекты сокетов в комнате
var room = io.sockets.adapter.rooms['clients']
console.log(room) // Room { sockets: { kCUjAOSH5UIrZ5mAAAAA: true }, length: 1 }

// Достаю ID всех сокетов комнаты
var socketsID = Object.keys(room.sockets)
console.log(socketsID) // [ 'kCUjAOSH5UIrZ5mAAAAA' ]

But I have absolutely no idea what to do next. The documentation doesn't give examples on the disconnect method and seems a bit empty. Google has already helped as much as it could. Please tell me how can I complete the connection knowing the ID?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PloAl, 2018-09-13
@mishell_trickster

socketsID.forEach(function(socketid){
  io.sockets.connected[socketid].disconnect();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question