-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Description
Is your feature request related to a problem? Please describe.
In my functions to cause a socket to manage leave all rooms they no longer have permissions for and join rooms they now have permissions for, there's no way to leave multiple rooms at once without individually leaving each room, which seems like a waste, especially if I end up moving to an adapter that makes leaving async.
Currently the JSDocs for the socket leave mentions that you can use socket.leave('room1').leave('room2')
which isn't valid according to the typescript as it returns Promise<void> | void
.
Which means that to leave multiple rooms I have to do something like this depending on the behavior I'm looking for.
const toLeave = new Set<string>();
// ... fill toLeave
for(const room of toLeave){
await socket.leave(room);
}
await Promise.all(Array.from(toLeave,room=>socket.leave(room)));
Describe the solution you'd like
I'd like leave to have the same functionality as join where it allows a single value or an array of values: socket.leave(['room1','room2'])
Which would make the above example much simpler and presumably allow the adapters to handle it more efficiently.
await socket.leave(Array.from(toLeave));
Describe alternatives you've considered
I'm not sure what other alternatives exist. Regardless, fixing the JSDocs or the typescript types - based on which one of those is wrong would be helpful (which I'm pretty sure is the JSDoc)