我将 getstream.io API 与他们的库一起使用。他们的 JS 库中有以下钩子:
newsFeed.subscribe(function callback(data) {
//do something with the data
});
我创建了一个包来包装 NPM 库。我现在想使用此功能并将结果发布到仅限客户端的集合。
我要试试这个,但我不知道它是否可以:
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();
});
这个可以吗 ?还是我应该这样做?
// 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});
}
});