50 lines
1.8 KiB
Java
50 lines
1.8 KiB
Java
package de.vanitasvitae.sync_client;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
|
|
import org.jivesoftware.smack.SmackException;
|
|
import org.jivesoftware.smack.XMPPConnection;
|
|
import org.jivesoftware.smack.XMPPException;
|
|
import org.jivesoftware.smack.roster.Roster;
|
|
import org.jivesoftware.smack.roster.SubscribeListener;
|
|
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
|
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransport;
|
|
import org.jivesoftware.smackx.jingle.transport.jingle_ibb.JingleIBBTransportManager;
|
|
import org.jivesoftware.smackx.jingle.transport.jingle_s5b.JingleS5BTransportManager;
|
|
|
|
import org.jxmpp.jid.FullJid;
|
|
import org.jxmpp.stringprep.XmppStringprepException;
|
|
|
|
public class Client {
|
|
|
|
protected final XMPPConnection connection;
|
|
protected final Path root;
|
|
protected final Set<FullJid> remotes = new HashSet<>();
|
|
|
|
public Client(String username, String password, String directory) throws XmppStringprepException {
|
|
File dir = new File(directory);
|
|
if (!dir.exists()) {
|
|
throw new IllegalArgumentException("Directory " + directory + " does not exist!");
|
|
}
|
|
|
|
root = Paths.get(directory);
|
|
connection = new XMPPTCPConnection(username, password);
|
|
Roster.getInstanceFor(connection).addSubscribeListener((from, subscribeRequest) -> SubscribeListener.SubscribeAnswer.Approve);
|
|
JingleS5BTransportManager.getInstanceFor(connection);
|
|
JingleIBBTransportManager.getInstanceFor(connection);
|
|
}
|
|
|
|
public void login() throws InterruptedException, IOException, SmackException, XMPPException {
|
|
((XMPPTCPConnection) connection).connect().login();
|
|
}
|
|
|
|
public void addRemote(FullJid remote) {
|
|
remotes.add(remote);
|
|
}
|
|
}
|