Without Adapter
If you only have one server instance, the easiest way is:
// rooms is a Map object
const rooms = io.of("/").adapter.rooms;
const roomSockets = rooms.get('roomid')
You can see from the official document here
Using An Adapter (Redis)
But if you have multiple server instance and are using Adapters like Redis, this will not work as it will only returns the socket in that instance memory, so based on which server instance you request hit, the result will vary.
To get the actual rooms and sockets, you will need to (for RedisAdapter):
// this is a Set of room ids
const rooms = await io.of("/").adapter.allRooms();
// or get the sockets directly if you know the room id
const roomSockets = await io.of("/").adapter.sockets(new Set(['room id']);
You can see more methods here