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

Add transport replace actions

This commit is contained in:
vanitasvitae 2017-06-19 19:22:59 +02:00
parent 2bac6297ee
commit 96197d4092
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
6 changed files with 142 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
import org.jxmpp.jid.FullJid;
@ -60,6 +61,12 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
return jutil.createErrorOutOfOrder(initiate);
}
JingleContent content = initiate.getContents().get(0);
this.creator = content.getCreator();
this.file = (JingleFileTransfer) content.getDescription();
this.name = content.getName();
this.transport = content.getJingleTransports().get(0);
JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(initiate, this);
setState(State.pending);
return jutil.createAck(initiate);

View file

@ -20,6 +20,9 @@ import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.JingleUtil;
import org.jivesoftware.smackx.jingle.Role;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
import org.jxmpp.jid.FullJid;
@ -45,6 +48,11 @@ public abstract class JingleFileTransferSession extends JingleSession {
protected final XMPPConnection connection;
protected final JingleUtil jutil;
protected JingleContent.Creator creator;
protected String name;
protected JingleFileTransfer file;
protected JingleContentTransport transport;
private final Type type;
private State state;

View file

@ -21,9 +21,11 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
import org.jivesoftware.smackx.jingle.Role;
import org.jivesoftware.smackx.jingle.element.Jingle;
import org.jivesoftware.smackx.jingle.element.JingleContent;
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
@ -60,4 +62,32 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
}
}
@Override
public IQ handleSessionAccept(Jingle sessionAccept) {
//TODO
setState(State.active);
return jutil.createAck(sessionAccept);
}
@Override
public IQ handleSessionTerminate(Jingle sessionTerminate) {
//TODO
setState(State.terminated);
return jutil.createAck(sessionTerminate);
}
@Override
public IQ handleTransportReplace(Jingle transportReplace)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
JingleTransportManager<?> replacementManager = JingleTransportMethodManager.getInstanceFor(connection)
.getTransportManager(transportReplace);
if (replacementManager != null) {
jutil.sendTransportAccept(transportReplace.getFrom().asFullJidOrThrow(),
transportReplace.getInitiator(), transportReplace.getSid(), creator, name,
replacementManager.createTransport());
}
}
}

View file

@ -16,6 +16,8 @@
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smackx.jingle.element.Jingle;
@ -177,7 +179,7 @@ public abstract class JingleSession implements JingleSessionHandler {
return IQ.createResultIQ(transportInfo);
}
protected IQ handleTransportReplace(Jingle transportReplace) {
protected IQ handleTransportReplace(Jingle transportReplace) throws InterruptedException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, SmackException.NoResponseException {
return IQ.createResultIQ(transportReplace);
}

View file

@ -64,8 +64,17 @@ public final class JingleTransportMethodManager extends Manager {
}
public JingleTransportManager<?> getTransportManager(Jingle request) {
JingleContent content = request.getContents().get(0);
if (content == null) {
return null;
}
JingleContentTransport transport = content.getJingleTransports().get(0);
if (transport == null) {
return null;
}
return getTransportManager(transport.getNamespace());
}

View file

@ -355,6 +355,91 @@ public class JingleUtil {
connection.sendStanza(createAck(jingle));
}
public Jingle createTransportReplace(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setInitiator(initiator)
.setSessionId(sessionId)
.setAction(JingleAction.transport_replace);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setName(contentName).setCreator(contentCreator).addTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
public IQ sendTransportReplace(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportReplace(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createTransportAccept(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.transport_accept)
.setInitiator(initiator)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName).addTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
public IQ sendTransportAccept(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportAccept(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createTransportReject(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.transport_reject)
.setInitiator(initiator)
.setSessionId(sessionId);
JingleContent.Builder cb = JingleContent.getBuilder();
cb.setCreator(contentCreator).setName(contentName).addTransport(transport);
Jingle jingle = jb.addJingleContent(cb.build()).build();
jingle.setTo(recipient);
jingle.setFrom(connection.getUser());
return jingle;
}
public IQ sendTransportReject(FullJid recipient, FullJid initiator, String sessionId,
JingleContent.Creator contentCreator, String contentName,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createTransportReject(recipient, initiator, sessionId, contentCreator, contentName, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
/*
* ####################################################################################################
*/
public IQ createErrorUnknownSession(Jingle request) {
XMPPError.Builder error = XMPPError.getBuilder();
error.setCondition(XMPPError.Condition.item_not_found)