Search code examples
javascriptxmppstrophe

Strophe retrieving info before entering a room


I have a web XMPP client, based on Strophe, which connects to a private instance of Openfire server.

After connection to XMPP server I get all public rooms list.

Now I need a way to retrieve some info of those rooms without entering them.

In particular I need the current number of participants and eventually the list of them.


Solution

  • You can send a disco#items query to a MUC room to retrieve the list of current occupants, see XEP-0045 §6.5.

    The user hag66@shakespeare.lit/pda queries the room coven@chat.shakespeare.lit for its list of participants:

    <iq from='hag66@shakespeare.lit/pda'
        id='kl2fax27'
        to='coven@chat.shakespeare.lit'
        type='get'>
      <query xmlns='http://jabber.org/protocol/disco#items'/>
    </iq>
    

    Room responds:

    <iq from='coven@chat.shakespeare.lit'
        id='kl2fax27'
        to='hag66@shakespeare.lit/pda'
        type='result'>
      <query xmlns='http://jabber.org/protocol/disco#items'>
        <item jid='coven@chat.shakespeare.lit/firstwitch'/>
        <item jid='coven@chat.shakespeare.lit/secondwitch'/>
      </query>
    </iq>
    

    The server may refuse to answer if this information is private.