mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-24 19:47:58 +01:00
Progress
This commit is contained in:
parent
b0c8a8027a
commit
185d569b89
18 changed files with 266 additions and 65 deletions
|
@ -23,8 +23,11 @@ import java.util.List;
|
|||
import java.util.WeakHashMap;
|
||||
|
||||
import org.jivesoftware.smack.Manager;
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smackx.disco.ServiceDiscoveryManager;
|
||||
import org.jivesoftware.smackx.jft.adapter.JingleFileTransferAdapter;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
|
@ -32,6 +35,7 @@ import org.jivesoftware.smackx.jft.internal.JingleIncomingFileOffer;
|
|||
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileOffer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleOutgoingFileRequest;
|
||||
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
|
||||
import org.jivesoftware.smackx.jft.listener.IncomingFileOfferListener;
|
||||
import org.jivesoftware.smackx.jft.listener.IncomingFileRequestListener;
|
||||
import org.jivesoftware.smackx.jft.provider.JingleFileTransferProvider;
|
||||
|
@ -59,6 +63,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
private final List<IncomingFileRequestListener> requestListeners =
|
||||
Collections.synchronizedList(new ArrayList<IncomingFileRequestListener>());
|
||||
|
||||
static {
|
||||
JingleManager.addJingleDescriptionAdapter(new JingleFileTransferAdapter());
|
||||
}
|
||||
|
||||
private JingleFileTransferManager(XMPPConnection connection) {
|
||||
super(connection);
|
||||
ServiceDiscoveryManager.getInstanceFor(connection).addFeature(getNamespace());
|
||||
|
@ -78,7 +86,10 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
return manager;
|
||||
}
|
||||
|
||||
public OutgoingFileOfferController sendFile(File file, FullJid to) {
|
||||
public OutgoingFileOfferController sendFile(File file, FullJid to)
|
||||
throws SmackException.NotConnectedException, InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NoResponseException {
|
||||
|
||||
if (file == null || !file.exists()) {
|
||||
throw new IllegalArgumentException("File MUST NOT be null and MUST exist.");
|
||||
}
|
||||
|
@ -94,12 +105,13 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
JingleTransportManager transportManager = jingleManager.getBestAvailableTransportManager();
|
||||
content.setTransport(transportManager.createTransport(content));
|
||||
|
||||
//TODO
|
||||
session.initiate(connection());
|
||||
|
||||
return offer;
|
||||
}
|
||||
|
||||
public OutgoingFileRequestController requestFile() {
|
||||
JingleOutgoingFileRequest request = new JingleOutgoingFileRequest();
|
||||
public OutgoingFileRequestController requestFile(RemoteFile file) {
|
||||
JingleOutgoingFileRequest request = new JingleOutgoingFileRequest(file);
|
||||
|
||||
//TODO at some point.
|
||||
|
||||
|
@ -116,7 +128,7 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
|
|||
|
||||
public void notifyIncomingFileOfferListeners(JingleIncomingFileOffer offer) {
|
||||
for (IncomingFileOfferListener l : offerListeners) {
|
||||
l.onIncomingFileTransfer(offer);
|
||||
l.onIncomingFileOffer(offer);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
*
|
||||
* 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.jft.adapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileOffer;
|
||||
import org.jivesoftware.smackx.jft.internal.JingleIncomingFileRequest;
|
||||
import org.jivesoftware.smackx.jingle.adapter.JingleDescriptionAdapter;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionChildElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 28.07.17.
|
||||
*/
|
||||
public class JingleFileTransferAdapter implements JingleDescriptionAdapter<JingleFileTransfer> {
|
||||
|
||||
@Override
|
||||
public JingleFileTransfer descriptionFromElement(JingleContentElement.Creator creator, JingleContentElement.Senders senders,
|
||||
String contentName, String contentDisposition, JingleContentDescriptionElement element) {
|
||||
JingleFileTransferElement description = (JingleFileTransferElement) element;
|
||||
List<JingleContentDescriptionChildElement> childs = description.getJingleContentDescriptionChildren();
|
||||
assert childs.size() == 1;
|
||||
JingleFileTransferChildElement file = (JingleFileTransferChildElement) childs.get(0);
|
||||
|
||||
if (senders == JingleContentElement.Senders.initiator) {
|
||||
return new JingleIncomingFileOffer(file);
|
||||
} else if (senders == JingleContentElement.Senders.responder) {
|
||||
return new JingleIncomingFileRequest(file);
|
||||
} else {
|
||||
throw new AssertionError("Senders attribute MUST be either initiator or responder. Is: " + senders);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
}
|
|
@ -16,9 +16,12 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
*/
|
||||
public interface IncomingFileOfferController extends JingleFileTransferController {
|
||||
|
||||
Future<Void> accept(File target);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
|
||||
|
||||
/**
|
||||
|
@ -24,15 +23,7 @@ import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
|
|||
*/
|
||||
public abstract class AbstractJingleFileOffer<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer {
|
||||
|
||||
protected D jingleFile;
|
||||
|
||||
public AbstractJingleFileOffer(D fileTransferFile) {
|
||||
super();
|
||||
this.jingleFile = fileTransferFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
return new JingleFileTransferElement(jingleFile.getElement());
|
||||
super(fileTransferFile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,15 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 22.07.17.
|
||||
*/
|
||||
public abstract class AbstractJingleFileRequest extends JingleFileTransfer {
|
||||
public abstract class AbstractJingleFileRequest<D extends AbstractJingleFileTransferFile> extends JingleFileTransfer {
|
||||
|
||||
public AbstractJingleFileRequest(D fileTransferFile) {
|
||||
super(fileTransferFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
|
||||
import org.jivesoftware.smackx.jft.controller.JingleFileTransferController;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.file.AbstractJingleFileTransferFile;
|
||||
import org.jivesoftware.smackx.jft.listener.ProgressListener;
|
||||
import org.jivesoftware.smackx.jingle.components.JingleDescription;
|
||||
|
||||
|
@ -37,9 +38,14 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
|
|||
public abstract boolean isRequest();
|
||||
|
||||
protected State state;
|
||||
protected AbstractJingleFileTransferFile file;
|
||||
|
||||
protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
|
||||
|
||||
public JingleFileTransfer(AbstractJingleFileTransferFile file) {
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProgressListener(ProgressListener listener) {
|
||||
progressListeners.add(listener);
|
||||
|
@ -57,6 +63,16 @@ public abstract class JingleFileTransfer extends JingleDescription<JingleFileTra
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getNamespace() {
|
||||
return JingleFileTransfer.NAMESPACE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
return new JingleFileTransferElement(file.getElement());
|
||||
}
|
||||
|
||||
@Override
|
||||
public State getState() {
|
||||
return state;
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft.internal;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
@ -25,6 +27,9 @@ import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
|||
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
|
||||
import org.jivesoftware.smackx.jingle.components.JingleSession;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
|
@ -37,6 +42,11 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
|
|||
super(new RemoteFile(offer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
InputStream inputStream;
|
||||
|
@ -57,4 +67,14 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
|
|||
public boolean isRequest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Future<Void> accept(File target) {
|
||||
JingleSession session = getParent().getParent();
|
||||
if (session.getSessionState() == JingleSession.SessionState.pending) {
|
||||
//session.accept();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,17 +18,32 @@ package org.jivesoftware.smackx.jft.internal;
|
|||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.controller.IncomingFileRequestController;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferChildElement;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
* TODO: RemoteFile????
|
||||
*/
|
||||
public class JingleIncomingFileRequest extends AbstractJingleFileRequest implements IncomingFileRequestController {
|
||||
public class JingleIncomingFileRequest extends AbstractJingleFileRequest<RemoteFile> implements IncomingFileRequestController {
|
||||
|
||||
public JingleIncomingFileRequest(JingleFileTransferChildElement request) {
|
||||
super(new RemoteFile(request));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOffer() {
|
||||
return false;
|
||||
|
|
|
@ -21,6 +21,8 @@ import java.io.File;
|
|||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.internal.file.LocalFile;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 26.07.17.
|
||||
|
@ -31,6 +33,11 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer<LocalFile>
|
|||
super(new LocalFile(file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTransportReady(BytestreamSession bytestreamSession) {
|
||||
|
||||
|
|
|
@ -18,14 +18,21 @@ package org.jivesoftware.smackx.jft.internal;
|
|||
|
||||
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileRequestController;
|
||||
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
|
||||
import org.jivesoftware.smackx.jft.internal.file.RemoteFile;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContentDescriptionInfoElement;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleElement;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 27.07.17.
|
||||
*/
|
||||
public class JingleOutgoingFileRequest extends AbstractJingleFileRequest implements OutgoingFileRequestController {
|
||||
public class JingleOutgoingFileRequest extends AbstractJingleFileRequest<RemoteFile> implements OutgoingFileRequestController {
|
||||
|
||||
public JingleOutgoingFileRequest(RemoteFile file) {
|
||||
super(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JingleFileTransferElement getElement() {
|
||||
public JingleElement handleDescriptionInfo(JingleContentDescriptionInfoElement info) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,5 +23,5 @@ import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
|
|||
*/
|
||||
public interface IncomingFileOfferListener {
|
||||
|
||||
void onIncomingFileTransfer(IncomingFileOfferController offer);
|
||||
void onIncomingFileOffer(IncomingFileOfferController offer);
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -16,20 +16,35 @@
|
|||
*/
|
||||
package org.jivesoftware.smackx.jft;
|
||||
|
||||
import static junit.framework.TestCase.fail;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.jivesoftware.smackx.bytestreams.socks5.Socks5Proxy;
|
||||
import org.jivesoftware.smackx.jft.controller.IncomingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.controller.OutgoingFileOfferController;
|
||||
import org.jivesoftware.smackx.jft.listener.IncomingFileOfferListener;
|
||||
import org.jivesoftware.smackx.jft.listener.ProgressListener;
|
||||
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransportManager;
|
||||
|
||||
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
|
||||
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
||||
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
||||
import org.junit.AfterClass;
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 29.06.17.
|
||||
*/
|
||||
public class FileTransferTest extends AbstractSmackIntegrationTest {
|
||||
public class JingleFileTransferTest extends AbstractSmackIntegrationTest {
|
||||
|
||||
private static final File tempDir;
|
||||
|
||||
|
@ -43,13 +58,16 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
public FileTransferTest(SmackIntegrationTestEnvironment environment) {
|
||||
public JingleFileTransferTest(SmackIntegrationTestEnvironment environment) {
|
||||
super(environment);
|
||||
}
|
||||
|
||||
/*
|
||||
@SmackIntegrationTest
|
||||
public void basicFileTransferTest() {
|
||||
public void basicFileTransferTest() throws Exception {
|
||||
JingleIBBTransportManager.getInstanceFor(conOne);
|
||||
JingleIBBTransportManager.getInstanceFor(conTwo);
|
||||
|
||||
|
||||
final SimpleResultSyncPoint resultSyncPoint1 = new SimpleResultSyncPoint();
|
||||
final SimpleResultSyncPoint resultSyncPoint2 = new SimpleResultSyncPoint();
|
||||
|
||||
|
@ -59,45 +77,55 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
|||
File source = prepareNewTestFile("source");
|
||||
final File target = new File(tempDir, "target");
|
||||
|
||||
JingleFileTransferManagerAlt aftm = JingleFileTransferManagerAlt.getInstanceFor(conOne);
|
||||
JingleFileTransferManagerAlt bftm = JingleFileTransferManagerAlt.getInstanceFor(conTwo);
|
||||
JingleFileTransferManager aftm = JingleFileTransferManager.getInstanceFor(conOne);
|
||||
JingleFileTransferManager bftm = JingleFileTransferManager.getInstanceFor(conTwo);
|
||||
|
||||
bftm.addJingleFileTransferOfferListener(new JingleFileTransferOfferListener() {
|
||||
final ArrayList<Future<Void>> receiveFuture = new ArrayList<>(); //Uglaay
|
||||
|
||||
bftm.addIncomingFileOfferListener(new IncomingFileOfferListener() {
|
||||
@Override
|
||||
public void onFileOffer(JingleElement request, IncomingFileOfferCallback callback) {
|
||||
FileTransferHandler handler2 = callback.acceptIncomingFileOffer(request, target);
|
||||
handler2.addEndedListener(new FileTransferHandler.EndedListener() {
|
||||
public void onIncomingFileOffer(IncomingFileOfferController offer) {
|
||||
LOGGER.log(Level.INFO, "INCOMING FILE TRANSFER!");
|
||||
offer.addProgressListener(new ProgressListener() {
|
||||
@Override
|
||||
public void onEnded(JingleReasonElement.Reason reason) {
|
||||
public void started() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void progress(float percent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finished() {
|
||||
resultSyncPoint2.signal();
|
||||
}
|
||||
});
|
||||
receiveFuture.add(offer.accept(target));
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
FileTransferHandler handler = aftm.sendFile(bob, source);
|
||||
handler.addEndedListener(new FileTransferHandler.EndedListener() {
|
||||
@Override
|
||||
public void onEnded(JingleReasonElement.Reason reason) {
|
||||
resultSyncPoint1.signal();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException e) {
|
||||
fail();
|
||||
}
|
||||
OutgoingFileOfferController sending = aftm.sendFile(source, bob);
|
||||
sending.addProgressListener(new ProgressListener() {
|
||||
@Override
|
||||
public void started() {
|
||||
|
||||
try {
|
||||
resultSyncPoint1.waitForResult(10 * 1000);
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
resultSyncPoint2.waitForResult(10 * 1000);
|
||||
} catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
@Override
|
||||
public void progress(float percent) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finished() {
|
||||
resultSyncPoint1.signal();
|
||||
}
|
||||
});
|
||||
|
||||
resultSyncPoint1.waitForResult(60 * 1000);
|
||||
resultSyncPoint2.waitForResult(60 * 1000);
|
||||
|
||||
byte[] sBytes = new byte[(int) source.length()];
|
||||
byte[] tBytes = new byte[(int) target.length()];
|
||||
|
@ -116,7 +144,6 @@ public class FileTransferTest extends AbstractSmackIntegrationTest {
|
|||
LOGGER.log(Level.INFO, "SUCCESSFULLY SENT AND RECEIVED");
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
private File prepareNewTestFile(String name) {
|
||||
File testFile = new File(tempDir, name);
|
Loading…
Reference in a new issue