How to fetch room list from openfire?

2019-07-25 16:14发布

问题:

I am using openfire server and XMPP protocol for chatting and i got success in it.

Now i want to implement room chatting. I google lots about it, what i get is 'Joing Room', 'Create Room' but first i want to get list of all room name from conferrance.

i have conferance and room in it :

#define CONFERENCE_ROOM_SERVER      @"chatroomforfriends"
#define CONFERENCE_ROOM_NAME        @"cr1"

'chatroomforfriends' is conferance name and it contain 'cr1' room.

How do i fetch all room name in iOS ?

回答1:

As per MUC XEP (0045) you can get list of all rooms by querying:

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

and you get the response as:

<iq from='chat.shakespeare.lit'
  id='zb8q41f4' to='hag66@shakespeare.lit/pda' type='result'>
  <query xmlns='http://jabber.org/protocol/disco#items'>
    <item jid='heath@chat.shakespeare.lit'
      name='A Lonely Heath'/>
    <item jid='coven@chat.shakespeare.lit'
      name='A Dark Cave'/>
    <item jid='forres@chat.shakespeare.lit'
      name='The Palace'/>
    <item jid='inverness@chat.shakespeare.lit'
      name='Macbeth&apos;s Castle'/>
  </query>
</iq>

Details are mentioned in XEP-0045

This method returns all public rooms hosted by MUC Service. To get private rooms, or to get rooms of a specific user, you will have to write a plugin to handle your custom query (XMPP Way) or you can write a servlet (HTTP Way) in Openfire for this.