1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-16 08:34:50 +02:00
Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/components/JingleTransport.java

139 lines
4.8 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.
*/
2017-07-27 15:18:18 +02:00
package org.jivesoftware.smackx.jingle.components;
2017-07-19 15:17:12 +02:00
2017-07-21 17:58:57 +02:00
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
2017-07-21 17:58:57 +02:00
2017-07-21 23:05:46 +02:00
import org.jivesoftware.smack.SmackException;
2017-07-27 00:12:42 +02:00
import org.jivesoftware.smack.SmackFuture;
2017-07-19 23:15:17 +02:00
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.IQ;
2017-07-25 20:25:36 +02:00
import org.jivesoftware.smackx.bytestreams.BytestreamSession;
2017-07-27 18:09:49 +02:00
import org.jivesoftware.smackx.jingle.callbacks.JingleTransportCallback;
2017-07-21 23:05:46 +02:00
import org.jivesoftware.smackx.jingle.element.JingleContentTransportElement;
import org.jivesoftware.smackx.jingle.element.JingleContentTransportInfoElement;
2017-07-25 20:25:36 +02:00
import org.jivesoftware.smackx.jingle.element.JingleElement;
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
*/
2017-07-27 00:12:42 +02:00
public abstract class JingleTransport<D extends JingleContentTransportElement> extends SmackFuture<BytestreamSession> {
2017-07-19 15:17:12 +02:00
private static final Logger LOGGER = Logger.getLogger(JingleTransport.class.getName());
private JingleContent parent;
private final ArrayList<JingleTransportCandidate<?>> ourCandidates = new ArrayList<>();
private final ArrayList<JingleTransportCandidate<?>> theirCandidates = new ArrayList<>();
2017-07-21 17:58:57 +02:00
2017-07-25 20:25:36 +02:00
protected BytestreamSession bytestreamSession;
2017-07-19 15:17:12 +02:00
public abstract D getElement();
public void addOurCandidate(JingleTransportCandidate<?> candidate) {
2017-07-27 00:12:42 +02:00
// Insert sorted by descending priority
// Empty list -> insert
if (ourCandidates.isEmpty()) {
ourCandidates.add(candidate);
candidate.setParent(this);
return;
}
// Find appropriate index
for (int i = 0; i < ourCandidates.size(); i++) {
JingleTransportCandidate<?> c = ourCandidates.get(i);
2017-07-21 17:58:57 +02:00
// list already contains element -> return
if (c == candidate || c.equals(candidate)) {
return;
}
//Found the index
if (c.getPriority() <= candidate.getPriority()) {
ourCandidates.add(i, candidate);
candidate.setParent(this);
return;
}
}
}
public void addTheirCandidate(JingleTransportCandidate<?> candidate) {
// Insert sorted by descending priority
2017-07-21 17:58:57 +02:00
// Empty list -> insert
if (theirCandidates.isEmpty()) {
theirCandidates.add(candidate);
2017-07-21 17:58:57 +02:00
candidate.setParent(this);
return;
}
// Find appropriate index
for (int i = 0; i < theirCandidates.size(); i++) {
JingleTransportCandidate<?> c = theirCandidates.get(i);
2017-07-21 17:58:57 +02:00
// list already contains element -> return
if (c == candidate || c.equals(candidate)) {
2017-07-21 17:58:57 +02:00
return;
}
//Found the index
if (c.getPriority() <= candidate.getPriority()) {
theirCandidates.add(i, candidate);
2017-07-21 17:58:57 +02:00
candidate.setParent(this);
return;
2017-07-21 17:58:57 +02:00
}
}
}
2017-08-03 23:01:55 +02:00
public abstract void prepare(XMPPConnection connection);
public List<JingleTransportCandidate<?>> getOurCandidates() {
return ourCandidates;
}
public List<JingleTransportCandidate<?>> getTheirCandidates() {
return theirCandidates;
2017-07-21 17:58:57 +02:00
}
2017-07-19 15:17:12 +02:00
public abstract String getNamespace();
2017-07-27 22:23:10 +02:00
public abstract void establishIncomingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
2017-07-25 20:25:36 +02:00
throws SmackException.NotConnectedException, InterruptedException;
2017-07-19 23:15:17 +02:00
2017-07-27 22:23:10 +02:00
public abstract void establishOutgoingBytestreamSession(XMPPConnection connection, JingleTransportCallback callback, JingleSession session)
2017-07-25 20:25:36 +02:00
throws SmackException.NotConnectedException, InterruptedException;
2017-07-19 15:17:12 +02:00
public abstract IQ 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-25 20:25:36 +02:00
public BytestreamSession getBytestreamSession() {
return bytestreamSession;
}
2017-08-03 23:01:55 +02:00
public abstract void handleSessionAccept(JingleContentTransportElement transportElement, XMPPConnection connection);
2017-07-19 15:17:12 +02:00
}