1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-12-26 04:28:00 +01:00

Some improvements

This commit is contained in:
vanitasvitae 2017-06-21 15:54:20 +02:00
parent ecd29a1ea8
commit 7f04265bb9
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 32 additions and 32 deletions

View file

@ -77,11 +77,12 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
this.transportManager = tm.getTransportManager(initiate);
if (transportManager == null) {
//Fallback
//Try fallback.
pendingSessionInitiate = initiate;
transportManager = tm.getBestAvailableTransportManager();
if (transportManager == null) {
//No usable transports.
jutil.sendSessionTerminateUnsupportedTransports(initiate.getInitiator(), initiate.getSid());
state = State.terminated;
return jutil.createAck(initiate);

View file

@ -49,8 +49,7 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
sent_transport_replace,
active,
terminated,
;
}
;}
private Thread sendingThread;
private File source;
@ -66,20 +65,22 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
this(connection, recipient, JingleManager.randomSid());
}
public void sendFile(JingleFileTransfer file, JingleContent.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
if (state == State.fresh) {
transportManager = JingleTransportMethodManager.getInstanceFor(connection)
.getBestAvailableTransportManager();
if (transportManager == null) {
throw new IllegalStateException("There must be at least one workable transport method.");
}
transport = transportManager.createTransport(getResponder());
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
state = State.pending;
public void initiateFileOffer(JingleFileTransfer file, JingleContent.Creator creator, String name) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
if (state != State.fresh) {
throw new IllegalStateException("This session is not fresh.");
}
transportManager = JingleTransportMethodManager.getInstanceFor(connection)
.getBestAvailableTransportManager();
if (transportManager == null) {
throw new IllegalStateException("There must be at least one workable transport method.");
}
transport = transportManager.createTransport(getResponder());
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
state = State.pending;
}
@Override
@ -87,24 +88,22 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
// Out of order?
if (state != State.pending) {
LOGGER.log(Level.WARNING, "Out of order!");
jutil.sendErrorOutOfOrder(sessionAccept);
return jutil.createErrorOutOfOrder(sessionAccept);
}
// Legal
else {
state = State.active;
transportManager.initiateOutgoingSession(getResponder(), transport, new JingleTransportInitiationCallback() {
@Override
public void onSessionInitiated(final BytestreamSession session) {
sendingThread = new SendingThread(session, source);
sendingThread.run();
}
@Override
public void onException(Exception e) {
LOGGER.log(Level.SEVERE, "Cannot create outgoing Bytestream session: ", e);
}
});
}
state = State.active;
transportManager.initiateOutgoingSession(getResponder(), transport, new JingleTransportInitiationCallback() {
@Override
public void onSessionInitiated(final BytestreamSession session) {
sendingThread = new SendingThread(session, source);
sendingThread.run();
}
@Override
public void onException(Exception e) {
LOGGER.log(Level.SEVERE, "Cannot create outgoing Bytestream session: ", e);
}
});
return jutil.createAck(sessionAccept);
}