Skip to content

Add broadcast room include functionality - opposite of exclude #5390

@ZachHaber

Description

@ZachHaber

Is your feature request related to a problem? Please describe.
I'm trying to emit events to a collection of rooms, but I want to make sure that one of those rooms is always the case.

In my app I have rooms for which roles each socket is able to manage as well as a room for if the socket is currently active in an app. I'd like to be able to send the message to the subset of sockets that are currently active and able to manage the values.

Describe the solution you'd like
I was thinking that we should be able to have include rooms that are always included - akin to the current exclude rooms.

For example, io.include('active1').to(['r1','r2','r3']).emit() would emit specifically to the sockets with both active1 and one of the rooms (r1, r2, r3).

If you were to do something like io.include(['active1','test']).to(['r1','r2','r3']).emit() we'd need to figure out whether both 'active' and 'test' should be applied or if they should be ored together. Similarly if io.include('active1').include('test').to(['r1','r2','r3']).emit() should be the same as the previous or different.

I think that .include(['active1','test']) should be either of those two rooms, while .include('active1').include('test) should require both of the rooms on the same socket to pass.

Describe alternatives you've considered
Alternatively, in .to and .in, there could be an object property to indicate whether the newly added values should be anded or ored in. The same example as above could be: io.to(['r1','r2','r3']).to({type:'and', rooms: ['active1']})

Without having the full boolean logic in one single call, it could be confusing which pieces should be the same and which should be different.


Another alternative (for my use case), would be to keep track of which apps the socket is not in and maintain an "inactive" rooms and then use exclude. Which isn't ideal due to the need to keep track of a negative value - and would get far too complicated to keep track of if I wanted to include two rooms instead of just one.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions