我正在为分布式ddp客户端创建包
基本例程如下:
用户可以通过使用给定的ip搜索将客户端分配到他们的帐户。
这样我们就可以自动注册客户了。
我想解决的是在服务器端设计类似于Meteor.userId的功能。
step1: ddp客户机登录,(跳过DH算法)
//client:
DDPClient.call('register',[key:key,token:token, ip:ip]);
//server
Meteor.methods({
'register' : function(options){
var self = this;
// check key token
// store registered clientId similar to Meteor.userId in currentContext
// self contains field _sessionData;
// storing data inside this method works fine
_.extend(self._sessionData, {clientId: ID }
}
});step2: ddp客户端调用其他方法
//client:
DDPClient.call('other-method',[]);
//server
Meteor.methods({
'other-method' : function(options){
var self = this;
//this returns what we set inside register method
console.log(self._sessionData.clientId);
}
});Meteor.publish方法的问题是,有什么简单的方法可以用有效的ClientID重新启动当前上下文中的所有订阅吗?我可以遵循livedata包中的setUserId方法,但是它使用了很多我不想触及的内部元素
这一定要起作用
Meteor.publish('data' : function(){
var self = this;
var clientId = ?????
return Data.find({owner : clientId});
});或者还有别的方法来完成我的任务?我只想在上下文中保留client id,这样它就不必对每个方法调用进行授权。
这个解决方案是不可接受的。
Meteor.publish('data', function(clientId){
});发布于 2013-09-02 15:40:42
Meteor.userId()已经存在于服务器端,在发布函数以外的任何位置。如果您在发布函数中,则可以使用this.userId。
https://stackoverflow.com/questions/17183937
复制相似问题