mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-12-25 20:18:00 +01:00
Temp
This commit is contained in:
parent
a3bb7e3f59
commit
87949f94b9
7 changed files with 164 additions and 3 deletions
|
@ -30,6 +30,7 @@ import org.jivesoftware.smackx.jingle.JingleTransportMethodManager;
|
|||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle.element.Jingle;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleContent;
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportInitiationCallback;
|
||||
import org.jivesoftware.smackx.jingle.transports.JingleTransportManager;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.callback.IncomingFileOfferCallback;
|
||||
|
@ -46,6 +47,41 @@ public class IncomingJingleFileOffer extends JingleFileTransferSession implement
|
|||
private ReceiveTask receivingThread;
|
||||
private File target;
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStarted() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEndedListener(EndedListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStartedListener(StartedListener listener) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyEndedListeners(JingleReason.Reason reason) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyStartedListeners() {
|
||||
|
||||
}
|
||||
|
||||
public enum State {
|
||||
fresh,
|
||||
pending,
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.jivesoftware.smackx.jingle.provider.JingleContentProviderManager;
|
|||
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.handler.FileTransferHandler;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.listener.JingleFileTransferOfferListener;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.provider.JingleFileTransferProvider;
|
||||
|
||||
|
@ -75,12 +76,13 @@ public final class JingleFileTransferManager extends Manager implements JingleHa
|
|||
return manager;
|
||||
}
|
||||
|
||||
public void sendFile(FullJid recipient, File file)
|
||||
public FileTransferHandler sendFile(FullJid recipient, File file)
|
||||
throws InterruptedException, XMPPException.XMPPErrorException,
|
||||
SmackException.NotConnectedException, SmackException.NoResponseException {
|
||||
OutgoingJingleFileOffer offer = new OutgoingJingleFileOffer(connection(), recipient);
|
||||
JingleManager.getInstanceFor(connection()).registerJingleSessionHandler(recipient, offer.getSessionId(), offer);
|
||||
offer.send(file);
|
||||
return offer;
|
||||
}
|
||||
|
||||
public SmackFuture<?> asyncSendFile(FullJid recipient, File file) {
|
||||
|
|
|
@ -21,13 +21,14 @@ import org.jivesoftware.smackx.jingle.JingleSession;
|
|||
import org.jivesoftware.smackx.jingle.JingleUtil;
|
||||
import org.jivesoftware.smackx.jingle.Role;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.element.JingleFileTransfer;
|
||||
import org.jivesoftware.smackx.jingle_filetransfer.handler.FileTransferHandler;
|
||||
|
||||
import org.jxmpp.jid.FullJid;
|
||||
|
||||
/**
|
||||
* Class representing a Jingle session in the context of Jingle File Transfer (XEP-0234).
|
||||
*/
|
||||
public abstract class JingleFileTransferSession extends JingleSession {
|
||||
public abstract class JingleFileTransferSession extends JingleSession implements FileTransferHandler {
|
||||
|
||||
public enum Type {
|
||||
offer,
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
*
|
||||
* 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.handler;
|
||||
|
||||
import org.jivesoftware.smackx.jingle.element.JingleReason;
|
||||
|
||||
/**
|
||||
* Handler that provides some control over the JingleFileOffer session.
|
||||
*/
|
||||
public interface FileTransferHandler {
|
||||
|
||||
/**
|
||||
* Cancels the current file transfer.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Returns true, if the file transfer is finished.
|
||||
* @return true if transfer finished.
|
||||
*/
|
||||
boolean isFinished();
|
||||
|
||||
/**
|
||||
* Returns true, if the file transfer is started.
|
||||
* @return true if started.
|
||||
*/
|
||||
boolean isStarted();
|
||||
|
||||
/**
|
||||
* Add a new FinishedListener.
|
||||
* @param listener listener
|
||||
*/
|
||||
void addEndedListener(EndedListener listener);
|
||||
|
||||
/**
|
||||
* Add a new AcceptedListener.
|
||||
* @param listener listener
|
||||
*/
|
||||
void addStartedListener(StartedListener listener);
|
||||
|
||||
/**
|
||||
* Notify all registered FinishedListeners that the file transfer has finished.
|
||||
*/
|
||||
void notifyEndedListeners(JingleReason.Reason reason);
|
||||
|
||||
/**
|
||||
* Notify all registered AcceptedListeners that the file transfer session has been accepted by the remote user.
|
||||
*/
|
||||
void notifyStartedListeners();
|
||||
|
||||
/**
|
||||
* A FinishedListener will be notified by the SendFileHandler when the corresponding file transfer is finished.
|
||||
*/
|
||||
interface EndedListener {
|
||||
void onEnded(JingleReason.Reason reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* An AcceptedListener will be notified by the SendFileHandler when the corresponding pending session has been
|
||||
* accepted by the remote user.
|
||||
*/
|
||||
interface StartedListener {
|
||||
void onStarted();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/**
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Smack's API for <a href="https://xmpp.org/extensions/xep-0234.html">XEP-0234: Jingle File Transfer</a>.
|
||||
* Handlers.
|
||||
*/
|
||||
package org.jivesoftware.smackx.jingle_filetransfer.handler;
|
|
@ -20,6 +20,7 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
|
@ -171,7 +172,8 @@ public abstract class JingleSession implements JingleSessionHandler {
|
|||
return IQ.createResultIQ(jingle);
|
||||
}
|
||||
} catch (InterruptedException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | SmackException.NoResponseException e) {
|
||||
return null; //TODO:
|
||||
LOGGER.log(Level.SEVERE, "Caught an Exception: ", e);
|
||||
return null; //TODO: Handle better?
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.jivesoftware.smackx.jingle;
|
||||
|
||||
/**
|
||||
* Created by vanitas on 06.07.17.
|
||||
*/
|
||||
public class JingleStreamRouter {
|
||||
private static JingleStreamRouter INSTANCE;
|
||||
|
||||
private JingleStreamRouter() {
|
||||
|
||||
}
|
||||
|
||||
public static JingleStreamRouter getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new JingleStreamRouter();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue