how can i effecively display the status 'connected user' on my Friends list using mongoose ?
am using socket io too (and i plan to switch to socket p2p)
my friend list is an array of objects with uid , name , pic , socket as props and this array is stored in my profile document.
i see a couple of options here but can't figure out what's best
use the operator $in to query all the users connected to the app and match the result with my array of friends
store every logged in user in a separate collection and make a sort of comparaison
search in socket io adapter with socket id of each friend ( couple of issues to handle here ex: browser refresh)
thanks for your help
Consider using Primus and Primus Rooms for this purpose. Basically Primus is an abstraction for your socket layer and gives you the possibility to use different web socket implementations.
Primus Rooms adds the functionality to let clients (friends in your case) join a certain 'room' and then broadcast messages to all connected clients.
As these open source tools could give you the wanted functionality it makes no sense to reinvent the wheel.
Regarding Mongoose: Primus Rooms uses a "memory adapter" by default. That means that it is not persisted when clients join rooms. However, feel free to write a Mongoose Adapter for Primus Rooms and contribute it to the community.