I want to cast NON-MONGO-DB data from a server publisher to a client collection. Currently, I keep all registered subscriber pens to use for posting data.
client.js: col = new Meteor.Collection("data") Meteor.subscribe("stream")
On the server side, it looks like
server.js all_handles = []; Meteor.publish("stream", function() { // safe reference to this sessions var self = this; // save reference to this subscriber all_handles.push(self); // signal ready self.ready(); // on stop subscription remove this handle from list self.onStop(function() { all_handles = _.without(all_handles, self); } }
Then I can use all_handles somewhere in my application to send data to these clients, for example:
function broadcast(msg) { all_handles.forEach(function(handle) { handle.added("data", Random.id(), msg); } }
It is already in use and works.
Q: I am looking for: can I get all the pens from existing meteorite objects, such as _sessions or something else?
It would be great if I did not organize subscribers who process all the time themselves.
Please do not respond to links to other broadcast packages such as streamy or else. I want to continue the standard collection, but with less code.
Thanks for the help and feedback Tom
source share