mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-09 17:19:39 +02:00
Add S5B candidate accept/error
This commit is contained in:
parent
a101de29fd
commit
699a19d3c2
8 changed files with 118 additions and 32 deletions
|
@ -17,6 +17,7 @@
|
|||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
@ -27,6 +28,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
@ -42,11 +44,17 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
|
||||
protected final String sid;
|
||||
|
||||
protected final List<JingleContent> contents = new ArrayList<>();
|
||||
|
||||
protected ExecutorService threadPool = Executors.newSingleThreadExecutor();
|
||||
protected ArrayList<Future<?>> queued = new ArrayList<>();
|
||||
protected JingleTransportSession<?> transportSession;
|
||||
|
||||
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid) {
|
||||
this(initiator, responder, role, sid, null);
|
||||
}
|
||||
|
||||
public JingleSession(FullJid initiator, FullJid responder, Role role, String sid, List<JingleContent> contents) {
|
||||
if (role == Role.initiator) {
|
||||
this.local = initiator;
|
||||
this.remote = responder;
|
||||
|
@ -56,6 +64,10 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
}
|
||||
this.sid = sid;
|
||||
this.role = role;
|
||||
|
||||
if (contents != null) {
|
||||
this.contents.addAll(contents);
|
||||
}
|
||||
}
|
||||
|
||||
public FullJid getInitiator() {
|
||||
|
@ -90,6 +102,10 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
return new FullJidAndSessionId(remote, sid);
|
||||
}
|
||||
|
||||
public List<JingleContent> getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
public JingleTransportSession<?> getTransportSession() {
|
||||
return transportSession;
|
||||
}
|
||||
|
|
|
@ -59,9 +59,5 @@ public abstract class JingleTransportSession<T extends JingleContentTransport> {
|
|||
|
||||
public abstract IQ handleTransportInfo(Jingle transportInfo);
|
||||
|
||||
public void setRemoteTransport(JingleContentTransport remoteTransport) {
|
||||
this.remoteTransport = remoteTransport;
|
||||
}
|
||||
|
||||
public abstract JingleTransportManager<T> transportManager();
|
||||
}
|
||||
|
|
|
@ -89,7 +89,6 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
|
|||
public void incomingBytestreamRequest(BytestreamRequest request) {
|
||||
if (request.getFrom().asFullJidIfPossible().equals(jingleSession.get().getRemote())
|
||||
&& request.getSessionID().equals(ibbTransport.getSessionId())) {
|
||||
LOGGER.log(Level.INFO,"MATCH! Create bytesteam session.");
|
||||
BytestreamSession session;
|
||||
|
||||
try {
|
||||
|
@ -99,8 +98,6 @@ public class JingleIBBTransportSession extends JingleTransportSession<JingleIBBT
|
|||
return;
|
||||
}
|
||||
callback.onSessionInitiated(session);
|
||||
} else {
|
||||
LOGGER.log(Level.SEVERE, "MISSMATCH");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -30,12 +30,16 @@ import org.jivesoftware.smack.packet.IQ;
|
|||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager;
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportSession;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.elements.JingleS5BTransport;
|
||||
import org.jivesoftware.smackx.jingle.transports.jingle_s5b.provider.JingleS5BTransportProvider;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
import org.jxmpp.jid.Jid;
|
||||
|
||||
/**
|
||||
|
@ -131,4 +135,40 @@ public final class JingleS5BTransportManager extends JingleTransportManager<Jing
|
|||
LOGGER.log(Level.WARNING, "Could not query available StreamHosts: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
public Jingle createCandidateUsed(FullJid recipient, String sessionId, JingleContent.Senders contentSenders,
|
||||
JingleContent.Creator contentCreator, String contentName, String streamId,
|
||||
String candidateId) {
|
||||
Jingle.Builder jb = Jingle.getBuilder();
|
||||
jb.setSessionId(sessionId).setInitiator(recipient).setAction(JingleAction.transport_info);
|
||||
|
||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||
cb.setName(contentName).setCreator(contentCreator).setSenders(contentSenders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
tb.setCandidateUsed(candidateId).setStreamId(streamId);
|
||||
|
||||
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
|
||||
jingle.setTo(recipient);
|
||||
|
||||
return jingle;
|
||||
}
|
||||
|
||||
public Jingle createCandidateError(FullJid remote, String sessionId, JingleContent.Senders senders, JingleContent.Creator creator, String name, String streamId) {
|
||||
Jingle.Builder jb = Jingle.getBuilder();
|
||||
jb.setSessionId(sessionId).setInitiator(remote).setAction(JingleAction.transport_info);
|
||||
|
||||
JingleContent.Builder cb = JingleContent.getBuilder();
|
||||
cb.setName(name).setCreator(creator).setSenders(senders);
|
||||
|
||||
JingleS5BTransport.Builder tb = JingleS5BTransport.getBuilder();
|
||||
tb.setCandidateError();
|
||||
|
||||
Jingle jingle = jb.addJingleContent(cb.setTransport(tb.build()).build()).build();
|
||||
jingle.setFrom(getConnection().getUser().asFullJidOrThrow());
|
||||
jingle.setTo(remote);
|
||||
|
||||
return jingle;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ import org.jivesoftware.smackx.bytestreams.socks5.packet.Bytestream;
|
|||
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||
import org.jivesoftware.smackx.jingle.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentTransportCandidate;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
|
@ -47,6 +48,9 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
private static final Logger LOGGER = Logger.getLogger(JingleS5BTransportSession.class.getName());
|
||||
private final JingleS5BTransportManager transportManager;
|
||||
|
||||
private Socket connectedSocket;
|
||||
private JingleS5BTransportCandidate usedCandidate;
|
||||
|
||||
public JingleS5BTransportSession(JingleSession jingleSession) {
|
||||
super(jingleSession);
|
||||
transportManager = JingleS5BTransportManager.getInstanceFor(jingleSession.getConnection());
|
||||
|
@ -91,6 +95,11 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
|
||||
@Override
|
||||
public void initiateOutgoingSession(JingleTransportInitiationCallback callback) {
|
||||
JingleSession jSession = jingleSession.get();
|
||||
if (jSession == null) {
|
||||
throw new NullPointerException("Lost reference to jingleSession.");
|
||||
}
|
||||
|
||||
JingleS5BTransport receivedTransport = (JingleS5BTransport) remoteTransport;
|
||||
|
||||
Socket socket = null;
|
||||
|
@ -112,8 +121,29 @@ public class JingleS5BTransportSession extends JingleTransportSession<JingleS5BT
|
|||
+ receivedTransport.getDestinationAddress());
|
||||
}
|
||||
|
||||
if (socket != null) {
|
||||
JingleContent content = jSession.getContents().get(0);
|
||||
|
||||
Jingle response;
|
||||
|
||||
if (socket != null) {
|
||||
connectedSocket = socket;
|
||||
usedCandidate = workedForUs;
|
||||
|
||||
response = transportManager.createCandidateUsed(jSession.getRemote(),
|
||||
jSession.getSessionId(), content.getSenders(), content.getCreator(),
|
||||
content.getName(), receivedTransport.getStreamId(), usedCandidate.getCandidateId());
|
||||
|
||||
} else {
|
||||
response = transportManager.createCandidateError(jSession.getRemote(),
|
||||
jSession.getSessionId(), content.getSenders(), content.getCreator(),
|
||||
content.getName(), receivedTransport.getStreamId());
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
jSession.getConnection().sendStanza(response);
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Could not send candidate-used.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue