4

I am using the XMPP smack api to connect to an Openfire server. I am trying to query the server to return all public rooms available without knowing this names of the rooms in advance. The goal of this is so that my client can display a list of all public rooms available and join them accordingly. The Smack Extensions Documentation provides several examples of returning room information from the server however none of them seem to fit my need.

One example requires you to know the name of the room beforehand, which is no good if you want to display available rooms that the client otherwise has no knowledge of. The code for this example is as follows.

 // Discover information about the room roomName@conference.myserver
  RoomInfo info = MultiUserChat.getRoomInfo(conn, "roomName@conference.myserver");
  System.out.println("Number of occupants:" + info.getOccupantsCount());
  System.out.println("Room Subject:" + info.getSubject());

Another example allows you to query the rooms that all of your contacts are currently in. This seems to be a very indirect way of getting room names and has the potential to leave some of the rooms out. As XMPP is a server based protocol and not a p2p based protocol this does not seem like the most logical way of accomplishing this (although please correct me if I am wrong). This code example is as follows

 Iterator joinedRooms = MultiUserChat.getJoinedRooms(conn, "user3@host.org/Smack");

If someone could either please send me a link or provide an example of how to accomplish this it would be greatly appreciated.

pat8719
  • 1,700
  • 1
  • 26
  • 47

1 Answers1

2

It looks like MultiUserChat.getHostedRooms() is what you are looking for.

Robin
  • 24,062
  • 5
  • 49
  • 58
  • thank you that worked perfectly, I didn't see that in the examples and must have overlooked it in the jdocs. – pat8719 Jun 27 '11 at 18:35
  • 1
    i think get hostedrooms should send you the rooms that the user have created but what about the rooms that user has joined but not hosted' – ozmank Oct 14 '11 at 07:32
  • Hi @Robin i was not able to execute any of the static method of **MultiUserChat**. I am getting **NullPointerException**. Do we need to set anything before executing this method ?? – KK_07k11A0585 Aug 24 '13 at 08:36
  • @Robin. I am getting Empty Collections while using this method or using getJoinedRooms Method. What may be the possible error. Can you please help. Have a look at my code. http://pastie.org/8340999 – Gaurav Arora Sep 20 '13 at 07:26