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;
}
});
}
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;
}
});
}
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);
}
}
}
Aggregations