From 1bf4d2fed24767081516c7965f24adec4c81f86f Mon Sep 17 00:00:00 2001 From: Gaston Dombiak Date: Mon, 3 Jan 2005 02:08:23 +0000 Subject: [PATCH] Added support for discovering MUC services. SMACK-39 git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@2443 b35dd754-fafc-0310-a699-88a17e54d16e --- .../smackx/muc/MultiUserChat.java | 21 +++++++++++++++++++ .../smackx/muc/MultiUserChatTest.java | 11 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index 5dc01db3c..cc42b3156 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -195,6 +195,27 @@ public class MultiUserChat { return new RoomInfo(info); } + /** + * Returns a collection with the XMPP addresses of the Multi-User Chat services. + * + * @param connection the XMPP connection to use for discovering Multi-User Chat services. + * @return a collection with the XMPP addresses of the Multi-User Chat services. + * @throws XMPPException if an error occured while trying to discover MUC services. + */ + public static Collection getServiceNames(XMPPConnection connection) throws XMPPException { + List answer = new ArrayList(); + ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(connection); + DiscoverItems items = discoManager.discoverItems(connection.getHost()); + for (Iterator it = items.getItems(); it.hasNext();) { + DiscoverItems.Item item = (DiscoverItems.Item) it.next(); + DiscoverInfo info = discoManager.discoverInfo(item.getEntityID()); + if (info.containsFeature("http://jabber.org/protocol/muc")) { + answer.add(item.getEntityID()); + } + } + return answer; + } + /** * Returns the name of the room this MultiUserChat object represents. * diff --git a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java index 48bb67b21..f17fd3e96 100644 --- a/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java +++ b/test/org/jivesoftware/smackx/muc/MultiUserChatTest.java @@ -365,6 +365,17 @@ public class MultiUserChatTest extends SmackTestCase { } } + public void testDiscoverMUCService() { + try { + Collection services = MultiUserChat.getServiceNames(getConnection(1)); + assertFalse("No MUC service was found", services.isEmpty()); + } + catch (XMPPException e) { + e.printStackTrace(); + fail(e.getMessage()); + } + } + public void testPrivateChat() { try { // User2 joins the new room