mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-24 04:52:05 +01:00
Join JingleSession and Handler in JingleFT
This commit is contained in:
parent
b91a9c120f
commit
1912ebb8d0
8 changed files with 162 additions and 60 deletions
|
@ -24,6 +24,7 @@ import org.jxmpp.jid.FullJid;
|
||||||
* Offer.
|
* Offer.
|
||||||
*/
|
*/
|
||||||
public class JingleFileOffer extends JingleFileTransferSession {
|
public class JingleFileOffer extends JingleFileTransferSession {
|
||||||
|
|
||||||
public JingleFileOffer(FullJid initiator, FullJid responder, Role role, String sid) {
|
public JingleFileOffer(FullJid initiator, FullJid responder, Role role, String sid) {
|
||||||
super(initiator, responder, role, sid, Type.offer);
|
super(initiator, responder, role, sid, Type.offer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.jingle.Role;
|
import org.jivesoftware.smackx.jingle.Role;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
|
@ -28,4 +30,9 @@ public class JingleFileRequest extends JingleFileTransferSession {
|
||||||
public JingleFileRequest(FullJid initiator, FullJid responder, Role role, String sid) {
|
public JingleFileRequest(FullJid initiator, FullJid responder, Role role, String sid) {
|
||||||
super(initiator, responder, role, sid, Type.request);
|
super(initiator, responder, role, sid, Type.request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IQ handleJingleSessionRequest(Jingle jingle) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.jivesoftware.smack.packet.IQ;
|
||||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||||
import org.jivesoftware.smackx.jingle.JingleHandler;
|
import org.jivesoftware.smackx.jingle.JingleHandler;
|
||||||
import org.jivesoftware.smackx.jingle.JingleManager;
|
import org.jivesoftware.smackx.jingle.JingleManager;
|
||||||
|
import org.jivesoftware.smackx.jingle.Role;
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
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_filetransfer.element.JingleFileTransfer;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -56,8 +59,23 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
public IQ handleJingleRequest(Jingle jingle) {
|
public IQ handleJingleRequest(Jingle jingle) {
|
||||||
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
||||||
String sid = jingle.getSid();
|
String sid = jingle.getSid();
|
||||||
JingleFileTransferSessionHandler handler = JingleFileTransferSessionHandler.getInstanceFor(connection());
|
|
||||||
|
JingleFileTransferSession handler = createSession(jingle);
|
||||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(fullJid, sid, handler);
|
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(fullJid, sid, handler);
|
||||||
return handler.handleJingleSessionRequest(jingle, jingle.getSid());
|
return handler.handleJingleSessionRequest(jingle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private JingleFileTransferSession createSession(Jingle request) {
|
||||||
|
if (request.getAction() != JingleAction.session_initiate) {
|
||||||
|
throw new IllegalArgumentException("Requests action MUST be session-initiate.");
|
||||||
|
}
|
||||||
|
JingleContent content = request.getContents().get(0);
|
||||||
|
if (content.getSenders() == JingleContent.Senders.initiator) {
|
||||||
|
return new JingleFileOffer(request.getInitiator(), request.getResponder(), Role.responder, request.getSid());
|
||||||
|
} else if (content.getSenders() == JingleContent.Senders.responder) {
|
||||||
|
return new JingleFileRequest(request.getInitiator(), request.getResponder(), Role.responder, request.getSid());
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Requests content.senders MUST be either responder or initiator.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,13 @@ public abstract class JingleFileTransferSession extends JingleSession {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
pending,
|
||||||
|
active,
|
||||||
|
terminated,
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
private final Type type;
|
private final Type type;
|
||||||
|
|
||||||
public JingleFileTransferSession(FullJid initiator, FullJid responder, Role role, String sid, Type type) {
|
public JingleFileTransferSession(FullJid initiator, FullJid responder, Role role, String sid, Type type) {
|
||||||
|
|
|
@ -1,56 +0,0 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
* Copyright 2017 Paul Schaub
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
|
||||||
|
|
||||||
import java.util.WeakHashMap;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
|
||||||
import org.jivesoftware.smack.packet.IQ;
|
|
||||||
import org.jivesoftware.smackx.jingle.JingleSessionHandler;
|
|
||||||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
|
||||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handler for JingleFileTransfer sessions.
|
|
||||||
*/
|
|
||||||
public final class JingleFileTransferSessionHandler implements JingleSessionHandler {
|
|
||||||
|
|
||||||
private static final WeakHashMap<XMPPConnection, JingleFileTransferSessionHandler> INSTANCES = new WeakHashMap<>();
|
|
||||||
|
|
||||||
private final XMPPConnection connection;
|
|
||||||
private final JingleUtil jutil;
|
|
||||||
|
|
||||||
private JingleFileTransferSessionHandler(XMPPConnection connection) {
|
|
||||||
this.connection = connection;
|
|
||||||
jutil = new JingleUtil(connection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static JingleFileTransferSessionHandler getInstanceFor(XMPPConnection connection) {
|
|
||||||
JingleFileTransferSessionHandler handler = INSTANCES.get(connection);
|
|
||||||
if (handler == null) {
|
|
||||||
handler = new JingleFileTransferSessionHandler(connection);
|
|
||||||
INSTANCES.put(connection, handler);
|
|
||||||
}
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IQ handleJingleSessionRequest(Jingle jingle, String sessionId) {
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -16,9 +16,12 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle;
|
package org.jivesoftware.smackx.jingle;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.packet.IQ;
|
||||||
|
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
|
||||||
public class JingleSession {
|
public abstract class JingleSession implements JingleSessionHandler {
|
||||||
|
|
||||||
protected final FullJid local;
|
protected final FullJid local;
|
||||||
|
|
||||||
|
@ -83,4 +86,103 @@ public class JingleSession {
|
||||||
&& getResponder().equals(otherJingleSession.getResponder())
|
&& getResponder().equals(otherJingleSession.getResponder())
|
||||||
&& sid.equals(otherJingleSession.sid);
|
&& sid.equals(otherJingleSession.sid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IQ handleJingleSessionRequest(Jingle jingle) {
|
||||||
|
switch (jingle.getAction()) {
|
||||||
|
case content_accept:
|
||||||
|
return handleContentAccept(jingle);
|
||||||
|
case content_add:
|
||||||
|
return handleContentAdd(jingle);
|
||||||
|
case content_modify:
|
||||||
|
return handleContentModify(jingle);
|
||||||
|
case content_reject:
|
||||||
|
return handleContentReject(jingle);
|
||||||
|
case content_remove:
|
||||||
|
return handleContentRemove(jingle);
|
||||||
|
case description_info:
|
||||||
|
return handleDescriptionInfo(jingle);
|
||||||
|
case session_info:
|
||||||
|
return handleSessionInfo(jingle);
|
||||||
|
case security_info:
|
||||||
|
return handleSecurityInfo(jingle);
|
||||||
|
case session_accept:
|
||||||
|
return handleSessionAccept(jingle);
|
||||||
|
case transport_accept:
|
||||||
|
return handleTransportAccept(jingle);
|
||||||
|
case transport_info:
|
||||||
|
return handleTransportInfo(jingle);
|
||||||
|
case session_initiate:
|
||||||
|
return handleSessionInitiate(jingle);
|
||||||
|
case transport_reject:
|
||||||
|
return handleTransportReject(jingle);
|
||||||
|
case session_terminate:
|
||||||
|
return handleSessionTerminate(jingle);
|
||||||
|
case transport_replace:
|
||||||
|
return handleTransportReplace(jingle);
|
||||||
|
default:
|
||||||
|
return IQ.createResultIQ(jingle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleSessionInitiate(Jingle sessionInitiate) {
|
||||||
|
return IQ.createResultIQ(sessionInitiate);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleSessionTerminate(Jingle sessionTerminate) {
|
||||||
|
return IQ.createResultIQ(sessionTerminate);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleSessionInfo(Jingle sessionInfo) {
|
||||||
|
return IQ.createResultIQ(sessionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleSessionAccept(Jingle sessionAccept) {
|
||||||
|
return IQ.createResultIQ(sessionAccept);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleContentAdd(Jingle contentAdd) {
|
||||||
|
return IQ.createResultIQ(contentAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleContentAccept(Jingle contentAccept) {
|
||||||
|
return IQ.createResultIQ(contentAccept);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleContentModify(Jingle contentModify) {
|
||||||
|
return IQ.createResultIQ(contentModify);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleContentReject(Jingle contentReject) {
|
||||||
|
return IQ.createResultIQ(contentReject);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleContentRemove(Jingle contentRemove) {
|
||||||
|
return IQ.createResultIQ(contentRemove);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleDescriptionInfo(Jingle descriptionInfo) {
|
||||||
|
return IQ.createResultIQ(descriptionInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleSecurityInfo(Jingle securityInfo) {
|
||||||
|
return IQ.createResultIQ(securityInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleTransportAccept(Jingle transportAccept) {
|
||||||
|
return IQ.createResultIQ(transportAccept);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleTransportInfo(Jingle transportInfo) {
|
||||||
|
return IQ.createResultIQ(transportInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleTransportReplace(Jingle transportReplace) {
|
||||||
|
return IQ.createResultIQ(transportReplace);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IQ handleTransportReject(Jingle transportReject) {
|
||||||
|
return IQ.createResultIQ(transportReject);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,6 @@ import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||||
|
|
||||||
public interface JingleSessionHandler {
|
public interface JingleSessionHandler {
|
||||||
|
|
||||||
IQ handleJingleSessionRequest(Jingle jingle, String sessionId);
|
IQ handleJingleSessionRequest(Jingle jingle);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,29 @@ public class JingleUtil {
|
||||||
return jingle;
|
return jingle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Jingle createSessionInitiateFileOffer(FullJid recipient,
|
||||||
|
String sessionId,
|
||||||
|
JingleContent.Creator contentCreator,
|
||||||
|
String contentName,
|
||||||
|
JingleContentDescription description,
|
||||||
|
JingleContentTransport transport) {
|
||||||
|
return createSessionInitiate(recipient, sessionId, contentCreator, contentName,
|
||||||
|
JingleContent.Senders.initiator, description, transport);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IQ sendSessionInitiateFileOffer(FullJid recipient,
|
||||||
|
String sessionId,
|
||||||
|
JingleContent.Creator contentCreator,
|
||||||
|
String contentName,
|
||||||
|
JingleContentDescription description,
|
||||||
|
JingleContentTransport transport)
|
||||||
|
throws SmackException.NotConnectedException, InterruptedException,
|
||||||
|
XMPPException.XMPPErrorException, SmackException.NoResponseException {
|
||||||
|
|
||||||
|
Jingle jingle = createSessionInitiateFileOffer(recipient, sessionId, contentCreator, contentName, description, transport);
|
||||||
|
return connection.createStanzaCollectorAndSend(jingle).nextResultOrThrow();
|
||||||
|
}
|
||||||
|
|
||||||
public IQ sendSessionInitiate(FullJid recipient,
|
public IQ sendSessionInitiate(FullJid recipient,
|
||||||
String sessionId,
|
String sessionId,
|
||||||
JingleContent.Creator contentCreator,
|
JingleContent.Creator contentCreator,
|
||||||
|
|
Loading…
Reference in a new issue