1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 17:49:38 +02:00
This commit is contained in:
vanitasvitae 2017-07-28 14:02:32 +02:00
parent b0c8a8027a
commit 185d569b89
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
18 changed files with 266 additions and 65 deletions

View file

@ -243,10 +243,10 @@ public final class JingleManager extends Manager {
JingleSession session;
if (role == Role.initiator) {
session = new JingleSession(this, connection().getUser().asDomainFullJidOrThrow(), peer,
session = new JingleSession(this, connection().getUser().asFullJidOrThrow(), peer,
role, StringUtils.randomString(24));
} else {
session = new JingleSession(this, peer, connection().getUser().asDomainFullJidOrThrow(),
session = new JingleSession(this, peer, connection().getUser().asFullJidOrThrow(),
role, StringUtils.randomString(24));
}

View file

@ -18,13 +18,15 @@ package org.jivesoftware.smackx.jingle.adapter;
import org.jivesoftware.smackx.jingle.components.JingleDescription;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
/**
* Adapter that creates a Description object from an element.
*/
public interface JingleDescriptionAdapter<D extends JingleDescription<?>> {
D descriptionFromElement(JingleContentDescriptionElement element);
D descriptionFromElement(JingleContentElement.Creator creator, JingleContentElement.Senders senders,
String contentName, String contentDisposition, JingleContentDescriptionElement element);
String getNamespace();
}

View file

@ -95,7 +95,7 @@ public class JingleContent implements JingleTransportCallback {
if (descriptionElement != null) {
JingleDescriptionAdapter<?> descriptionAdapter = JingleManager.getJingleDescriptionAdapter(content.getDescription().getNamespace());
if (descriptionAdapter != null) {
description = descriptionAdapter.descriptionFromElement(descriptionElement);
description = descriptionAdapter.descriptionFromElement(content.getCreator(), content.getSenders(), content.getName(), content.getDisposition(), descriptionElement);
} else {
throw new AssertionError("DescriptionProvider for " + descriptionElement.getNamespace() +
" seems to be registered, but no corresponding JingleDescriptionAdapter was found.");
@ -108,7 +108,7 @@ public class JingleContent implements JingleTransportCallback {
if (transportAdapter != null) {
transport = transportAdapter.transportFromElement(transportElement);
} else {
throw new AssertionError("DescriptionProvider for " + transportElement.getNamespace() +
throw new AssertionError("TransportProvider for " + transportElement.getNamespace() +
" seems to be registered, but no corresponding JingleTransportAdapter was found.");
}
}
@ -132,15 +132,19 @@ public class JingleContent implements JingleTransportCallback {
}
public JingleContentElement getElement() {
return JingleContentElement.getBuilder()
JingleContentElement.Builder builder = JingleContentElement.getBuilder()
.setName(name)
.setCreator(creator)
.setSenders(senders)
.setDescription(description.getElement())
.setTransport(transport.getElement())
.setSecurity(security.getElement())
.setDisposition(disposition)
.build();
.setDisposition(disposition);
if (security != null) {
builder.setSecurity(security.getElement());
}
return builder.build();
}
public Set<String> getTransportBlacklist() {

View file

@ -27,6 +27,7 @@ import java.util.logging.Level;
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.smack.util.Async;
@ -60,6 +61,15 @@ public class JingleSession {
private final Role role;
private final String sessionId;
public enum SessionState {
fresh, //pre-session-inititate
pending, //pre-session-accept
active, //pre-session-terminate
ended //post-session-terminate
}
private SessionState sessionState;
private final Map<JingleContent, PendingJingleAction> pendingJingleActions =
Collections.synchronizedMap(new HashMap<JingleContent, PendingJingleAction>());
@ -69,6 +79,7 @@ public class JingleSession {
this.responder = responder;
this.role = role;
this.sessionId = sessionId;
this.sessionState = SessionState.fresh;
}
public void addContent(JingleContent content) {
@ -114,9 +125,16 @@ public class JingleSession {
session.addContent(content);
}
session.sessionState = SessionState.pending;
return session;
}
public void initiate(XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException, SmackException.NoResponseException {
connection.createStanzaCollectorAndSend(createSessionInitiate()).nextResultOrThrow();
this.sessionState = SessionState.pending;
}
public JingleElement createSessionInitiate() {
if (role != Role.initiator) {
throw new IllegalStateException("Sessions role is not initiator.");
@ -216,6 +234,7 @@ public class JingleSession {
}
private IQ handleSessionTerminate(JingleElement request) {
this.sessionState = SessionState.ended;
JingleReasonElement reason = request.getReason();
if (reason == null) {
@ -223,7 +242,6 @@ public class JingleSession {
}
//TODO: Inform client.
jingleManager.removeSession(this);
return IQ.createResultIQ(request);
@ -231,7 +249,9 @@ public class JingleSession {
private IQ handleTransportReject(JingleElement request) {
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
for (JingleContent c : affectedContents.values()) {
}
return null;
}
@ -283,6 +303,8 @@ public class JingleSession {
}
private IQ handleSessionAccept(JingleElement request) {
this.sessionState = SessionState.active;
return null;
}
@ -430,4 +452,8 @@ public class JingleSession {
}
return map;
}
public SessionState getSessionState() {
return sessionState;
}
}

View file

@ -37,6 +37,10 @@ public final class JingleIBBTransportManager extends Manager implements JingleTr
private static final WeakHashMap<XMPPConnection, JingleIBBTransportManager> INSTANCES = new WeakHashMap<>();
static {
JingleManager.addJingleTransportAdapter(new JingleIBBTransportAdapter());
}
private JingleIBBTransportManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());

View file

@ -68,6 +68,10 @@ public final class JingleS5BTransportManager extends Manager implements JingleTr
private static boolean useLocalCandidates = true;
private static boolean useExternalCandidates = true;
static {
JingleManager.addJingleTransportAdapter(new JingleS5BTransportAdapter());
}
private JingleS5BTransportManager(XMPPConnection connection) {
super(connection);
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());