mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-28 13:38:00 +01:00
Transport Fallback works, but does not save file
This commit is contained in:
parent
f26f3bb503
commit
4a8251fbe5
3 changed files with 87 additions and 36 deletions
|
@ -44,6 +44,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
|||
private static final Logger LOGGER = Logger.getLogger(IncomingJingleFileOffer.class.getName());
|
||||
private Jingle pendingSessionInitiate = null;
|
||||
private ReceiveTask receivingThread;
|
||||
private File target;
|
||||
|
||||
public enum State {
|
||||
fresh,
|
||||
|
@ -112,6 +113,55 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
|||
return jutil.createAck(initiate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportReplace(final Jingle transportReplace)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
final JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
|
||||
.getTransportManager(transportReplace);
|
||||
|
||||
queued.add(JingleManager.getThreadPool().submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (replacementManager != null) {
|
||||
LOGGER.log(Level.INFO, "Accept transport-replace.");
|
||||
IncomingJingleFileOffer.this.transportSession = replacementManager.transportSession(IncomingJingleFileOffer.this);
|
||||
transportSession.processJingle(transportReplace);
|
||||
transportSession.initiateIncomingSession(new JingleTransportInitiationCallback() {
|
||||
@Override
|
||||
public void onSessionInitiated(BytestreamSession bytestreamSession) {
|
||||
LOGGER.log(Level.INFO, "Bytestream initiated. Start receiving.");
|
||||
receivingThread = new ReceiveTask(bytestreamSession, file, target);
|
||||
queued.add(JingleManager.getThreadPool().submit(receivingThread));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception e) {
|
||||
LOGGER.log(Level.SEVERE, "EXCEPTION IN INCOMING SESSION: ", e);
|
||||
}
|
||||
});
|
||||
|
||||
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
|
||||
transportReplace.getInitiator(), transportReplace.getSid(),
|
||||
getContents().get(0).getCreator(), getContents().get(0).getName(),
|
||||
transportSession.createTransport());
|
||||
|
||||
} else {
|
||||
LOGGER.log(Level.INFO, "Unsupported transport. Reject transport-replace.");
|
||||
jutil.sendTransportReject(transportReplace.getFrom().asFullJidOrThrow(), transportReplace.getInitiator(),
|
||||
transportReplace.getSid(), getContents().get(0).getCreator(),
|
||||
getContents().get(0).getName(), transportReplace.getContents().get(0).getJingleTransport());
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
LOGGER.log(Level.SEVERE, "Help me please!", e);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
return jutil.createAck(transportReplace);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IQ handleTransportAccept(Jingle transportAccept) {
|
||||
LOGGER.log(Level.INFO, "Received transport-accept.");
|
||||
|
@ -134,6 +184,7 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
|||
|
||||
@Override
|
||||
public void acceptIncomingFileOffer(final Jingle request, final File target) {
|
||||
this.target = target;
|
||||
LOGGER.log(Level.INFO, "Client accepted incoming file offer. Try to start receiving.");
|
||||
if (transportSession == null) {
|
||||
//Unsupported transport
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.jivesoftware.smack.util.StringUtils;
|
|||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
|
@ -175,6 +174,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
|||
@Override
|
||||
public IQ handleTransportAccept(Jingle transportAccept)
|
||||
throws SmackException.NotConnectedException, InterruptedException {
|
||||
|
||||
return handleSessionAccept(transportAccept);
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
|||
if (next == null) {
|
||||
//Failure
|
||||
try {
|
||||
new JingleUtil(getConnection()).sendSessionTerminateUnsupportedTransports(getRemote(), getSessionId());
|
||||
jutil.sendSessionTerminateUnsupportedTransports(getRemote(), getSessionId());
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send session-terminate.", e);
|
||||
}
|
||||
|
|
|
@ -136,40 +136,40 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
@Override
|
||||
public IQ handleJingleSessionRequest(Jingle jingle) {
|
||||
try {
|
||||
switch (jingle.getAction()) {
|
||||
case content_accept:
|
||||
return handleContentAccept(jingle);
|
||||
case content_add:
|
||||
return handleContentAdd(jingle);
|
||||
case content_modify:
|
||||
return handleContentModify(jingle);
|
||||
case content_reject:
|
||||
return handleContentReject(jingle);
|
||||
case content_remove:
|
||||
return handleContentRemove(jingle);
|
||||
case description_info:
|
||||
return handleDescriptionInfo(jingle);
|
||||
case session_info:
|
||||
return handleSessionInfo(jingle);
|
||||
case security_info:
|
||||
return handleSecurityInfo(jingle);
|
||||
case session_accept:
|
||||
return handleSessionAccept(jingle);
|
||||
case transport_accept:
|
||||
return handleTransportAccept(jingle);
|
||||
case transport_info:
|
||||
return transportSession.handleTransportInfo(jingle);
|
||||
case session_initiate:
|
||||
return handleSessionInitiate(jingle);
|
||||
case transport_reject:
|
||||
return handleTransportReject(jingle);
|
||||
case session_terminate:
|
||||
return handleSessionTerminate(jingle);
|
||||
case transport_replace:
|
||||
return handleTransportReplace(jingle);
|
||||
default:
|
||||
return IQ.createResultIQ(jingle);
|
||||
}
|
||||
switch (jingle.getAction()) {
|
||||
case content_accept:
|
||||
return handleContentAccept(jingle);
|
||||
case content_add:
|
||||
return handleContentAdd(jingle);
|
||||
case content_modify:
|
||||
return handleContentModify(jingle);
|
||||
case content_reject:
|
||||
return handleContentReject(jingle);
|
||||
case content_remove:
|
||||
return handleContentRemove(jingle);
|
||||
case description_info:
|
||||
return handleDescriptionInfo(jingle);
|
||||
case session_info:
|
||||
return handleSessionInfo(jingle);
|
||||
case security_info:
|
||||
return handleSecurityInfo(jingle);
|
||||
case session_accept:
|
||||
return handleSessionAccept(jingle);
|
||||
case transport_accept:
|
||||
return handleTransportAccept(jingle);
|
||||
case transport_info:
|
||||
return transportSession.handleTransportInfo(jingle);
|
||||
case session_initiate:
|
||||
return handleSessionInitiate(jingle);
|
||||
case transport_reject:
|
||||
return handleTransportReject(jingle);
|
||||
case session_terminate:
|
||||
return handleSessionTerminate(jingle);
|
||||
case transport_replace:
|
||||
return handleTransportReplace(jingle);
|
||||
default:
|
||||
return IQ.createResultIQ(jingle);
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
return null; //TODO:
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue