10

I am using NodeJS,Scoket.io

I am trying to send notifications like Facebook. If there are 1000 Users and User A have 50 friends then Notification is send to those 50 Users. I do not want to broadcast for all Users

What is the efficient way to do this ?

2
  • Quite a broad question, I suggest you look into socket.io/docs/rooms-and-namespaces for ways to 'group' socket connections
    – snozza
    Commented Jul 22, 2015 at 21:35
  • you can emit sockets by user session email value or user session username value
    – Erdi
    Commented Sep 5, 2015 at 20:03

2 Answers 2

1

If a user has lots of friends then you can have all of those friends listening to a namespace or room for that user.

The explanation and example is here: http://socket.io/docs/rooms-and-namespaces/

1
  • Actually we want something like facebook , for example there is post then 5 another user comments then notification send to those person who comments , Notification system like facebook . Do you work on redis for this purpose ? Commented Sep 7, 2015 at 2:04
0

I think there is better solution then this but for right now I placed userID in socket object and then loops on userID on which we have to send notifications

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.