Search in sources :

Example 31 with ServiceDiscoveryManager

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

the class GroupChatParticipantList method setChatRoom.

public void setChatRoom(final ChatRoom chatRoom) {
    this.groupChatRoom = (GroupChatRoom) chatRoom;
    chat = groupChatRoom.getMultiUserChat();
    chat.addInvitationRejectionListener((jid1, message) -> {
        String nickname = userManager.getUserNicknameFromJID(jid1);
        userHasLeft(nickname);
        chatRoom.getTranscriptWindow().insertNotificationMessage(nickname + " has rejected the invitation.", ChatManager.NOTIFICATION_COLOR);
    });
    listener = p -> SwingUtilities.invokeLater(() -> {
        if (p.getError() != null) {
            if (p.getError().getCondition().equals(XMPPError.Condition.conflict.toString())) {
                return;
            }
        }
        final String userid = p.getFrom();
        String displayName = XmppStringUtils.parseResource(userid);
        userMap.put(displayName, userid);
        if (p.getType() == Presence.Type.available) {
            addParticipant(userid, p);
            agentInfoPanel.setVisible(true);
            groupChatRoom.validate();
        } else {
            removeUser(displayName);
        }
        // When joining a room, check if the current user is an owner/admin. If so, the UI should allow the current
        // user to change settings of this MUC.
        final MUCUser mucUserEx = p.getExtension(MUCUser.ELEMENT, MUCUser.NAMESPACE);
        if (// 110 = Inform user that presence refers to itself
        mucUserEx != null && mucUserEx.getStatus().contains(MUCUser.Status.create(110))) {
            final MUCItem item = mucUserEx.getItem();
            if (item != null) {
                if (item.getAffiliation() == MUCAffiliation.admin || item.getAffiliation() == MUCAffiliation.owner) {
                    groupChatRoom.notifySettingsAccessRight();
                }
            }
        }
    });
    chat.addParticipantListener(listener);
    ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    try {
        roomInformation = disco.discoverInfo(chat.getRoom());
    } catch (XMPPException | SmackException e) {
        Log.debug("Unable to retrieve room information for " + chat.getRoom());
    }
}
Also used : MUCItem(org.jivesoftware.smackx.muc.packet.MUCItem) MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 32 with ServiceDiscoveryManager

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

the class SparkManager method addFeature.

/**
 * Adds a feature that can be discovered through Disco.
 *
 * @param namespace the namespace of the feature.
 */
public static void addFeature(String namespace) {
    // Obtain the ServiceDiscoveryManager associated with my XMPPConnection
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(getConnection());
    // Register that a new feature is supported by this XMPP entity
    discoManager.addFeature(namespace);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 33 with ServiceDiscoveryManager

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

the class Socks5BytestreamManager method enableService.

/**
 * Adds the SOCKS5 Bytestream feature to the service discovery.
 */
private void enableService() {
    ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection());
    manager.addFeature(Bytestream.NAMESPACE);
}
Also used : ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 34 with ServiceDiscoveryManager

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

the class Socks5BytestreamManager method determineProxies.

/**
 * Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
 * in the same order as returned by the XMPP server.
 *
 * @return list of JIDs of SOCKS5 proxies
 * @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies
 * @throws NoResponseException if there was no response from the server.
 * @throws NotConnectedException if the XMPP connection is not connected.
 * @throws InterruptedException if the calling thread was interrupted.
 */
public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    List<Jid> proxies = new ArrayList<>();
    // get all items from XMPP server
    DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());
    // query all items if they are SOCKS5 proxies
    for (Item item : discoverItems.getItems()) {
        // skip blacklisted servers
        if (this.proxyBlacklist.contains(item.getEntityID())) {
            continue;
        }
        DiscoverInfo proxyInfo;
        try {
            proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
        } catch (NoResponseException | XMPPErrorException e) {
            // blacklist errornous server
            proxyBlacklist.add(item.getEntityID());
            continue;
        }
        if (proxyInfo.hasIdentity("proxy", "bytestreams")) {
            proxies.add(item.getEntityID());
        } else {
            /*
                 * server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
                 * bytestream should be established
                 */
            this.proxyBlacklist.add(item.getEntityID());
        }
    }
    return proxies;
}
Also used : Item(org.jivesoftware.smackx.disco.packet.DiscoverItems.Item) DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) Jid(org.jxmpp.jid.Jid) EntityFullJid(org.jxmpp.jid.EntityFullJid) ArrayList(java.util.ArrayList) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPConnection(org.jivesoftware.smack.XMPPConnection) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 35 with ServiceDiscoveryManager

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

the class EntityTimeManager method enable.

public synchronized void enable() {
    if (enabled)
        return;
    ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
    sdm.addFeature(Time.NAMESPACE);
    enabled = true;
}
Also used : 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