mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-27 14:32:06 +01:00
Add send method
This commit is contained in:
parent
4649defe4f
commit
4f03cf9a24
3 changed files with 30 additions and 3 deletions
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package org.jivesoftware.smackx.jingle_filetransfer;
|
package org.jivesoftware.smackx.jingle_filetransfer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.jivesoftware.smack.Manager;
|
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.Jingle;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
import org.jivesoftware.smackx.jingle.element.JingleAction;
|
||||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
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.callback.IncomingFileOfferCallback;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
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.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||||
|
|
||||||
import org.jxmpp.jid.FullJid;
|
import org.jxmpp.jid.FullJid;
|
||||||
|
@ -61,6 +65,11 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
return manager;
|
return manager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void sendFile(FullJid recipient, File file) {
|
||||||
|
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||||
|
offer.send(file);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IQ handleJingleRequest(Jingle jingle) {
|
public IQ handleJingleRequest(Jingle jingle) {
|
||||||
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
FullJid fullJid = jingle.getFrom().asFullJidOrThrow();
|
||||||
|
@ -114,7 +123,16 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
||||||
jingleFileTransferOfferListeners.add(listener);
|
jingleFileTransferOfferListeners.add(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(JingleFileTransferOfferListener listener) {
|
public void removeJingleFileTransferOfferListener(JingleFileTransferOfferListener listener) {
|
||||||
jingleFileTransferOfferListeners.remove(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()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,15 @@ public class OutgoingJingleFileOffer extends JingleFileTransferSession {
|
||||||
|
|
||||||
private static final Logger LOGGER = Logger.getLogger(OutgoingJingleFileOffer.class.getName());
|
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 {
|
public enum State {
|
||||||
fresh,
|
fresh,
|
||||||
pending,
|
pending,
|
||||||
|
|
|
@ -28,7 +28,7 @@ import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransferChild;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by vanitas on 21.06.17.
|
* Thread for receiving data.
|
||||||
*/
|
*/
|
||||||
public class ReceivingThread extends Thread {
|
public class ReceivingThread extends Thread {
|
||||||
private static final Logger LOGGER = Logger.getLogger(ReceivingThread.class.getName());
|
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);
|
System.arraycopy(bufbuf, 0, filebuf, read, r);
|
||||||
read += r;
|
read += r;
|
||||||
} else {
|
} else {
|
||||||
//TODO
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue