Search in sources :

Example 46 with ServiceDiscoveryManager

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

the class PepManager method isSupported.

public boolean isSupported() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
    XMPPConnection connection = connection();
    ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
    BareJid localBareJid = connection.getUser().asBareJid();
    return serviceDiscoveryManager.supportsFeatures(localBareJid, REQUIRED_FEATURES);
}
Also used : EntityBareJid(org.jxmpp.jid.EntityBareJid) BareJid(org.jxmpp.jid.BareJid) XMPPConnection(org.jivesoftware.smack.XMPPConnection) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 47 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 48 with ServiceDiscoveryManager

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

the class TransportUtils method isRegistered.

/**
 * Checks if the user is registered with a gateway.
 *
 * @param con       the XMPPConnection.
 * @param transport the transport.
 * @return true if the user is registered with the transport.
 */
public static boolean isRegistered(XMPPConnection con, Transport transport) {
    if (!con.isConnected()) {
        return false;
    }
    ServiceDiscoveryManager discoveryManager = ServiceDiscoveryManager.getInstanceFor(con);
    try {
        Jid jid = JidCreate.from(transport.getXMPPServiceDomain());
        DiscoverInfo info = discoveryManager.discoverInfo(jid);
        return info.containsFeature("jabber:iq:registered");
    } catch (XMPPException | SmackException | XmppStringprepException | InterruptedException e) {
        Log.error(e);
    }
    return false;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) Jid(org.jxmpp.jid.Jid) DomainBareJid(org.jxmpp.jid.DomainBareJid) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 49 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, reason, message, rejection) -> {
        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(StanzaError.Condition.conflict)) {
                return;
            }
        }
        final EntityFullJid userid = p.getFrom().asEntityFullJidOrThrow();
        Resourcepart displayName = userid.getResourcepart();
        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 | InterruptedException 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) EntityFullJid(org.jxmpp.jid.EntityFullJid) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) Resourcepart(org.jxmpp.jid.parts.Resourcepart) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Example 50 with ServiceDiscoveryManager

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

the class BookmarksUI method getConferenceServices.

private Collection<DomainBareJid> getConferenceServices(DomainBareJid server) throws Exception {
    List<DomainBareJid> answer = new ArrayList<>();
    ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
    DiscoverItems items = discoManager.discoverItems(server);
    for (DiscoverItems.Item item : items.getItems()) {
        DomainBareJid entityID = item.getEntityID().asDomainBareJid();
        // TODO: We should not simply assumet that this is MUC service just because it starts with a given prefix.
        if (entityID.toString().startsWith("conference") || entityID.toString().startsWith("private")) {
            answer.add(entityID);
        } else {
            try {
                DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
                if (info.containsFeature("http://jabber.org/protocol/muc")) {
                    answer.add(entityID);
                }
            } catch (XMPPException | SmackException e) {
                Log.error("Problem when loading conference service.", e);
            }
        }
    }
    return answer;
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) SmackException(org.jivesoftware.smack.SmackException) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) XMPPException(org.jivesoftware.smack.XMPPException) DomainBareJid(org.jxmpp.jid.DomainBareJid) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager)

Aggregations

ServiceDiscoveryManager (org.jivesoftware.smackx.disco.ServiceDiscoveryManager)51 XMPPException (org.jivesoftware.smack.XMPPException)17 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)17 SmackException (org.jivesoftware.smack.SmackException)16 DiscoverItems (org.jivesoftware.smackx.disco.packet.DiscoverItems)12 XMPPConnection (org.jivesoftware.smack.XMPPConnection)8 AfterClass (org.igniterealtime.smack.inttest.annotations.AfterClass)7 DomainBareJid (org.jxmpp.jid.DomainBareJid)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