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

Add send method

This commit is contained in:
vanitasvitae 2017-06-21 17:34:34 +02:00
parent 4649defe4f
commit 4f03cf9a24
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 30 additions and 3 deletions

View file

@ -16,7 +16,9 @@
*/
package org.jivesoftware.smackx.jingle_filetransfer;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.WeakHashMap;
import org.jivesoftware.smack.Manager;
@ -29,8 +31,10 @@ import org.jivesoftware.smackx.jingle.JingleUtil;
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.element.JingleContentDescriptionChildElement;
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
import org.jxmpp.jid.FullJid;
@ -61,6 +65,11 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
return manager;
}
public void sendFile(FullJid recipient, File file) {
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
offer.send(file);
}
@Override
public IQ handleJingleRequest(Jingle jingle) {
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
@ -114,7 +123,16 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
jingleFileTransferOfferListeners.add(listener);
}
public void remove(JingleFileTransferOfferListener listener) {
public void removeJingleFileTransferOfferListener(JingleFileTransferOfferListener listener) {
jingleFileTransferOfferListeners.remove(listener);
}
public static JingleFileTransfer fileTransferFromFile(File file) {
JingleFileTransferChild.Builder fb = JingleFileTransferChild.getBuilder();
fb.setFile(file)
.setDescription("A file.")
.setMediaType("application/octet-stream");
return new JingleFileTransfer(Collections.<JingleContentDescriptionChildElement>singletonList(fb.build()));
}
}

View file

@ -43,6 +43,15 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
public void send(File file) throws InterruptedException, XMPPException.XMPPErrorException,
SmackException.NotConnectedException, SmackException.NoResponseException {
source = file;
String contentName = JingleManager.randomSid();
JingleFileTransfer transfer = JingleFileTransferManager.fileTransferFromFile(file);
initiateFileOffer(transfer, JingleContent.Creator.initiator, contentName);
}
public enum State {
fresh,
pending,

View file

@ -28,7 +28,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
/**
* Created by vanitas on 21.06.17.
* Thread for receiving data.
*/
public class ReceivingThread extends Thread {
private static final Logger LOGGER = Logger.getLogger(ReceivingThread.class.getName());
@ -63,7 +63,7 @@ public class ReceivingThread extends Thread {
System.arraycopy(bufbuf, 0, filebuf, read, r);
read += r;
} else {
//TODO
break;
}
}