1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-25 04:44:49 +02:00
Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/internal/JingleTransport.java

106 lines
3.5 KiB
Java
Raw Normal View History

2017-07-21 23:05:46 +02:00
/**
*
* 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.internal;
2017-07-19 15:17:12 +02:00
2017-07-21 17:58:57 +02:00
import java.util.ArrayList;
import java.util.List;
2017-07-21 23:05:46 +02:00
import org.jivesoftware.smack.SmackException;
2017-07-19 23:15:17 +02:00
import org.jivesoftware.smack.XMPPConnection;
2017-07-21 23:05:46 +02:00
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
2017-07-22 00:26:50 +02:00
import org.jivesoftware.smackx.jingle.element.JingleElement;
2017-07-21 23:05:46 +02:00
import org.jivesoftware.smackx.jingle.transport.BytestreamSessionEstablishedListener;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
2017-07-19 23:15:17 +02:00
2017-07-19 15:17:12 +02:00
/**
2017-07-21 23:05:46 +02:00
* Class that represents a contents transport component.
2017-07-19 15:17:12 +02:00
*/
public abstract class JingleTransport<D extends JingleContentTransportElement> {
2017-07-19 15:17:12 +02:00
private JingleContent parent;
private final ArrayList<JingleTransportCandidate<?>> candidates = new ArrayList<>();
2017-07-21 17:58:57 +02:00
private JingleTransport peersProposal;
2017-07-21 17:58:57 +02:00
private boolean isPeersProposal;
2017-07-19 15:17:12 +02:00
public abstract D getElement();
public void addCandidate(JingleTransportCandidate<?> candidate) {
2017-07-21 17:58:57 +02:00
// 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++) {
JingleTransportCandidate<?> c = candidates.get(i);
2017-07-21 17:58:57 +02:00
// 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<JingleTransportCandidate<?>> getCandidates() {
2017-07-21 17:58:57 +02:00
return candidates;
}
2017-07-19 15:17:12 +02:00
public abstract String getNamespace();
2017-07-21 23:05:46 +02:00
public abstract void establishIncomingBytestreamSession(BytestreamSessionEstablishedListener listener,
XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException;
2017-07-19 23:15:17 +02:00
2017-07-21 23:05:46 +02:00
public abstract void establishOutgoingBytestreamSession(BytestreamSessionEstablishedListener listener,
XMPPConnection connection) throws SmackException.NotConnectedException, InterruptedException;
2017-07-19 15:17:12 +02:00
public void setPeersProposal(JingleTransport peersProposal) {
2017-07-21 17:58:57 +02:00
this.peersProposal = peersProposal;
peersProposal.isPeersProposal = true;
}
public boolean isPeersProposal() {
return isPeersProposal;
}
2017-07-19 15:17:12 +02:00
public JingleTransport<?> getPeersProposal() {
2017-07-21 18:29:27 +02:00
return peersProposal;
}
2017-07-22 00:26:50 +02:00
public abstract void handleTransportInfo(JingleContentTransportInfoElement info, JingleElement wrapping);
2017-07-21 17:58:57 +02:00
public void setParent(JingleContent parent) {
2017-07-21 17:58:57 +02:00
if (this.parent != parent) {
this.parent = parent;
}
}
public JingleContent getParent() {
2017-07-21 17:58:57 +02:00
return parent;
}
2017-07-19 15:17:12 +02:00
}