1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-31 17:25:58 +01:00

Added support for discovering the rooms hosted by a MUC service. SMACK-13

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2455 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Gaston Dombiak 2005-02-06 16:36:23 +00:00 committed by gaston
parent 3fe4678384
commit 6af5705ae5
2 changed files with 30 additions and 0 deletions

View file

@ -216,6 +216,28 @@ public class MultiUserChat {
return answer;
}
/**
* Returns a collection of HostedRooms where each HostedRoom has the XMPP address of the room
* and the room's name. Once discovered the rooms hosted by a chat service it is possible to
* discover more detailed room information or join the room.
*
* @param connection the XMPP connection to use for discovering hosted rooms by the MUC service.
* @param serviceName the service that is hosting the rooms to discover.
* @return a collection of HostedRooms.
* @throws XMPPException if an error occured while trying to discover the information.
*/
public static Collection getHostedRooms(XMPPConnection connection, String serviceName)
throws XMPPException {
List answer = new ArrayList();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = discoManager.discoverItems(serviceName);
for (Iterator it = items.getItems(); it.hasNext();) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next();
answer.add(new HostedRoom(item));
}
return answer;
}
/**
* Returns the name of the room this MultiUserChat object represents.
*

View file

@ -420,6 +420,14 @@ public class MultiUserChatTest extends SmackTestCase {
try {
Collection services = MultiUserChat.getServiceNames(getConnection(1));
assertFalse("No MUC service was found", services.isEmpty());
// Discover the hosted rooms by the chat service.
Collection rooms = MultiUserChat.getHostedRooms(getConnection(1),
(String) services.toArray()[0]);
// Check that we have discovered the room used by this test
assertFalse("No room was found", rooms.isEmpty());
// Check that we have discovered the room used by this test
assertEquals("Wrong room JID found", room, ((HostedRoom)rooms.toArray()[0]).getJid());
}
catch (XMPPException e) {
e.printStackTrace();