use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class UserTuneIntegrationTest method registerListenerAndWait.
/**
* Registers a listener for User Tune data. This implicitly publishes a CAPS update to include a notification
* filter for the usertune node. This method blocks until the server has indicated that this update has been
* received.
*
* @param userTuneManager The UserTuneManager instance for the connection that is expected to receive data.
* @param discoManager The ServiceDiscoveryManager instance for the connection that is expected to publish data.
* @param listener A listener instance for UserTune data that is to be registered.
*
* @throws Exception if the test fails
*/
public void registerListenerAndWait(UserTuneManager userTuneManager, ServiceDiscoveryManager discoManager, PepEventListener<UserTuneElement> listener) throws Exception {
final SimpleResultSyncPoint notificationFilterReceived = new SimpleResultSyncPoint();
final EntityCapabilitiesChangedListener notificationFilterReceivedListener = info -> {
if (info.containsFeature(UserTuneManager.USERTUNE_NODE + "+notify")) {
notificationFilterReceived.signal();
}
};
discoManager.addEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
try {
userTuneManager.addUserTuneListener(listener);
notificationFilterReceived.waitForResult(timeout);
} finally {
discoManager.removeEntityCapabilitiesChangedListener(notificationFilterReceivedListener);
}
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class RTPBridge method serviceAvailable.
/**
* Check if the server support RTPBridge Service.
*
* @param connection TODO javadoc me please
* @return true if the server supports the RTPBridge service
* @throws XMPPErrorException if there was an XMPP error returned.
* @throws NoResponseException if there was no response from the remote entity.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public static boolean serviceAvailable(XMPPConnection connection) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
if (!connection.isConnected()) {
return false;
}
LOGGER.fine("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
// DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
// Iterator iter = items.getItems();
// while (iter.hasNext()) {
// DiscoverItems.Item item = (DiscoverItems.Item) iter.next();
// if (item.getEntityID().startsWith("rtpbridge.")) {
// return true;
// }
// }
DiscoverInfo discoInfo = disco.discoverInfo(connection.getXMPPServiceDomain());
for (DiscoverInfo.Identity identity : discoInfo.getIdentities()) {
if (identity.getName() != null && identity.getName().startsWith("rtpbridge")) {
return true;
}
}
return false;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class STUN method serviceAvailable.
/**
* Check if the server support STUN Service.
*
* @param connection the connection
* @return true if the server support STUN
* @throws SmackException if Smack detected an exceptional situation.
* @throws XMPPException if an XMPP protocol error was received.
* @throws InterruptedException if the calling thread was interrupted.
*/
public static boolean serviceAvailable(XMPPConnection connection) throws XMPPException, SmackException, InterruptedException {
if (!connection.isConnected()) {
return false;
}
LOGGER.fine("Service listing");
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection);
DiscoverItems items = disco.discoverItems(connection.getXMPPServiceDomain());
for (DiscoverItems.Item item : items.getItems()) {
DiscoverInfo info = disco.discoverInfo(item.getEntityID());
for (DiscoverInfo.Identity identity : info.getIdentities()) {
if (identity.getCategory().equals("proxy") && identity.getType().equals("stun"))
if (info.containsFeature(NAMESPACE))
return true;
}
LOGGER.fine(item.getName() + "-" + info.getType());
}
return false;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project xabber-android by redsolution.
the class BlockingManager method discoverSupport.
private void discoverSupport(XMPPConnection xmppConnection) throws SmackException.NotConnectedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(xmppConnection);
final String account = xmppConnection.getUser();
final boolean isSupported = discoManager.serverSupportsFeature(XmlConstants.NAMESPACE);
if (isSupported) {
LogManager.i(this, "Blocking is supported for account" + account);
}
supportForAccounts.put(account, isSupported);
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Spark by igniterealtime.
the class ConferenceServiceBrowser method getConferenceServices.
public Collection<String> getConferenceServices(String server) throws Exception {
List<String> answer = new ArrayList<>();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(SparkManager.getConnection());
DiscoverItems items = discoManager.discoverItems(server);
for (DiscoverItems.Item item : items.getItems()) {
if (item.getEntityID().startsWith("conference") || item.getEntityID().startsWith("private")) {
answer.add(item.getEntityID());
} else {
try {
DiscoverInfo info = discoManager.discoverInfo(item.getEntityID());
if (info.containsFeature("http://jabber.org/protocol/muc")) {
answer.add(item.getEntityID());
}
} catch (XMPPException | SmackException e) {
// Nothing to do
}
}
}
return answer;
}
Aggregations