Broadcast to connected clients


#1

How to broadcast a message to all connected clients? This is possible without a Collection? Should I create a Messages Collection? What is the impact of storing those messages in my Mongo database, does it scale?
Thanks.


An official way to stream data from one client to any number of other clients?
#2

Your client needs to subscribe to a null publication and use a client-side collection (does not exist on the server, so no MongoDB storage). Then you can “roll your own” publication which creates and sends the correct messages to your client. Check the docs I linked to and read on for added, changed, removed and ready.


#3

Got it, thanks! As I can see, I will need a Observer implementation, simulating what a Colletion.observeChanges would do.


#4

Well, you don’t actually need to code an observer if you use pub/sub with a client-only collection. The pub/sub manages the observer for you as long as you name the “fake” data in your roll-your-own publication as belonging to that (client) collection.

Here’s a similar use case (although this isn’t a null publication):


#5

I need a Observer implementation do listen and emit new broadcast messages, don’t I?
Used Node’s EventEmitter, that’s my conclusion, what do you think? Can it be better?

Cheers!

EDIT
You are right. I just updated the pad to work without EventEmitter, it works.