1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-23 20:42:06 +01:00

Allow session-removal and use threads

This commit is contained in:
vanitasvitae 2017-07-28 00:55:44 +02:00
parent d37bdb5d20
commit b0c8a8027a
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
5 changed files with 84 additions and 65 deletions

View file

@ -253,4 +253,8 @@ public final class JingleManager extends Manager {
jingleSessions.put(new FullJidAndSessionId(peer, session.getSessionId()), session);
return session;
}
public void removeSession(JingleSession session) {
jingleSessions.remove(new FullJidAndSessionId(session.getPeer(), session.getSessionId()));
}
}

View file

@ -18,6 +18,8 @@ package org.jivesoftware.smackx.jingle.components;
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
import org.jivesoftware.smackx.jingle.element.JingleElement;
/**
* Class that represents a contents description component.
@ -34,6 +36,8 @@ public abstract class JingleDescription<D extends JingleContentDescriptionElemen
}
}
public abstract JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info);
public JingleContent getParent() {
return parent;
}

View file

@ -29,6 +29,7 @@ import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.util.Async;
import org.jivesoftware.smackx.jingle.JingleDescriptionManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.adapter.JingleTransportAdapter;
@ -166,7 +167,10 @@ public class JingleSession {
}
}
private IQ handleTransportReplace(JingleElement request) {
private IQ handleTransportReplace(final JingleElement request) {
Async.go(new Runnable() {
@Override
public void run() {
List<JingleContentElement> affectedContents = request.getContents();
List<JingleElement> responses = new ArrayList<>();
@ -198,7 +202,6 @@ public class JingleSession {
content.getCreator(), content.getName(), newTransport));
}
//TODO: Put in Thread?
for (JingleElement response : responses) {
try {
jingleManager.getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow();
@ -206,6 +209,8 @@ public class JingleSession {
LOGGER.log(Level.SEVERE, "Could not send response to transport-replace: " + e, e);
}
}
}
});
return IQ.createResultIQ(request);
}
@ -217,32 +222,10 @@ public class JingleSession {
throw new AssertionError("Reason MUST not be null! (I guess)...");
}
switch (reason.asEnum()) {
case alternative_session:
case busy:
case cancel:
case connectivity_error:
case decline:
// :(
case expired:
case failed_application:
case failed_transport:
case general_error:
// well... shit.
case gone:
case incompatible_parameters:
case media_error:
case security_error:
case success:
// Weeeeeh
break;
case timeout:
case unsupported_applications:
case unsupported_transports:
break;
default:
throw new AssertionError("Unknown reason enum: " + reason.asEnum().toString());
}
//TODO: Inform client.
jingleManager.removeSession(this);
return IQ.createResultIQ(request);
}
@ -270,7 +253,6 @@ public class JingleSession {
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
for (Map.Entry<JingleContentElement, JingleContent> entry : affectedContents.entrySet()) {
JingleTransport<?> transport = entry.getValue().getTransport();
JingleContentTransportInfoElement info = entry.getKey().getTransport().getInfo();
transport.handleTransportInfo(info, request);
@ -328,7 +310,22 @@ public class JingleSession {
}
private IQ handleDescriptionInfo(JingleElement request) {
return null;
HashMap<JingleContentElement, JingleContent> affectedContents = getAffectedContents(request);
List<JingleElement> responses = new ArrayList<>();
for (Map.Entry<JingleContentElement, JingleContent> entry : affectedContents.entrySet()) {
responses.add(entry.getValue().getDescription().handleDescriptionInfo(entry.getKey().getDescription().getDescriptionInfo()));
}
for (JingleElement response : responses) {
try {
getJingleManager().getConnection().createStanzaCollectorAndSend(response).nextResultOrThrow();
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException e) {
LOGGER.log(Level.SEVERE, "Could not send response to description-info: " + e, e);
}
}
return IQ.createResultIQ(request);
}
private IQ handleContentRemove(JingleElement request) {

View file

@ -57,6 +57,10 @@ public abstract class JingleContentDescriptionElement implements ExtensionElemen
return payloads;
}
public JingleContentDescriptionInfoElement getDescriptionInfo() {
return null; //TODO
}
protected void addExtraAttributes(XmlStringBuilder xml) {
}

View file

@ -0,0 +1,10 @@
package org.jivesoftware.smackx.jingle.element;
import org.jivesoftware.smack.packet.NamedElement;
/**
* Created by vanitas on 28.07.17.
*/
public abstract class JingleContentDescriptionInfoElement implements NamedElement {
}