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, message) -> {
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(XMPPError.Condition.conflict.toString())) {
return;
}
}
final String userid = p.getFrom();
String displayName = XmppStringUtils.parseResource(userid);
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 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 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 Smack by igniterealtime.
the class Socks5BytestreamManager method enableService.
/**
* Adds the SOCKS5 Bytestream feature to the service discovery.
*/
private void enableService() {
ServiceDiscoveryManager manager = ServiceDiscoveryManager.getInstanceFor(connection());
manager.addFeature(Bytestream.NAMESPACE);
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class Socks5BytestreamManager method determineProxies.
/**
* Returns a list of JIDs of SOCKS5 proxies by querying the XMPP server. The SOCKS5 proxies are
* in the same order as returned by the XMPP server.
*
* @return list of JIDs of SOCKS5 proxies
* @throws XMPPErrorException if there was an error querying the XMPP server for SOCKS5 proxies
* @throws NoResponseException if there was no response from the server.
* @throws NotConnectedException if the XMPP connection is not connected.
* @throws InterruptedException if the calling thread was interrupted.
*/
public List<Jid> determineProxies() throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
XMPPConnection connection = connection();
ServiceDiscoveryManager serviceDiscoveryManager = ServiceDiscoveryManager.getInstanceFor(connection);
List<Jid> proxies = new ArrayList<>();
// get all items from XMPP server
DiscoverItems discoverItems = serviceDiscoveryManager.discoverItems(connection.getXMPPServiceDomain());
// query all items if they are SOCKS5 proxies
for (Item item : discoverItems.getItems()) {
// skip blacklisted servers
if (this.proxyBlacklist.contains(item.getEntityID())) {
continue;
}
DiscoverInfo proxyInfo;
try {
proxyInfo = serviceDiscoveryManager.discoverInfo(item.getEntityID());
} catch (NoResponseException | XMPPErrorException e) {
// blacklist errornous server
proxyBlacklist.add(item.getEntityID());
continue;
}
if (proxyInfo.hasIdentity("proxy", "bytestreams")) {
proxies.add(item.getEntityID());
} else {
/*
* server is not a SOCKS5 proxy, blacklist server to skip next time a Socks5
* bytestream should be established
*/
this.proxyBlacklist.add(item.getEntityID());
}
}
return proxies;
}
use of org.jivesoftware.smackx.disco.ServiceDiscoveryManager in project Smack by igniterealtime.
the class EntityTimeManager method enable.
public synchronized void enable() {
if (enabled)
return;
ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(connection());
sdm.addFeature(Time.NAMESPACE);
enabled = true;
}
Aggregations