Sending events from server to client(s) in Meteor
events, meteor
Solution
The package is now deprecated and do not work for versions >0.9
You can use the following package which is originally aim to broadcast messages from clients-server-clients
http://arunoda.github.io/meteor-streams/
No collection, no mongodb behind, usage is as follow (not tested):
stream = new Meteor.Stream('streamName'); // defined on client and server side
if(Meteor.isClient) {
stream.on("channelName", function(message) {
console.log("message:"+message);
});
}
if(Meteor.isServer) {
setInterval(function() {
stream.emit("channelName", 'This is my message!');
}, 1000);
}
Problem
Is there a way to send events from the server to all or some clients without using collections. I want to send events with some custom data to clients. While meteor is very good in doing this with collections, in this case the added complexity and storage its not needed. On the server there is no need for Mongo storage or local collections. The client only needs to be alerted that it received an event from the server and act accordingly to the data. I know this is fairly easy with sockjs but its very difficult to access sockjs from the server. `Meteor.Error` does something similar to this.