Leave multiple rooms at once
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 63.2k
- Forks
- 10.3k
- Avg merge
- 11d 20h
- Merged PRs (30d)
- 2
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the socket.leave entry point and compare its JSDoc and TypeScript signature with socket.join, which already accepts a single value or an array. Check the relevant tests around these methods; done means leave accepts multiple rooms, the documentation and types agree, and existing behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100