Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 481 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to list rooms on socket.io nodejs server

#11
function ActiveRooms(){
var activeRooms = [];
Object.keys(io.sockets.adapter.rooms).forEach(room=>{
var isRoom = true;
Object.keys(io.sockets.adapter.sids).forEach(id=>{
isRoom = (id === room)? false: isRoom;
});
if(isRoom)activeRooms.push(room);
});
return activeRooms;}
Reply

#12
in Socketio 2.0

to get rooms use

Object.keys(socket.adapter.rooms);

to get the room name

Object.keys(socket.adapter.rooms)[1];

Reply

#13
Filtering out the 'real' rooms can be done like this:

var realRooms = Object.keys(io.sockets.adapter.rooms).reduce((filtered, key) => {
if(!io.sockets.adapter.rooms[key].sockets.hasOwnProperty(key)) filtered.push(key);
return filtered;
}, []);
Reply

#14
According to the documentation of [Socket.io-v3.x][1], to get all current rooms created, you just simply do `socket.rooms`

```js
io.on('connection', socket => {

console.log(socket.rooms);
socket.on('disconnect', () => {
// socket.rooms.size === 0
});
});
```
and it return like this

```js
Set(2) {
'_y_xQeeF6PpFiPQqAAFC',
'6113cb71359644408895afcf6112df3c76981e3f88bc5c08'
}
```

[1]:https://socket.io/docs/v3/rooms/index.html#Disconnection
Reply

#15
on v4 proceed like this:

Array.from(io.adapter.rooms.entries())
It will return an array with the keys (roomIds) and values (socketIds), same structure as Object.entries():

[
[roomId],[Set(2) {"socketId1","socketId2"}],
[roomId2], [Set(3) {"socketId3","socketId4","socketId5"}],
]
Reply

#16
For socket v4. This works:

io.sockets.adapter.rooms.get("id of the room")
Reply

#17
To obtain an array of strings that contains all rooms in v4 you can use:

// if you are not using namespaces
Array.from(io.of("/").adapter.rooms.keys());
// if you are using namespaces
Array.from(io.of("/your-namespace").adapter.rooms.keys());
// output: ["room1", "room2", ...]
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through