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

Merge branch 'jingleFTElements' into jingle2

This commit is contained in:
vanitasvitae 2017-06-18 13:08:56 +02:00
commit 49868ecdaf

View file

@ -32,7 +32,7 @@ import org.jivesoftware.smackx.jingle.element.JingleReason;
import org.jxmpp.jid.FullJid; import org.jxmpp.jid.FullJid;
/** /**
* Util to quickly send jingle stanzas. * Util to quickly create and send jingle stanzas.
*/ */
public class JingleUtil { public class JingleUtil {
@ -42,15 +42,13 @@ public class JingleUtil {
this.connection = connection; this.connection = connection;
} }
public IQ sendSessionInitiate(FullJid recipient, public Jingle createSessionInitiate(FullJid recipient,
String sessionId, String sessionId,
JingleContent.Creator contentCreator, JingleContent.Creator contentCreator,
String contentName, String contentName,
JingleContent.Senders contentSenders, JingleContent.Senders contentSenders,
JingleContentDescription description, JingleContentDescription description,
JingleContentTransport transport) JingleContentTransport transport) {
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_initiate) jb.setAction(JingleAction.session_initiate)
@ -68,18 +66,32 @@ public class JingleUtil {
jingle.setFrom(connection.getUser()); jingle.setFrom(connection.getUser());
jingle.setTo(recipient); jingle.setTo(recipient);
return jingle;
}
public IQ sendSessionInitiate(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionInitiate(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionAccept(FullJid recipient, public Jingle createSessionAccept(FullJid recipient,
String sessionId, String sessionId,
JingleContent.Creator contentCreator, JingleContent.Creator contentCreator,
String contentName, String contentName,
JingleContent.Senders contentSenders, JingleContent.Senders contentSenders,
JingleContentDescription description, JingleContentDescription description,
JingleContentTransport transport) JingleContentTransport transport) {
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setResponder(connection.getUser()) jb.setResponder(connection.getUser())
@ -97,9 +109,42 @@ public class JingleUtil {
jingle.setTo(recipient); jingle.setTo(recipient);
jingle.setFrom(connection.getUser()); jingle.setFrom(connection.getUser());
return jingle;
}
public IQ sendSessionAccept(FullJid recipient,
String sessionId,
JingleContent.Creator contentCreator,
String contentName,
JingleContent.Senders contentSenders,
JingleContentDescription description,
JingleContentTransport transport)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionAccept(recipient, sessionId, contentCreator, contentName, contentSenders,
description, transport);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public Jingle createSessionTerminate(FullJid recipient, String sessionId, JingleReason reason) {
Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId)
.setReason(reason);
Jingle jingle = jb.build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return jingle;
}
public Jingle createSessionTerminate(FullJid recipient, String sessionId, JingleReason.Reason reason) {
return createSessionTerminate(recipient, sessionId, new JingleReason(reason));
}
private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason.Reason reason) private IQ sendSessionTerminate(FullJid recipient, String sessionId, JingleReason.Reason reason)
throws SmackException.NotConnectedException, InterruptedException, throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException { XMPPException.XMPPErrorException, SmackException.NoResponseException {
@ -111,61 +156,74 @@ public class JingleUtil {
throws SmackException.NotConnectedException, InterruptedException, throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException { XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle.Builder jb = Jingle.getBuilder(); Jingle jingle = createSessionTerminate(recipient, sessionId, reason);
jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId)
.setReason(reason);
Jingle jingle = jb.build();
jingle.setFrom(connection.getUser());
jingle.setTo(recipient);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionTerminateDecline(FullJid recipient, public Jingle createSessionTerminateDecline(FullJid recipient, String sessionId) {
String sessionId) return createSessionTerminate(recipient, sessionId, JingleReason.Reason.decline);
}
public IQ sendSessionTerminateDecline(FullJid recipient, String sessionId)
throws SmackException.NotConnectedException, InterruptedException, throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException { XMPPException.XMPPErrorException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.decline);
Jingle jingle = createSessionTerminateDecline(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionTerminateSuccess(FullJid recipient, public Jingle createSessionTerminateSuccess(FullJid recipient, String sessionId) {
String sessionId) return createSessionTerminate(recipient, sessionId, JingleReason.Reason.success);
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.success);
} }
public IQ sendSessionTerminateBusy(FullJid recipient, public IQ sendSessionTerminateSuccess(FullJid recipient, String sessionId)
String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.busy);
Jingle jingle = createSessionTerminateSuccess(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionTerminateAlternativeSession(FullJid recipient, public Jingle createSessionTerminateBusy(FullJid recipient, String sessionId) {
String sessionId, return createSessionTerminate(recipient, sessionId, JingleReason.Reason.busy);
String altSessionId) }
public IQ sendSessionTerminateBusy(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.AlternativeSession(altSessionId));
Jingle jingle = createSessionTerminateBusy(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.AlternativeSession(altSessionId));
}
public IQ sendSessionTerminateAlternativeSession(FullJid recipient, String sessionId, String altSessionId)
throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateAlternativeSession(recipient, sessionId, altSessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateCancel(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.cancel);
} }
public IQ sendSessionTerminateCancel(FullJid recipient, public IQ sendSessionTerminateCancel(FullJid recipient,
String sessionId) String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.cancel);
Jingle jingle = createSessionTerminateCancel(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionTerminateContentCancel(FullJid recipient, public Jingle createSessionTerminateContentCancel(FullJid recipient, String sessionId,
String sessionId, JingleContent.Creator contentCreator, String contentName) {
JingleContent.Creator contentCreator,
String contentName)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setAction(JingleAction.session_terminate) jb.setAction(JingleAction.session_terminate)
.setSessionId(sessionId); .setSessionId(sessionId);
@ -177,43 +235,73 @@ public class JingleUtil {
jingle.setFrom(connection.getUser()); jingle.setFrom(connection.getUser());
jingle.setTo(recipient); jingle.setTo(recipient);
return jingle;
}
public IQ sendSessionTerminateContentCancel(FullJid recipient, String sessionId,
JingleContent.Creator contentCreator, String contentName)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionTerminateContentCancel(recipient, sessionId, contentCreator, contentName);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public Jingle createSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_transports);
}
public IQ sendSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId) public IQ sendSessionTerminateUnsupportedTransports(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_transports); Jingle jingle = createSessionTerminateUnsupportedTransports(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateFailedTransport(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_transport);
} }
public IQ sendSessionTerminateFailedTransport(FullJid recipient, String sessionId) public IQ sendSessionTerminateFailedTransport(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_transport); Jingle jingle = createSessionTerminateFailedTransport(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_applications);
} }
public IQ sendSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId) public IQ sendSessionTerminateUnsupportedApplications(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.unsupported_applications); Jingle jingle = createSessionTerminateUnsupportedApplications(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateFailedApplication(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_application);
} }
public IQ sendSessionTerminateFailedApplication(FullJid recipient, String sessionId) public IQ sendSessionTerminateFailedApplication(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.failed_application); Jingle jingle = createSessionTerminateFailedApplication(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
}
public Jingle createSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId) {
return createSessionTerminate(recipient, sessionId, JingleReason.Reason.incompatible_parameters);
} }
public IQ sendSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId) public IQ sendSessionTerminateIncompatibleParameters(FullJid recipient, String sessionId)
throws InterruptedException, XMPPException.XMPPErrorException, throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException { SmackException.NotConnectedException, SmackException.NoResponseException {
return sendSessionTerminate(recipient, sessionId, JingleReason.Reason.incompatible_parameters); Jingle jingle = createSessionTerminateIncompatibleParameters(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ sendSessionPing(FullJid recipient, String sessionId) public Jingle createSessionPing(FullJid recipient, String sessionId) {
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle.Builder jb = Jingle.getBuilder(); Jingle.Builder jb = Jingle.getBuilder();
jb.setSessionId(sessionId) jb.setSessionId(sessionId)
.setAction(JingleAction.session_info); .setAction(JingleAction.session_info);
@ -222,31 +310,47 @@ public class JingleUtil {
jingle.setFrom(connection.getUser()); jingle.setFrom(connection.getUser());
jingle.setTo(recipient); jingle.setTo(recipient);
return jingle;
}
public IQ sendSessionPing(FullJid recipient, String sessionId)
throws SmackException.NotConnectedException, InterruptedException,
XMPPException.XMPPErrorException, SmackException.NoResponseException {
Jingle jingle = createSessionPing(recipient, sessionId);
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow(); return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
} }
public IQ createErrorUnknownSession(Jingle request) {
XMPPError.Builder error = XMPPError.getBuilder();
error.setCondition(XMPPError.Condition.item_not_found)
.addExtension(JingleError.UNKNOWN_SESSION);
return IQ.createErrorResponse(request, error);
}
public void sendErrorUnknownSession(Jingle request) public void sendErrorUnknownSession(Jingle request)
throws SmackException.NotConnectedException, InterruptedException { throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorUnknownSession(request));
}
XMPPError.Builder error = XMPPError.getBuilder(); public IQ createErrorUnknownInitiator(Jingle request) {
error.setCondition(XMPPError.Condition.item_not_found) return IQ.createErrorResponse(request, XMPPError.Condition.service_unavailable);
.addExtension(JingleError.UNKNOWN_SESSION);
connection.sendStanza(IQ.createErrorResponse(request, error));
} }
public void sendErrorUnknownInitiator(Jingle request) public void sendErrorUnknownInitiator(Jingle request)
throws SmackException.NotConnectedException, InterruptedException { throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(IQ.createErrorResponse(request, XMPPError.Condition.service_unavailable)); connection.sendStanza(createErrorUnknownInitiator(request));
} }
public void sendErrorUnsupportedInfo(Jingle request) public IQ createErrorUnsupportedInfo(Jingle request) {
throws SmackException.NotConnectedException, InterruptedException {
XMPPError.Builder error = XMPPError.getBuilder(); XMPPError.Builder error = XMPPError.getBuilder();
error.setCondition(XMPPError.Condition.feature_not_implemented) error.setCondition(XMPPError.Condition.feature_not_implemented)
.addExtension(JingleError.UNSUPPORTED_INFO); .addExtension(JingleError.UNSUPPORTED_INFO);
connection.sendStanza(IQ.createErrorResponse(request, error)); return IQ.createErrorResponse(request, error);
}
public void sendErrorUnsupportedInfo(Jingle request)
throws SmackException.NotConnectedException, InterruptedException {
connection.sendStanza(createErrorUnsupportedInfo(request));
} }
} }