Running a global function that runs for all connected users upon event

I’m wanting to run a function upon a click event for all clients that displays a toast message and also plays a sound.

One solution that I’ve found to work is to define an object in a collection, create a Meteor.setInterval function and occasionally tick a certain amount of time to check for changes in the database. I’d prefer if this was reactive, however.

Is there a more elegant solution to doing this?

You can use observe() or observeChanges() :slight_smile:

Meteor.subscribe('messages')
Messages.observeChanges({
  added(id, message){
    alert(message.text)
  }
})

Is there a way to globally emit server events (like socket.io) instead of relying on solely on the database?

Yes, by creating a “manual” publication, using this.added, that publishes to a client-only collection