Search in sources :

Example 1 with AbstractNodeInformationProvider

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

the class EntityCapsManager method updateLocalEntityCaps.

/**
 * Updates the local user Entity Caps information with the data provided
 *
 * If we are connected and there was already a presence send, another
 * presence is send to inform others about your new Entity Caps node string.
 */
private void updateLocalEntityCaps(DiscoverInfo synthesizedDiscoveryInfo) {
    XMPPConnection connection = connection();
    DiscoverInfoBuilder discoverInfoBuilder = synthesizedDiscoveryInfo.asBuilder("synthesized-disco-info-result");
    // getLocalNodeVer() will return a result only after currentCapsVersion is set. Therefore
    // set it first and then call getLocalNodeVer()
    currentCapsVersion = generateVerificationString(discoverInfoBuilder);
    final String localNodeVer = getLocalNodeVer();
    discoverInfoBuilder.setNode(localNodeVer);
    final DiscoverInfo discoverInfo = discoverInfoBuilder.build();
    addDiscoverInfoByNode(localNodeVer, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        CapsVersionAndHash oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(entityNode + '#' + oldCapsVersion.version);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    if (connection != null)
        JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion));
    final List<Identity> identities = new LinkedList<>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
    sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() {

        List<String> features = sdm.getFeatures();

        List<DataForm> packetExtensions = sdm.getExtendedInfo();

        @Override
        public List<String> getNodeFeatures() {
            return features;
        }

        @Override
        public List<Identity> getNodeIdentities() {
            return identities;
        }

        @Override
        public List<DataForm> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AbstractNodeInformationProvider(org.jivesoftware.smackx.disco.AbstractNodeInformationProvider) DiscoverInfoBuilder(org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) List(java.util.List) LinkedList(java.util.LinkedList) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)

Example 2 with AbstractNodeInformationProvider

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

the class AdHocCommandManager method registerCommand.

/**
 * Registers a new command with this command manager, which is related to a
 * connection. The <code>node</code> is an unique identifier of that
 * command for the connection related to this command manager. The <code>name</code>
 * is the human readable name of the command. The <code>factory</code> generates
 * new instances of the command.
 *
 * @param node the unique identifier of the command.
 * @param name the human readable name of the command.
 * @param factory a factory to create new instances of the command.
 */
public void registerCommand(String node, final String name, LocalCommandFactory factory) {
    AdHocCommandInfo commandInfo = new AdHocCommandInfo(node, name, connection().getUser(), factory);
    commands.put(node, commandInfo);
    // Set the NodeInformationProvider that will provide information about
    // the added command
    serviceDiscoveryManager.setNodeInformationProvider(node, new AbstractNodeInformationProvider() {

        @Override
        public List<String> getNodeFeatures() {
            List<String> answer = new ArrayList<>();
            answer.add(NAMESPACE);
            // TODO: check if this service is provided by the
            // TODO: current connection.
            answer.add("jabber:x:data");
            return answer;
        }

        @Override
        public List<DiscoverInfo.Identity> getNodeIdentities() {
            List<DiscoverInfo.Identity> answer = new ArrayList<>();
            DiscoverInfo.Identity identity = new DiscoverInfo.Identity("automation", name, "command-node");
            answer.add(identity);
            return answer;
        }
    });
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) AbstractNodeInformationProvider(org.jivesoftware.smackx.disco.AbstractNodeInformationProvider) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with AbstractNodeInformationProvider

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

the class EntityCapsManager method updateLocalEntityCaps.

/**
     * Updates the local user Entity Caps information with the data provided
     *
     * If we are connected and there was already a presence send, another
     * presence is send to inform others about your new Entity Caps node string.
     *
     */
public void updateLocalEntityCaps() {
    XMPPConnection connection = connection();
    DiscoverInfo discoverInfo = new DiscoverInfo();
    discoverInfo.setType(IQ.Type.result);
    sdm.addDiscoverInfoTo(discoverInfo);
    // getLocalNodeVer() will return a result only after currentCapsVersion is set. Therefore
    // set it first and then call getLocalNodeVer()
    currentCapsVersion = generateVerificationString(discoverInfo);
    final String localNodeVer = getLocalNodeVer();
    discoverInfo.setNode(localNodeVer);
    addDiscoverInfoByNode(localNodeVer, discoverInfo);
    if (lastLocalCapsVersions.size() > 10) {
        CapsVersionAndHash oldCapsVersion = lastLocalCapsVersions.poll();
        sdm.removeNodeInformationProvider(entityNode + '#' + oldCapsVersion.version);
    }
    lastLocalCapsVersions.add(currentCapsVersion);
    if (connection != null)
        JID_TO_NODEVER_CACHE.put(connection.getUser(), new NodeVerHash(entityNode, currentCapsVersion));
    final List<Identity> identities = new LinkedList<Identity>(ServiceDiscoveryManager.getInstanceFor(connection).getIdentities());
    sdm.setNodeInformationProvider(localNodeVer, new AbstractNodeInformationProvider() {

        List<String> features = sdm.getFeatures();

        List<ExtensionElement> packetExtensions = sdm.getExtendedInfoAsList();

        @Override
        public List<String> getNodeFeatures() {
            return features;
        }

        @Override
        public List<Identity> getNodeIdentities() {
            return identities;
        }

        @Override
        public List<ExtensionElement> getNodePacketExtensions() {
            return packetExtensions;
        }
    });
    // to respect ConnectionConfiguration.isSendPresence()
    if (connection != null && connection.isAuthenticated() && presenceSend != null) {
        try {
            connection.sendStanza(presenceSend.cloneWithNewId());
        } catch (InterruptedException | NotConnectedException e) {
            LOGGER.log(Level.WARNING, "Could could not update presence with caps info", e);
        }
    }
}
Also used : DiscoverInfo(org.jivesoftware.smackx.disco.packet.DiscoverInfo) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) AbstractNodeInformationProvider(org.jivesoftware.smackx.disco.AbstractNodeInformationProvider) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) XMPPConnection(org.jivesoftware.smack.XMPPConnection) LinkedList(java.util.LinkedList) List(java.util.List) LinkedList(java.util.LinkedList) Identity(org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)

Aggregations

List (java.util.List)3 AbstractNodeInformationProvider (org.jivesoftware.smackx.disco.AbstractNodeInformationProvider)3 DiscoverInfo (org.jivesoftware.smackx.disco.packet.DiscoverInfo)3 LinkedList (java.util.LinkedList)2 XMPPConnection (org.jivesoftware.smack.XMPPConnection)2 Identity (org.jivesoftware.smackx.disco.packet.DiscoverInfo.Identity)2 ArrayList (java.util.ArrayList)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)1 DiscoverInfoBuilder (org.jivesoftware.smackx.disco.packet.DiscoverInfoBuilder)1 DataForm (org.jivesoftware.smackx.xdata.packet.DataForm)1