-
Notifications
You must be signed in to change notification settings - Fork 486
Property 'allRooms' does not exist on type 'Adapter'.ts(2339) #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 -- I'm getting this too. |
+1 - I see this as well. I need to reconnect all rooms to the Redis adapter after error in the redis client connections, so this definition would be greatly helpful |
Although type assertions aren't ideal, something like this should work for now and is better than import { RedisAdapter } from '@socket.io/redis-adapter';
// ...
const rooms = await (io.of('/').adapter as RedisAdapter).allRooms(); The issue stems from getAdapter<T extends Adapter>(): T {
return this.adapter as T;
} Then, you would be able to call: const rooms = await io.of('/').getAdapter<RedisAdapter>().allRooms(); I'm no TypeScript genie, so someone might have a better, more elegant solution to this problem! |
You are right, the You can use the const fetchPublicRooms = (namespace) => {
const rooms = [];
namespace.adapter.rooms.forEach((sockets, room) => {
const isPrivate = sockets.size === 1 && sockets.has(room);
if (!isPrivate) {
rooms.push(room);
}
});
return rooms;
}
// requester
const allRooms = fetchPublicRooms(io.of("/"));
io.timeout(5000).serverSideEmit("all-rooms", (err, responses) => {
if (err) {
// something went wrong
}
responses.forEach(rooms => {
Array.prototype.push.apply(allRooms, rooms):
));
console.log(allRooms);
});
// receiver
io.on("all-rooms", (callback) => {
callback(fetchPublicRooms(io.of("/")));
}); |
Closed due to inactivity, please reopen if needed. |
Uh oh!
There was an error while loading. Please reload this page.
Using this snippet from the README,
const rooms = await io.of('/').adapter.allRooms();
Got a typescript error that allRooms does not exist on adapter ^^
Please update with what works to get the list of all rooms, across multiple nodes.
Using the version
"@socket.io/redis-adapter": "^7.1.0", "socket.io": "^4.4.1",
The text was updated successfully, but these errors were encountered: