mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 01:29:38 +02:00
Check for disco support before file transfers
This commit is contained in:
parent
6fad0b9fab
commit
cac35d74b4
6 changed files with 37 additions and 22 deletions
|
@ -22,6 +22,7 @@ import java.util.WeakHashMap;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
||||
import org.jivesoftware.smackx.ciphers.Aes256GcmNoPadding;
|
||||
|
@ -82,6 +83,11 @@ public final class JetManager extends Manager implements JingleDescriptionManage
|
|||
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
||||
}
|
||||
|
||||
ServiceDiscoveryManager disco = ServiceDiscoveryManager.getInstanceFor(connection());
|
||||
if (!disco.supportsFeature(recipient, getNamespace()) || !disco.supportsFeature(recipient, method.getNamespace())) {
|
||||
throw new SmackException.FeatureNotSupportedException(getNamespace(), recipient);
|
||||
}
|
||||
|
||||
JingleSession session = jingleManager.createSession(Role.initiator, recipient);
|
||||
|
||||
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
|
@ -90,7 +96,7 @@ public final class JetManager extends Manager implements JingleDescriptionManage
|
|||
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
||||
content.setDescription(offer);
|
||||
|
||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager();
|
||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(recipient);
|
||||
content.setTransport(transportManager.createTransportForInitiator(content));
|
||||
|
||||
JetSecurity security = new JetSecurity(method, recipient, content.getName(), Aes256GcmNoPadding.NAMESPACE);
|
||||
|
|
|
@ -90,12 +90,16 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
|
||||
public OutgoingFileOfferController sendFile(File file, FullJid to)
|
||||
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NoResponseException {
|
||||
SmackException.NoResponseException, SmackException.FeatureNotSupportedException {
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
||||
}
|
||||
|
||||
if (!ServiceDiscoveryManager.getInstanceFor(connection()).supportsFeature(to, getNamespace())) {
|
||||
throw new SmackException.FeatureNotSupportedException(getNamespace(), to);
|
||||
}
|
||||
|
||||
JingleSession session = jingleManager.createSession(Role.initiator, to);
|
||||
|
||||
JingleContent content = new JingleContent(JingleContentElement.Creator.initiator, JingleContentElement.Senders.initiator);
|
||||
|
@ -104,7 +108,7 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
JingleOutgoingFileOffer offer = new JingleOutgoingFileOffer(file);
|
||||
content.setDescription(offer);
|
||||
|
||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager();
|
||||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager(to);
|
||||
content.setTransport(transportManager.createTransportForInitiator(content));
|
||||
|
||||
session.initiate(connection());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue