Cobby
Cobby

Reputation: 5454

How do I publish data from the server and listen for changes on the client in Meteor?

I've figured out that Meteor (as in http://meteor.com) is using SockJS under the hood.

I have some server-side code that periodically check what song is playing in iTunes and I want to publish the track info to the client side.

I've looked at Meteors docs, and Meteor.publish/Meteor.subscribe seem to specifically deal with Meteor.Collections. I just want to pass through arbitrary data, like strings or JSON.

Is there anyway I can do simple pub/sub in Meteor like Socket.IO or Faye?

Upvotes: 2

Views: 1214

Answers (1)

debergalis
debergalis

Reputation: 11870

You can publish arbitrary data. It doesn't have to come from a Meteor.Collection.

See http://docs.meteor.com/#meteor_publish for a starting point. You'll want to write a publish function on the server which calls Meteor.setInterval to set up a periodic check, and then uses this.set, this.unset, and this.flush to push individual attributes to each client.

Upvotes: 3

Related Questions