Action on all clients after updating the collection


#1

Hello!

I’m trying to understand MeteorJS and do not understand how can I execute code on all clients after the collection has changed.

In my case, the change of status should start working JS client library in all clients and play the song. If you run this client library lib.play() in the file collection (where the collection is updated), it will apply only to the user who clicked to play. I was able to solve this problem only tracking changes to the HTML, but I’m sure there’s a more correct solution.

My pseudo code:

Collection:

Collection.update(
	{"_id": id},
	{$set: {"status": "play"}}
);

Template:

PS And sorry for my bad English.

Thanks.


#2

How do you subscribe to your data? Collection cursors are reactive so a template would update on all clients that have subscribed to the same data.