YuukanOO / streamy

Use meteor underlying sockets for realtime communications
https://atmospherejs.com/yuukan/streamy
MIT License
105 stars 20 forks source link

Socket labels #13

Closed cope closed 8 years ago

cope commented 9 years ago

Would it be possible to introduce labels to the Socket object so that we can then get a list of only those sockets that have a certain label?

This is not like a Room because any Socket can possibly have multiple labels.

Then a label filter could be used in the broadcast method in order to broadcast to the subset of users with a certain label.

For example: var sockets = Streamy.sockets({label: "puppy"}) // returns all connected socket objects with label "puppy".

Streamy.broadcastLabel('puppy', 'some_message', { data: 'world!' }); // broadcasts data to all connected socket objects with label "puppy".

Currently I am trying to simply add a label to a Socket object and then parse the list of sockets to only emit to the ones that have a given label, but I fear with a lot of users sending messages, the constant for loop parsing of all the socket objects will slow things down :(

cope commented 9 years ago

Maybe I just need an efficient way to filter the array of sockets objects based on the label attribute...