首页 > 解决方案 > 在 Ejabberd/XMPP 中同时禁用多个设备的用户登录

问题描述

环境:

Ejabberd 版本:16.04

Smack-android-4.1.0

我正在开发一个 Android 聊天应用程序。目前,可以使用相同的用户凭据从多个设备登录。

目前的情况如下:

1. User logs in into the app in device A
2. Using the same username and password, the user logs successfully into the app in device B
3. Now device A says, it is disconnected, but continue the chat in device B

但是,根据给定的要求,它的行为应该是这样的:

1. User logs in into the app in device A
2. Using the same username and password, when the user tries to log in from device B, it should not allow it. 
(Since he is already logged in from device A)

很高兴听到您对此的解决方案/想法。提前致谢。

标签: androidxmppchatejabberdsmack

解决方案


来自 XMPP 规范:

“如果已经有同名的活动资源,服务器必须(1)终止活动资源并允许新请求的会话,或(2)禁止新请求的会话并保持活动资源。服务器所做的这些取决于实施,尽管建议实施案例#1。”

更多信息在这里https://xmpp.org/rfcs/rfc3921.html#session

因此,您当前的方案是推荐的方案。

但是,我很快检查了 ejabberd src 代码,发现它可以以某种方式配置(closeold -> closenew)

https://github.com/processone/ejabberd/blob/master/src/ejabberd_c2s.erl#L964

https://github.com/processone/ejabberd/blob/master/src/ejabberd_c2s.erl#L873

我不是Erlang专家,但是貌似可以通过修改源码来实现


推荐阅读