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