如何知道谁在MUC房间收到消息

时间:2016-08-26 11:21:59

标签: xmpp smack multiuserchat

对于我的论文,我使用Smack来记录使用MUC模块的XMPP网络。

另一个软件目前正在将物联网传感器数据发送到不同的MUC房间。

我想知道发送到MUC房间的每条消息,消息发布时该用户在哪个房间。这可能吗?我可以使用messageListener到每个muc空间,但是监听器只接收消息作为参数。因此我无法知道谁在监听方法中登录了房间。

2 个答案:

答案 0 :(得分:0)

您可以在xmpp中的 StanzaListener 中获取所有 muc 消息。请按照几个步骤完成此操作

步骤1.声明为全局变量

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.bg$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R]  
RewriteRule ^(login|admin) /travelpartner.php [L]
RewriteRule !(perla/|travelpartner\.php) /perla [L]

步骤2.在oncreate或片段中使用此代码

注意:确保已连接聊天服务器。

ChatManagerListener chatListener;
Chat chat;
StanzaListener packetListener;

步骤3.一对一聊天用户的方法

    packetListener = new StanzaListener() {
        @Override
        public void processPacket(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {

            if (packet instanceof Message) {
                final Message message = (Message) packet;

               }
        }
    };

        XMPP.getInstance().getConnection(acitiviy)).addAsyncStanzaListener(stanzaListener, null);

    ServiceDiscoveryManager sdm = ServiceDiscoveryManager
        .getInstanceFor(XMPP.getInstance().getConnection(acitiviy)));
    sdm.addFeature("jabber.org/protocol/si");
    sdm.addFeature("http://jabber.org/protocol/si");
    sdm.addFeature("http://jabber.org/protocol/disco#info");
    sdm.addFeature("jabber:iq:privacy");

}

步骤4.摧毁  。XMPP.getInstance()的getConnection(acitiviy))removeAsyncStanzaListener(stanzaListener);

希望这会对您有所帮助,如果您想了解更多信息,请查看here。三江源

答案 1 :(得分:0)

没有什么能阻止您从侦听器中调用Multi UserCaht.getParticipants()。但要注意:如果你的目标是确定接收器的其他接收器,那么这种方法是脆弱的。我还建议考虑将PubSub而不是MUC用于您的物联网用例。

相关问题