Hi, I am using the getstream.io API with their library. They have the following hook in their JS library :
newsFeed.subscribe(function callback(data) {
//do something with the data
});
I created a package to wrap the NPM library.
I want now to use this function and publish the results to a client only collection.
I’m going to try this but I don’t know if it’s ok :
Meteor.publish("newsFeed", function () {
var self = this;
var newsFeed = GetstreamClient.feed('notification', 'newsFeed');
//TODO : Use MeteorAsync ?
newsFeed.subscribe(function callback(data) {
self.added("clientNewsCollection", Random.id(), {event: data});
});
self.ready();
});
Is this ok ? Or should I do it this way ?
// This will be used to store the subscription objects for later management
var subs = { };
// The helper publication
Meteor.publish('newsFeed', function() {
var subscription = this;
subs[subscription._session.id] = subscription;
subscription.onStop(function() {
delete subs[subscription._session.id];
});
});
var newsFeed = GetstreamClient.feed('notification', 'newsFeed');
//TODO : Use MeteorAsync ?
newsFeed.subscribe(function callback(data) {
for (var subscriptionID in subs) {
var subscription = subs[subscriptionID];
subscription.added("clientNewsCollection", Random.id(), {event: data});
}
});