mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-24 04:52:05 +01:00
Add transport replace actions
This commit is contained in:
parent
2bac6297ee
commit
96197d4092
6 changed files with 142 additions and 1 deletions
|
@ -31,6 +31,7 @@ import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||||
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -60,6 +61,12 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
||||||
return jutil.createErrorOutOfOrder(initiate);
|
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);
|
JingleFileTransferManager.getInstanceFor(connection).notifyIncomingFileOffer(initiate, this);
|
||||||
setState(State.pending);
|
setState(State.pending);
|
||||||
return jutil.createAck(initiate);
|
return jutil.createAck(initiate);
|
||||||
|
|
|
@ -20,6 +20,9 @@ import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
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;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -45,6 +48,11 @@ public abstract class JingleFileTransferSession extends JingleSession {
|
||||||
protected final XMPPConnection connection;
|
protected final XMPPConnection connection;
|
||||||
protected final JingleUtil jutil;
|
protected final JingleUtil jutil;
|
||||||
|
|
||||||
|
protected JingleContent.Creator creator;
|
||||||
|
protected String name;
|
||||||
|
protected JingleFileTransfer file;
|
||||||
|
protected JingleContentTransport transport;
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
private State state;
|
private State state;
|
||||||
|
|
||||||
|
|
|
@ -21,9 +21,11 @@ import java.util.logging.Logger;
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
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.JingleContent;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
import org.jivesoftware.smackx.jingle.element.JingleContentTransport;
|
||||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||||
|
@ -60,4 +62,32 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
jutil.sendSessionInitiateFileOffer(getResponder(), getSessionId(), creator, name, file, transport);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.SmackException;
|
||||||
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
|
||||||
|
@ -177,7 +179,7 @@ public abstract class JingleSession implements JingleSessionHandler {
|
||||||
return IQ.createResultIQ(transportInfo);
|
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);
|
return IQ.createResultIQ(transportReplace);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,17 @@ public final class JingleTransportMethodManager extends Manager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public JingleTransportManager<?> getTransportManager(Jingle request) {
|
public JingleTransportManager<?> getTransportManager(Jingle request) {
|
||||||
|
|
||||||
JingleContent content = request.getContents().get(0);
|
JingleContent content = request.getContents().get(0);
|
||||||
|
if (content == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
JingleContentTransport transport = content.getJingleTransports().get(0);
|
JingleContentTransport transport = content.getJingleTransports().get(0);
|
||||||
|
if (transport == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return getTransportManager(transport.getNamespace());
|
return getTransportManager(transport.getNamespace());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,6 +355,91 @@ public class JingleUtil {
|
||||||
connection.sendStanza(createAck(jingle));
|
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) {
|
public IQ createErrorUnknownSession(Jingle request) {
|
||||||
XMPPError.Builder error = XMPPError.getBuilder();
|
XMPPError.Builder error = XMPPError.getBuilder();
|
||||||
error.setCondition(XMPPError.Condition.item_not_found)
|
error.setCondition(XMPPError.Condition.item_not_found)
|
||||||
|
|
Loading…
Reference in a new issue