且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获得ejabberd / XMPP中所有在线用户的列表?

更新时间:2023-12-02 14:30:22

XEP-133中的大多数命令 do 与ejabberd都可以正常工作。

Most commands in XEP-133 do work fine with ejabberd.

您确实对某些特定命令不起作用(包括使在线用户成功)是正确的:我发现,尽管有针对ejabberd的非标准替代方法:

You are indeed right about some particular commands not working including getting the online-users: I discovered though there are non-standard alternatives specific to ejabberd:

如果您在主机上运行 disco#items 可以查询一些有趣的项目:

If you run a disco#items on the host you get some interesting items you can query:

<iq to="localhost" type="get" id="123">
    <query xmlns='http://jabber.org/protocol/disco#items' />
</iq>


<iq from="localhost" type="result" to="admin@localhost/jarnas" id="123">
    <query xmlns="http://jabber.org/protocol/disco#items">
        <item jid="conference.localhost" />
        <item jid="pubsub.localhost" />
        <item jid="riot.localhost" />
        <item jid="vjud.localhost" />
        <item node="announce" name="Announcements" jid="localhost" />
        <item node="config" name="Configuration" jid="localhost" />
        <item node="user" name="User Management" jid="localhost" />
        <item node="online users" name="Online Users" jid="localhost" />
        <item node="all users" name="All Users" jid="localhost" />
        <item node="outgoing s2s" name="Outgoing s2s Connections" jid="localhost" />
        <item node="running nodes" name="Running Nodes" jid="localhost" />
        <item node="stopped nodes" name="Stopped Nodes" jid="localhost" />
    </query>
</iq>

现在,如果您需要在线用户,则:

Now in you case you need the "Online Users" so:

<iq to="localhost" type="get" id="234">
    <query xmlns='http://jabber.org/protocol/disco#items' node="online users"/>
</iq>

<iq from="localhost" type="result" to="admin@localhost/jarnas" id="234" >
    <query xmlns="http://jabber.org/protocol/disco#items" node="online users" >
        <item name="admin@localhost" jid="admin@localhost/auto-CdB67NUOie" />
        <item name="admin@localhost" jid="admin@localhost/jarnas" />
    </query>
</iq>

将像护身符;)