mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-23 12:32:06 +01:00
Latest changes
This commit is contained in:
parent
d7f974dc69
commit
fb55b6caa8
3 changed files with 102 additions and 15 deletions
|
@ -94,10 +94,10 @@ public final class JingleManager extends Manager {
|
|||
// We have not seen this session before.
|
||||
// Either it is fresh, or unknown.
|
||||
if (session == null) {
|
||||
LOGGER.log(Level.INFO, connection().getUser().asFullJidOrThrow() + " received unknown session: " + jingle.getFrom().asFullJidOrThrow() + " " + jingle.getSid());
|
||||
if (jingle.getAction() == JingleAction.session_initiate) {
|
||||
//fresh. phew!
|
||||
try {
|
||||
LOGGER.log(Level.INFO, "Create new session with " + jingle.getFrom() + ": " + jingle.getSid());
|
||||
session = JingleSession.fromSessionInitiate(JingleManager.this, jingle);
|
||||
jingleSessions.put(fullJidAndSessionId, session);
|
||||
} catch (UnsupportedDescriptionException e) {
|
||||
|
@ -113,6 +113,7 @@ public final class JingleManager extends Manager {
|
|||
|
||||
} else {
|
||||
// Unknown session. Error!
|
||||
LOGGER.log(Level.INFO, connection().getUser().asFullJidOrThrow() + " received unknown session: " + jingle.getFrom().asFullJidOrThrow() + " " + jingle.getSid());
|
||||
return JingleElement.createJingleErrorUnknownSession(jingle);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,6 +178,7 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
|
|||
}
|
||||
|
||||
public void handleContentRemove(JingleSession session, XMPPConnection connection) {
|
||||
|
||||
}
|
||||
|
||||
private IQ handleSecurityInfo(JingleElement request, XMPPConnection connection) {
|
||||
|
@ -210,17 +211,22 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
|
|||
return transport.handleTransportInfo(content.getTransport().getInfo(), request);
|
||||
}
|
||||
|
||||
private IQ handleTransportReject(JingleElement request, XMPPConnection connection) {
|
||||
private IQ handleTransportReject(JingleElement request, final XMPPConnection connection) {
|
||||
if (pendingReplacingTransport == null) {
|
||||
throw new AssertionError("We didn't try to replace the transport.");
|
||||
}
|
||||
transportBlacklist.add(pendingReplacingTransport.getNamespace());
|
||||
pendingReplacingTransport = null;
|
||||
try {
|
||||
replaceTransport(transportBlacklist, connection);
|
||||
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not replace transport: " + e, e);
|
||||
}
|
||||
Async.go(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
transportBlacklist.add(pendingReplacingTransport.getNamespace());
|
||||
pendingReplacingTransport = null;
|
||||
try {
|
||||
replaceTransport(transportBlacklist, connection);
|
||||
} catch (SmackException.NotConnectedException | SmackException.NoResponseException | XMPPException.XMPPErrorException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not replace transport: " + e, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
return IQ.createResultIQ(request);
|
||||
}
|
||||
|
||||
|
@ -460,6 +466,20 @@ public class JingleContent implements JingleTransportCallback, JingleSecurityCal
|
|||
LOGGER.log(Level.SEVERE, "Security failed: " + e, e);
|
||||
}
|
||||
|
||||
public void onContentFinished() {
|
||||
JingleSession session = getParent();
|
||||
session.onContentFinished(this);
|
||||
}
|
||||
|
||||
public void onContentFailed(Exception e) {
|
||||
|
||||
}
|
||||
|
||||
public void onContentCancel() {
|
||||
JingleSession session = getParent();
|
||||
session.onContentCancel(this);
|
||||
}
|
||||
|
||||
private void replaceTransport(Set<String> blacklist, XMPPConnection connection)
|
||||
throws SmackException.NotConnectedException, InterruptedException,
|
||||
XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
||||
|
|
|
@ -145,6 +145,58 @@ public class JingleSession {
|
|||
return JingleElement.createSessionAccept(getInitiator(), getResponder(), getSessionId(), contentElements);
|
||||
}
|
||||
|
||||
void onContentFinished(JingleContent jingleContent) {
|
||||
if (contents.get(jingleContent.getName()) == null) {
|
||||
LOGGER.log(Level.WARNING, "Session does not contain content " + jingleContent.getName() + ". Ignore contentFinished.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (contents.size() == 1) {
|
||||
//Only content has finished. End session.
|
||||
terminateSession(JingleReasonElement.Reason.success);
|
||||
return;
|
||||
}
|
||||
|
||||
// Session has still active contents left.
|
||||
/*
|
||||
try {
|
||||
jingleManager.getConnection().createStanzaCollectorAndSend(JingleElement.createSessionTerminateContentCancel(
|
||||
getPeer(), getSessionId(), jingleContent.getCreator(), jingleContent.getName()));
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send content-cancel: " + e, e);
|
||||
}
|
||||
contents.remove(jingleContent.getName());
|
||||
*/
|
||||
}
|
||||
|
||||
void onContentCancel(JingleContent jingleContent) {
|
||||
if (contents.get(jingleContent.getName()) == null) {
|
||||
LOGGER.log(Level.WARNING, "Session does not contain content " + jingleContent.getName() + ". Ignore onContentCancel.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (contents.size() == 1) {
|
||||
terminateSession(JingleReasonElement.Reason.cancel);
|
||||
jingleManager.removeSession(this);
|
||||
} else {
|
||||
try {
|
||||
jingleManager.getConnection().createStanzaCollectorAndSend(JingleElement.createSessionTerminateContentCancel(getPeer(), getSessionId(), jingleContent.getCreator(), jingleContent.getName()));
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send content-cancel: " + e, e);
|
||||
}
|
||||
contents.remove(jingleContent.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void terminateSession(JingleReasonElement.Reason reason) {
|
||||
try {
|
||||
jingleManager.getConnection().createStanzaCollectorAndSend(JingleElement.createSessionTerminate(getPeer(), getSessionId(), reason));
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
||||
}
|
||||
jingleManager.removeSession(this);
|
||||
}
|
||||
|
||||
public IQ handleJingleRequest(JingleElement request) {
|
||||
switch (request.getAction()) {
|
||||
case content_modify:
|
||||
|
@ -198,15 +250,29 @@ public class JingleSession {
|
|||
}
|
||||
|
||||
private IQ handleSessionInitiate(JingleElement request) {
|
||||
JingleDescription<?> description = getSoleContentOrThrow().getDescription();
|
||||
JingleDescriptionManager descriptionManager = jingleManager.getDescriptionManager(description.getNamespace());
|
||||
final JingleDescription<?> description = getSoleContentOrThrow().getDescription();
|
||||
final JingleDescriptionManager descriptionManager = jingleManager.getDescriptionManager(description.getNamespace());
|
||||
|
||||
if (descriptionManager == null) {
|
||||
LOGGER.log(Level.WARNING, "Unsupported description type: " + description.getNamespace());
|
||||
return JingleElement.createSessionTerminate(getPeer(), getSessionId(), JingleReasonElement.Reason.unsupported_applications);
|
||||
}
|
||||
|
||||
descriptionManager.notifySessionInitiate(this);
|
||||
}
|
||||
Async.go(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (descriptionManager == null) {
|
||||
|
||||
LOGGER.log(Level.WARNING, "Unsupported description type: " + description.getNamespace());
|
||||
try {
|
||||
jingleManager.getConnection().createStanzaCollectorAndSend(JingleElement.createSessionTerminate(getPeer(), getSessionId(), JingleReasonElement.Reason.unsupported_applications));
|
||||
} catch (SmackException.NotConnectedException | InterruptedException e) {
|
||||
LOGGER.log(Level.SEVERE, "Could not send session-terminate: " + e, e);
|
||||
}
|
||||
|
||||
} else {
|
||||
descriptionManager.notifySessionInitiate(JingleSession.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return IQ.createResultIQ(request);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue