2017-07-19 15:17:12 +02:00
|
|
|
package org.jivesoftware.smackx.jingle3.internal;
|
|
|
|
|
2017-07-21 17:58:57 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2017-07-19 23:15:17 +02:00
|
|
|
import org.jivesoftware.smack.XMPPConnection;
|
2017-07-19 15:17:12 +02:00
|
|
|
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportElement;
|
|
|
|
import org.jivesoftware.smackx.jingle3.element.JingleContentTransportInfoElement;
|
|
|
|
import org.jivesoftware.smackx.jingle3.transport.BytestreamSessionEstablishedListener;
|
|
|
|
|
2017-07-19 23:15:17 +02:00
|
|
|
import org.jxmpp.jid.FullJid;
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
/**
|
|
|
|
* Created by vanitas on 18.07.17.
|
|
|
|
*/
|
|
|
|
public abstract class Transport<D extends JingleContentTransportElement> {
|
|
|
|
|
2017-07-21 17:58:57 +02:00
|
|
|
private Content parent;
|
|
|
|
private final ArrayList<TransportCandidate<?>> candidates = new ArrayList<>();
|
|
|
|
|
|
|
|
private Transport peersProposal;
|
|
|
|
private boolean isPeersProposal;
|
|
|
|
|
2017-07-21 18:29:27 +02:00
|
|
|
public Transport(Content content) {
|
|
|
|
this.parent = content;
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
public abstract D getElement();
|
|
|
|
|
2017-07-21 17:58:57 +02:00
|
|
|
public void addCandidate(TransportCandidate<?> candidate) {
|
|
|
|
// Insert sorted by priority descending
|
|
|
|
|
|
|
|
// Empty list -> insert
|
|
|
|
if (candidates.isEmpty()) {
|
|
|
|
candidates.add(candidate);
|
|
|
|
candidate.setParent(this);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find appropriate index
|
|
|
|
for (int i = 0; i < candidates.size(); i++) {
|
|
|
|
TransportCandidate<?> c = candidates.get(i);
|
|
|
|
|
|
|
|
// list already contains element -> return
|
|
|
|
if (c == candidate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Found the index
|
|
|
|
if (c.getPriority() <= candidate.getPriority()) {
|
|
|
|
candidates.add(i, candidate);
|
|
|
|
candidate.setParent(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public List<TransportCandidate<?>> getCandidates() {
|
|
|
|
return candidates;
|
|
|
|
}
|
|
|
|
|
2017-07-19 15:17:12 +02:00
|
|
|
public abstract String getNamespace();
|
|
|
|
|
2017-07-19 23:15:17 +02:00
|
|
|
public abstract void establishIncomingBytestreamSession(FullJid peer,
|
|
|
|
String transportSessionId,
|
|
|
|
BytestreamSessionEstablishedListener listener,
|
|
|
|
XMPPConnection connection);
|
|
|
|
|
|
|
|
public abstract void establishOutgoingBytestreamSession(FullJid peer,
|
|
|
|
String transportSessionId,
|
|
|
|
BytestreamSessionEstablishedListener listener,
|
|
|
|
XMPPConnection connection);
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-21 17:58:57 +02:00
|
|
|
public void setPeersProposal(Transport peersProposal) {
|
|
|
|
this.peersProposal = peersProposal;
|
|
|
|
peersProposal.isPeersProposal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPeersProposal() {
|
|
|
|
return isPeersProposal;
|
|
|
|
}
|
2017-07-19 15:17:12 +02:00
|
|
|
|
2017-07-21 18:29:27 +02:00
|
|
|
public Transport<?> getPeersProposal() {
|
|
|
|
return peersProposal;
|
|
|
|
}
|
|
|
|
|
2017-07-19 23:15:17 +02:00
|
|
|
public abstract void handleTransportInfo(JingleContentTransportInfoElement info);
|
2017-07-21 17:58:57 +02:00
|
|
|
|
|
|
|
public void setParent(Content parent) {
|
|
|
|
if (this.parent != parent) {
|
|
|
|
this.parent = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Content getParent() {
|
|
|
|
return parent;
|
|
|
|
}
|
2017-07-19 15:17:12 +02:00
|
|
|
}
|