As with broadcasting, the default is all clients from the default namespace (‘/’):
const io = require('socket.io')(); io.clients((error, clients) => { if (error) throw error; console.log(clients); // => [6em3d4TJP8Et9EMNAAAA, G5p55dHhGgUnLUctAAAB] });
Gets a list of client IDs connected to specific namespace (across all nodes if applicable):
const io = require('socket.io')(); io.of('/chat').clients((error, clients) => { if (error) throw error; console.log(clients); // => [PZDoMHjiu8PYfRiKAAAF, Anw2LatarvGVVXEIAAAD] });
An example to get all clients in namespace’s room:
const io = require('socket.io')(); io.of('/chat').in('general').clients((error, clients) => { if (error) throw error; console.log(clients); // => [Anw2LatarvGVVXEIAAAD] });