【发布时间】:2015-10-24 01:52:18
【问题描述】:
我想将 NON-MONGO-DB 数据从服务器发布者广播到客户端集合。目前我保存所有已注册的订阅者句柄以用于发布数据
client.js:
col = new Meteor.Collection("data")
Meteor.subscribe("stream")
在服务器端看起来像
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);
}
}
然后我可以在我的应用程序中的某处使用 all_handles 向这些客户端发送数据,例如:
function broadcast(msg) {
all_handles.forEach(function(handle) {
handle.added("data", Random.id(), msg);
}
}
这已经在使用并正在运行。
问:我正在寻找的是:我能否从当前已经存在的流星(内部)对象(如 _sessions 或其他对象)中获取所有句柄?
如果不是我一直自己组织订阅者的处理,那就太好了。
请不要回答其他广播包的链接,如streamy或其他。我想继续使用标准集合,但代码尽可能少。
感谢您的帮助和反馈 汤姆
【问题讨论】:
标签: meteor