Search in sources :

Example 16 with ServiceDiscoveryManager

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

the class AttentionManager method onSettingsChanged.

public void onSettingsChanged() {
    synchronized (enabledLock) {
        for (AccountJid account : AccountManager.getInstance().getEnabledAccounts()) {
            AccountItem accountItem = AccountManager.getInstance().getAccount(account);
            if (accountItem == null) {
                continue;
            }
            ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(accountItem.getConnection());
            if (manager == null) {
                continue;
            }
            boolean contains = false;
            for (String feature : manager.getFeatures()) {
                if (AttentionExtension.NAMESPACE.equals(feature)) {
                    contains = true;
                }
            }
            if (SettingsManager.chatsAttention() == contains) {
                continue;
            }
            if (SettingsManager.chatsAttention()) {
                manager.addFeature(AttentionExtension.NAMESPACE);
            } else {
                manager.removeFeature(AttentionExtension.NAMESPACE);
            }
        }
        AccountManager.getInstance().resendPresence();
    }
}
Also used : AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 17 with ServiceDiscoveryManager

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

the class MessageFasteningManager method announceSupport.

/**
 * Announce support for Message Fastening via Service Discovery.
 */
public void announceSupport() {
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection());
    discoveryManager.addFeature(NAMESPACE);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 18 with ServiceDiscoveryManager

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

the class MessageFasteningManager method stopAnnouncingSupport.

/**
 * Stop announcing support for Message Fastening.
 */
public void stopAnnouncingSupport() {
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(connection());
    discoveryManager.removeFeature(NAMESPACE);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 19 with ServiceDiscoveryManager

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

the class Socks5BytestreamManager method disableService.

/**
 * Disables the SOCKS5 Bytestream manager by removing the SOCKS5 Bytestream feature from the
 * service discovery, disabling the listener for SOCKS5 Bytestream initiation requests and
 * resetting its internal state, which includes removing this instance from the managers map.
 * <p>
 * To re-enable the SOCKS5 Bytestream feature invoke {@link #getBytestreamManager(XMPPConnection)}.
 * Using the file transfer API will automatically re-enable the SOCKS5 Bytestream feature.
 */
public synchronized void disableService() {
    XMPPConnection connection = connection();
    // remove initiation packet listener
    connection.unregisterIQRequestHandler(initiationListener);
    // shutdown threads
    this.initiationListener.shutdown();
    // clear listeners
    this.allRequestListeners.clear();
    this.userListeners.clear();
    // reset internal state
    this.lastWorkingProxy = null;
    this.proxyBlacklist.clear();
    this.ignoredBytestreamRequests.clear();
    // remove manager from static managers map
    managers.remove(connection);
    // shutdown local SOCKS5 proxy if there are no more managers for other connections
    if (managers.size() == 0) {
        Socks5Proxy.getSocks5Proxy().stop();
    }
    // remove feature from service discovery
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    // check if service discovery is not already disposed by connection shutdown
    if (serviceDiscoveryManager != null) {
        serviceDiscoveryManager.removeFeature(Bytestream.NAMESPACE);
    }
}
Also used : XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 20 with ServiceDiscoveryManager

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

the class FileTransferNegotiator method isServiceEnabled.

/**
 * Checks to see if all file transfer related services are enabled on the
 * connection.
 *
 * @param connection The connection to check
 * @return True if all related services are enabled, false if they are not.
 */
public static boolean isServiceEnabled(final XMPPConnection connection) {
    ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection);
    List<String> namespaces = new ArrayList<>();
    namespaces.addAll(Arrays.asList(NAMESPACE));
    namespaces.add(DataPacketExtension.NAMESPACE);
    if (!IBB_ONLY) {
        namespaces.add(Bytestream.NAMESPACE);
    }
    for (String namespace : namespaces) {
        if (!manager.includesFeature(namespace)) {
            return false;
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) 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