检测用户登录/注销xmpp谷歌应用引擎

时间:2012-01-27 11:42:41

标签: java google-app-engine xmpp

我在Java中使用Google App Engine发送XMPP消息。

我想知道是否有办法检查用户是否已登录系统或已注销。因此,当用户登录时,我想向他发送 welcome 聊天消息,当他退出时我想通知我的服务器代码。

我已经尝试过在线API但到目前为止没有运气。

1 个答案:

答案 0 :(得分:0)

假设您指的是通过XMPP查询用户的状态,请注意,如果您的App Engine帐户已授权, em>由该用户。如果您已经到目前为止,查询状态(用户登录/注销)非常简单(source)。

如果Google Talk用户订阅了某个应用(已接受邀请或邀请该应用进行聊天),该应用可以通过查找/_ah/xmpp/presence/available的POST来发现用户的可用性。如果用户已订阅且可用,您可以向他们发送您的应用程序的状态和状态:

// In the handler for _ah/xmpp/presence/available
XMPPService xmppService = XMPPServiceFactory.getXMPPService();
Presence presence = xmppService.parsePresence(req);

// Split the XMPP address (e.g., user@gmail.com)
// from the resource (e.g., gmail.CD6EBC4A)
String from = presence.getFromJid().getId().split("/")[0];

// Mirror the contact's presence back to them
xmppService.sendPresence(from, PresenceType.AVAILABLE, presence.getPresenceShow(), presence.getStatus());

要进一步说明,您的应用会通过以下POST网址路径收到自动状态通知:

  • 发送至/_ah/xmpp/presence/available/的信号表示用户可用并提供用户的聊天状态。
  • 发送至/_ah/xmpp/presence/unavailable/的信号表示用户不可用
  • 发布到/_ah/xmpp/presence/probe/ 请求用户当前的状态。

例如,当用户 sally 登录时,您将收到/_ah/xmpp/presence/available/的POST请求,然后您的服务器必须处理该请求。然后当 sally 注销时,您将收到/_ah/xmpp/presence/unavailable/的单独POST请求。