Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/jingle/component/JingleTransport.java

118 lines
4.1 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-08-04 23:05:59 +02:00
package org.jivesoftware.smackx.jingle.component;
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;
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-08-13 19:44:02 +02:00
public abstract class JingleTransport<D extends JingleContentTransportElement> {
2017-07-19 15:17:12 +02:00
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-08-05 00:43:54 +02:00
// Insert sorted by descending priority
int i;
// Find appropriate index
2017-08-05 00:43:54 +02:00
for (i = 0; i < ourCandidates.size(); i++) {
JingleTransportCandidate<?> c = ourCandidates.get(i);
2017-07-21 17:58:57 +02:00
if (c == candidate || c.equals(candidate)) {
2017-08-05 00:43:54 +02:00
c.setParent(this); // Candidate might equal, but not be same, so set parent just in case
return;
}
2017-08-05 00:43:54 +02:00
if (c.getPriority() < candidate.getPriority()) {
break;
}
}
2017-08-05 00:43:54 +02:00
ourCandidates.add(i, candidate);
candidate.setParent(this);
}
public void addTheirCandidate(JingleTransportCandidate<?> candidate) {
// Insert sorted by descending priority
2017-08-05 00:43:54 +02:00
int i;
2017-07-21 17:58:57 +02:00
// Find appropriate index
2017-08-05 00:43:54 +02:00
for (i = 0; i < theirCandidates.size(); i++) {
JingleTransportCandidate<?> c = theirCandidates.get(i);
2017-07-21 17:58:57 +02:00
if (c == candidate || c.equals(candidate)) {
2017-08-05 00:43:54 +02:00
c.setParent(this); // Candidate might equal, but not be same, so set parent just in case
2017-07-21 17:58:57 +02:00
return;
}
2017-08-05 00:43:54 +02:00
if (c.getPriority() < candidate.getPriority()) {
break;
2017-07-21 17:58:57 +02:00
}
}
2017-08-05 00:43:54 +02:00
theirCandidates.add(i, candidate);
candidate.setParent(this);
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-08-05 00:43:54 +02:00
this.parent = parent;
2017-07-21 17:58:57 +02:00
}
public JingleContent getParent() {
2017-07-21 17:58:57 +02:00
return parent;
}
2017-07-25 20:25:36 +02:00
2017-08-03 23:01:55 +02:00
public abstract void handleSessionAccept(JingleContentTransportElement transportElement, XMPPConnection connection);
public abstract void cleanup();
2017-07-19 15:17:12 +02:00
}