1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-10-31 17:25:58 +01:00

Notifiers and ProgressListeners

This commit is contained in:
vanitasvitae 2017-07-27 16:43:09 +02:00
parent 5ce12974c8
commit 3f6df8e6c7
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
14 changed files with 122 additions and 16 deletions

View file

@ -123,15 +123,22 @@ public final class JingleFileTransferManager extends Manager implements JingleDe
return AbstractJingleFileTransfer.NAMESPACE;
}
@Override
public void notifySessionInitiate(JingleSession session) {
JingleContent content = session.getSoleContentOrThrow();
AbstractJingleFileTransfer transfer = (AbstractJingleFileTransfer) content.getDescription();
private void notifyTransfer(AbstractJingleFileTransfer transfer) {
if (transfer.isOffer()) {
notifyIncomingFileOfferListeners((JingleIncomingFileOffer) transfer);
} else {
notifyIncomingFileRequestListeners((JingleIncomingFileRequest) transfer);
}
}
@Override
public void notifySessionInitiate(JingleSession session) {
JingleContent content = session.getSoleContentOrThrow();
notifyTransfer((AbstractJingleFileTransfer) content.getDescription());
}
@Override
public void notifyContentAdd(JingleContent content) {
notifyTransfer((AbstractJingleFileTransfer) content.getDescription());
}
}

View file

@ -1,10 +1,8 @@
package org.jivesoftware.smackx.jft.controller;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface IncomingFileOfferController extends JingleDescriptionController {
public interface IncomingFileOfferController extends JingleFileTransferController {
}

View file

@ -1,10 +1,8 @@
package org.jivesoftware.smackx.jft.controller;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface IncomingFileRequestController extends JingleDescriptionController {
public interface IncomingFileRequestController extends JingleFileTransferController {
}

View file

@ -0,0 +1,14 @@
package org.jivesoftware.smackx.jft.controller;
import org.jivesoftware.smackx.jft.listener.ProgressListener;
import org.jivesoftware.smackx.jingle.JingleDescriptionController;
/**
* Created by vanitas on 27.07.17.
*/
public interface JingleFileTransferController extends JingleDescriptionController {
void addProgressListener(ProgressListener listener);
void removeProgressListener(ProgressListener listener);
}

View file

@ -3,5 +3,5 @@ package org.jivesoftware.smackx.jft.controller;
/**
* Created by vanitas on 27.07.17.
*/
public interface OutgoingFileOfferController {
public interface OutgoingFileOfferController extends JingleFileTransferController {
}

View file

@ -3,5 +3,5 @@ package org.jivesoftware.smackx.jft.controller;
/**
* Created by vanitas on 27.07.17.
*/
public interface OutgoingFileRequestController {
public interface OutgoingFileRequestController extends JingleFileTransferController {
}

View file

@ -1,12 +1,18 @@
package org.jivesoftware.smackx.jft.internal;
import org.jivesoftware.smackx.jingle.components.JingleDescription;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.jivesoftware.smackx.jft.controller.JingleFileTransferController;
import org.jivesoftware.smackx.jft.element.JingleFileTransferElement;
import org.jivesoftware.smackx.jft.listener.ProgressListener;
import org.jivesoftware.smackx.jingle.components.JingleDescription;
/**
* Created by vanitas on 22.07.17.
*/
public abstract class AbstractJingleFileTransfer extends JingleDescription<JingleFileTransferElement> {
public abstract class AbstractJingleFileTransfer extends JingleDescription<JingleFileTransferElement> implements JingleFileTransferController {
public static final String NAMESPACE_V5 = "urn:xmpp:jingle:apps:file-transfer:5";
public static final String NAMESPACE = NAMESPACE_V5;
@ -14,4 +20,29 @@ public abstract class AbstractJingleFileTransfer extends JingleDescription<Jingl
public abstract boolean isOffer();
public abstract boolean isRequest();
protected State state;
protected final List<ProgressListener> progressListeners = Collections.synchronizedList(new ArrayList<ProgressListener>());
@Override
public void addProgressListener(ProgressListener listener) {
progressListeners.add(listener);
//TODO: Notify new listener?
}
@Override
public void removeProgressListener(ProgressListener listener) {
progressListeners.remove(listener);
}
public void notifyProgressListeners(float progress) {
for (ProgressListener p : progressListeners) {
p.progress(progress);
}
}
@Override
public State getState() {
return state;
}
}

View file

@ -31,4 +31,14 @@ public class JingleIncomingFileOffer extends AbstractJingleFileOffer<RemoteFile>
return;
}
}
@Override
public boolean isOffer() {
return true;
}
@Override
public boolean isRequest() {
return false;
}
}

View file

@ -13,6 +13,16 @@ public class JingleIncomingFileRequest extends AbstractJingleFileRequest impleme
return null;
}
@Override
public boolean isOffer() {
return false;
}
@Override
public boolean isRequest() {
return true;
}
@Override
public void onTransportReady(BytestreamSession bytestreamSession) {

View file

@ -19,4 +19,14 @@ public class JingleOutgoingFileOffer extends AbstractJingleFileOffer<LocalFile>
public void onTransportReady(BytestreamSession bytestreamSession) {
}
@Override
public boolean isOffer() {
return true;
}
@Override
public boolean isRequest() {
return false;
}
}

View file

@ -13,6 +13,16 @@ public class JingleOutgoingFileRequest extends AbstractJingleFileRequest impleme
return null;
}
@Override
public boolean isOffer() {
return false;
}
@Override
public boolean isRequest() {
return true;
}
@Override
public void onTransportReady(BytestreamSession bytestreamSession) {

View file

@ -0,0 +1,13 @@
package org.jivesoftware.smackx.jft.listener;
/**
* Created by vanitas on 27.07.17.
*/
public interface ProgressListener {
void started();
void progress(float percent);
void finished();
}

View file

@ -16,6 +16,7 @@
*/
package org.jivesoftware.smackx.jingle;
import org.jivesoftware.smackx.jingle.components.JingleContent;
import org.jivesoftware.smackx.jingle.components.JingleSession;
/**
@ -26,4 +27,6 @@ public interface JingleDescriptionManager {
String getNamespace();
void notifySessionInitiate(JingleSession session);
void notifyContentAdd(JingleContent content);
}

View file

@ -359,6 +359,8 @@ public class JingleSession {
}
for (final JingleContent content : descriptionCategory.getValue()) {
descriptionManager.notifyContentAdd(content);
ContentAddCallback callback = new ContentAddCallback() {
@Override
public void acceptContentAdd() {
@ -372,7 +374,7 @@ public class JingleSession {
// TODO: Send content-reject
}
};
descriptionManager.notifySessionInitiate();
descriptionManager
}
}