更新时间:2022-06-24 22:02:51
根据@laberning 的通知,我现在使用了未记录的"流星连接.
As informed by @laberning I used for now the "undocumented" meteor connections.
您可以发布给所有订阅者的发布方法,例如:
You can post to all subscribers of a publishing method like:
// publish updated values to all subscribers
function publish_to_all_subscribers(subscription_name, id, data) {
_.each(Meteor.server.stream_server.open_sockets, function(connection) {
_.each(connection._meteorSession._namedSubs, function(sub) {
if (sub._name == subscription_name) {
sub.insert(subscription_name, id, data);
}
})
});
}
// create stream publisher
Meteor.publish('stream', function(){
// set ready
this.ready();
});
...
// use publishing somewhere in your app
publish_to_all_subscribers('stream', Random.id(), {msg: "Hello to all"});
...
更新:查看示例 MeteorPad 用于发布、订阅和广播消息