Search in sources :

Example 26 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.

the class UserTuneIntegrationTest method registerListenerAndWait.

/**
 * Registers a listener for User Tune data. This implicitly publishes a CAPS update to include a notification
 * filter for the usertune node. This method blocks until the server has indicated that this update has been
 * received.
 *
 * @param userTuneManager The UserTuneManager instance for the connection that is expected to receive data.
 * @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
 * @param listener A listener instance for UserTune data that is to be registered.
 *
 * @throws Exception if the test fails
 */
public void registerListenerAndWait(UserTuneManager userTuneManager, ServiceDiscoveryManager discoManager, PepEventListener<UserTuneElement> listener) throws Exception {
    final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
    final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
        if (info.containsFeature(UserTuneManager.USERTUNE_NODE + "+notify")) {
            notificationFilterReceived.signal();
        }
    };
    discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    try {
        userTuneManager.addUserTuneListener(listener);
        notificationFilterReceived.waitForResult(timeout);
    } finally {
        discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) SmackIntegrationTestEnvironment(org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) NotLoggedInException(org.jivesoftware.smack.SmackException.NotLoggedInException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) TimeoutException(java.util.concurrent.TimeoutException) UserTuneElement(org.jivesoftware.smackx.usertune.element.UserTuneElement) PepEventListener(org.jivesoftware.smackx.pep.PepEventListener) Assertions(org.junit.jupiter.api.Assertions) IntegrationTestRosterUtil(org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil) URI(java.net.URI) SmackIntegrationTest(org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest) XMPPException(org.jivesoftware.smack.XMPPException) EntityCapabilitiesChangedListener(org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener) SimpleResultSyncPoint(org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)

Example 27 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.

the class RTPBridge method serviceAvailable.

/**
 * Check if the server support RTPBridge Service.
 *
 * @param connection TODO javadoc me please
 * @return true if the server supports the RTPBridge service
 * @throws XMPPErrorException if there was an XMPP error returned.
 * @throws NoResponseException if there was no response from the remote entity.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    if (!connection.isConnected()) {
        return false;
    }
    LOGGER.fine("Service listing");
    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
    // DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
    // Iterator iter = items.getItems();
    // while (iter.hasNext()) {
    // DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
    // if (item.getEntityID().startsWith("rtpbridge.")) {
    // return true;
    // }
    // }
    DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
    for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
        if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) {
            return true;
        }
    }
    return false;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 28 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.

the class STUN method serviceAvailable.

/**
 * Check if the server support STUN Service.
 *
 * @param connection the connection
 * @return true if the server support STUN
 * @throws SmackException if Smack detected an exceptional situation.
 * @throws XMPPException if an XMPP protocol error was received.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException {
    if (!connection.isConnected()) {
        return false;
    }
    LOGGER.fine("Service listing");
    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
    DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
    for (DiscoverItems.Item item : items.getItems()) {
        DiscoverInfo info = disco.discoverInfo(item.getEntityID());
        for (DiscoverInfo.Identity identity : info.getIdentities()) {
            if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
                if (info.containsFeature(NAMESPACE))
                    return true;
        }
        LOGGER.fine(item.getName() + "-" + info.getType());
    }
    return false;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 29 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project xabber-android by redsolution.

the class BlockingManager method discoverSupport.

private void discoverSupport(XMPPConnection xmppConnection) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(xmppConnection);
    final String account = xmppConnection.getUser();
    final boolean isSupported = discoManager.serverSupportsFeature(XmlConstants.NAMESPACE);
    if (isSupported) {
        LogManager.i(this, "Blocking is supported for account" + account);
    }
    supportForAccounts.put(account, isSupported);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 30 with ServiceDiscoveryManager

use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.

the class ConferenceServiceBrowser method getConferenceServices.

public Collection<String> getConferenceServices(String server) throws Exception {
    List<String> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems()) {
        if (item.getEntityID().startsWith("conference") || item.getEntityID().startsWith("private")) {
            answer.add(item.getEntityID());
        } else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(item.getEntityID());
                }
            } catch (XMPPException | SmackException e) {
            // Nothing to do
            }
        }
    }
    return answer;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackException(org.jivesoftware.smack.SmackException) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Aggregations

ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)46 XMPPException (org.jivesoftware.smack.XMPPException)15 SmackException (org.jivesoftware.smack.SmackException)14 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)14 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)10 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)7 XMPPConnection (org.jivesoftware.smack.XMPPConnection)7 ArrayList (java.util.ArrayList)6 TimeoutException (java.util.concurrent.TimeoutException)6 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)6 SmackIntegrationTestEnvironment (org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment)6 SmackIntegrationTest (org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest)6 IntegrationTestRosterUtil (org.igniterealtime.smack.inttest.util.IntegrationTestRosterUtil)6 SimpleResultSyncPoint (org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint)6 EntityCapabilitiesChangedListener (org.jivesoftware.smackx.disco.EntityCapabilitiesChangedListener)6 PepEventListener (org.jivesoftware.smackx.pep.PepEventListener)6 Assertions (org.junit.jupiter.api.Assertions)6 URI (java.net.URI)4 NotLoggedInException (org.jivesoftware.smack.SmackException.NotLoggedInException)4 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)3