- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 onConnection Hook 和一些模板助手来执行一些统计操作。但现在,当我是注册用户时,我不想排除这些操作。问题是,我无法在 onConnection Hook 中使用 Meteor.user() ,那么如何检查用户是否已登录?
关于代码,没有太多可展示的
Meteor.onConnection(function(conn) {
if(Meteor.user()) {
console.log("you are logged in")
} else {
console.log("u are not logged in")
}
});
这不是真实的例子,但它简单地显示了我想要做的事情错误
err [Error: Meteor.userId can only be invoked in method calls. Use this.userId in publish functions.]
我知道我可以在方法中使用 Meteor.user(),但是如何在 onConnection 中找到用户是否已登录?
最佳答案
出于统计目的,我建议使用出版物。他们有更复杂的 API,使您可以更好地控制您的连接。
Meteor.publish('users.trackPresence', function() {
// Both this.userId && this.connection are available to be called from here
this.onStop(function(){
// user went offline
});
this.ready();
});
在客户端上,您可以检查用户是否存在,如果是这种情况,甚至不订阅:
Tracker.autorun(function(){
if (!Meteor.userId())
Meteor.subscribe('users.trackPresence');
});
当您从 Tracker.autorun 中订阅时,Meteor 会自动处理取消订阅/重新订阅
在此处了解有关 pubsub api 的更多信息 https://docs.meteor.com/api/pubsub.html
关于javascript - Meteor:onConnection,检查用户是否登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42814310/
我为 Google LocationClient API 实现了这个 onConnected 回调: @Override public void onConnected(Bundle arg0) {
我只是想教自己关于Android音频开发的知识,而对于为什么在这里既不调用connectionCallback的onConnected方法也不对onConnectionFailed方法感到困惑。实例化
在我的集线器中,我有这样的东西(伪代码): public override Task OnConnected() { var isLegal = Authorize(); if (!i
我正在尝试覆盖 OnConnected() , OnDisconnected()方法,但我得到: OnConnected()': no suitable method found to overrid
使用“express”我设置了这个中间件: app.use(function(request, response, next) { console.log(request.headers["u
我有以下内容: public override Task OnConnected() { HandleConnectionAsync(Context).Wait();
我正在使用 onConnection Hook 和一些模板助手来执行一些统计操作。但现在,当我是注册用户时,我不想排除这些操作。问题是,我无法在 onConnection Hook 中使用 Meteo
我正在尝试通过 onConnected() 方法获取我的当前位置。但不幸的是 onMapReady() 被提前调用。因此,我的变量 currentLatitude 和 currentLongitude
中心代码 public class TestHub : Hub { public void Message(string message) {
很简单的问题。为什么刚刚连接的客户端没有收到任何消息,而其他所有客户端都收到了广播?发送连接消息的客户端的正确方法是什么? protected override void OnConnected(Ht
我正在尝试创建一个板,用户可以在其中动态添加 block 并将 block 与链接连接起来。 (类似 this 但动态)我正在使用 JointJs 框架,到目前为止一切都按预期工作,但我需要在用户连接
我今天一直在试验 SignalR,它真的很简洁。基本上我想要实现的是: 一旦设备连接上,它就应该向第一个设备发送一条消息。如果连接的设备多于 1 个,我想发送两条消息。一对所有除了最后一个连接的客户端
我有一个可穿戴设备,我正在尝试连接到 GoogleApiClient,但从未调用回调(onConnected、onConnectionSuspended 或 onConnectionFailed)。其
Meteor 客户端有 onConnection 钩子(Hook)吗?这是我的问题:我正在尝试检测 Meteor 何时重新连接到服务器以基于参数以编程方式重新订阅某些数据。 Meteor其实是自动重新
因此,我有自定义位置服务类,我想从中获取最后已知的位置。我有可能在连接 GoogleApiClient 之前调用 getLastKnownLocation(),所以我必须等待它然后调用 getLast
我正在编写一个使用 Google 定位服务的应用程序。据我了解,当我在 LocationClient 对象上调用 connect() 方法时,实现 GooglePlayServicesClient.C
当用户点击广告地理围栏按钮时,我想在用户的当前位置添加地理围栏。但是,在使用融合 api 客户端后,它声明尚未连接。这是我的代码- import android.Manifest; import an
有没有人遇到过这个问题:- 我正在用 ConnectionCallbacks 等初始化 LocationClient...- 然后,我在上面调用“connect()”。- 在我的“onConnecte
所以我有这段代码: package com.entu.bocterapp; import android.content.Context; import android.location.Locati
当我在 Activity 中使用 GoogleApiClient 但将其移至 Service 并且未调用 onConnected 时正在工作。 public class StepsMonitoring
我是一名优秀的程序员,十分优秀!