mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-12-06 02:51:11 +01:00
More Refactoring
git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@7311 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
parent
9e4be21775
commit
79b19ce620
10 changed files with 186 additions and 125 deletions
|
|
@ -54,7 +54,6 @@ public abstract class JingleMediaSession {
|
|||
this.local = local;
|
||||
this.remote = remote;
|
||||
this.payloadType = payloadType;
|
||||
initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ public class ICEResolver extends TransportResolver {
|
|||
long sid;
|
||||
String server = "stun.xten.net";
|
||||
int port = 3478;
|
||||
ICENegociator iceNegociator = null;
|
||||
|
||||
public ICEResolver(XMPPConnection connection, String server, int port) {
|
||||
super();
|
||||
|
|
@ -58,85 +59,11 @@ public class ICEResolver extends TransportResolver {
|
|||
if (!isResolving() && !isResolved()) {
|
||||
System.out.println("Initialized");
|
||||
|
||||
ICENegociator cc = new ICENegociator((short) 1, server, port);
|
||||
iceNegociator = new ICENegociator((short) 1, server, port);
|
||||
// gather candidates
|
||||
cc.gatherCandidateAddresses();
|
||||
iceNegociator.gatherCandidateAddresses();
|
||||
// priorize candidates
|
||||
cc.prioritizeCandidates();
|
||||
|
||||
for (Candidate candidate : cc.getSortedCandidates())
|
||||
try {
|
||||
Candidate.CandidateType type = candidate.getCandidateType();
|
||||
String typeString = "local";
|
||||
if (type.equals(Candidate.CandidateType.ServerReflexive))
|
||||
typeString = "srflx";
|
||||
else if (type.equals(Candidate.CandidateType.PeerReflexive))
|
||||
typeString = "prflx";
|
||||
else if (type.equals(Candidate.CandidateType.Relayed))
|
||||
typeString = "relay";
|
||||
else
|
||||
typeString = "host";
|
||||
|
||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), typeString);
|
||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||
transportCandidate.setPort(getFreePort());
|
||||
try {
|
||||
transportCandidate.addCandidateEcho();
|
||||
}
|
||||
catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.addCandidate(transportCandidate);
|
||||
|
||||
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (RTPBridge.serviceAvailable(connection)) {
|
||||
try {
|
||||
String localIp = cc.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
|
||||
|
||||
sid = Math.abs(random.nextLong());
|
||||
|
||||
RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
|
||||
|
||||
TransportCandidate localCandidate = new ICECandidate(
|
||||
rtpBridge.getIp(), 1, cc.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortA(), "1", 0, "relay");
|
||||
localCandidate.setLocalIp(localIp);
|
||||
|
||||
TransportCandidate remoteCandidate = new ICECandidate(
|
||||
rtpBridge.getIp(), 1, cc.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortB(), "1", 0, "relay");
|
||||
remoteCandidate.setLocalIp(localIp);
|
||||
|
||||
localCandidate.setSymmetric(remoteCandidate);
|
||||
remoteCandidate.setSymmetric(localCandidate);
|
||||
|
||||
localCandidate.setPassword(rtpBridge.getPass());
|
||||
remoteCandidate.setPassword(rtpBridge.getPass());
|
||||
|
||||
localCandidate.setSessionId(rtpBridge.getSid());
|
||||
remoteCandidate.setSessionId(rtpBridge.getSid());
|
||||
|
||||
localCandidate.setConnection(this.connection);
|
||||
remoteCandidate.setConnection(this.connection);
|
||||
|
||||
addCandidate(localCandidate);
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
iceNegociator.prioritizeCandidates();
|
||||
|
||||
}
|
||||
this.setInitialized();
|
||||
|
|
@ -151,7 +78,89 @@ public class ICEResolver extends TransportResolver {
|
|||
*/
|
||||
public synchronized void resolve() throws XMPPException {
|
||||
this.setResolveInit();
|
||||
System.out.println("Resolve");
|
||||
|
||||
this.cancel();
|
||||
for (TransportCandidate candidate : this.getCandidatesList()) {
|
||||
if (candidate instanceof ICECandidate) {
|
||||
ICECandidate iceCandidate = (ICECandidate) candidate;
|
||||
iceCandidate.removeCandidateEcho();
|
||||
}
|
||||
}
|
||||
|
||||
for (Candidate candidate : iceNegociator.getSortedCandidates())
|
||||
try {
|
||||
Candidate.CandidateType type = candidate.getCandidateType();
|
||||
String typeString = "local";
|
||||
if (type.equals(Candidate.CandidateType.ServerReflexive))
|
||||
typeString = "srflx";
|
||||
else if (type.equals(Candidate.CandidateType.PeerReflexive))
|
||||
typeString = "prflx";
|
||||
else if (type.equals(Candidate.CandidateType.Relayed))
|
||||
typeString = "relay";
|
||||
else
|
||||
typeString = "host";
|
||||
|
||||
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, candidate.getNetwork(), "1", candidate.getPort(), "1", candidate.getPriority(), typeString);
|
||||
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
|
||||
transportCandidate.setPort(getFreePort());
|
||||
try {
|
||||
transportCandidate.addCandidateEcho();
|
||||
}
|
||||
catch (SocketException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
this.addCandidate(transportCandidate);
|
||||
|
||||
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (RTPBridge.serviceAvailable(connection)) {
|
||||
try {
|
||||
String localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
|
||||
|
||||
sid = Math.abs(random.nextLong());
|
||||
|
||||
RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));
|
||||
|
||||
TransportCandidate localCandidate = new ICECandidate(
|
||||
rtpBridge.getIp(), 1, iceNegociator.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortA(), "1", 0, "relay");
|
||||
localCandidate.setLocalIp(localIp);
|
||||
|
||||
TransportCandidate remoteCandidate = new ICECandidate(
|
||||
rtpBridge.getIp(), 1, iceNegociator.getPublicCandidate().getNetwork(), "1", rtpBridge.getPortB(), "1", 0, "relay");
|
||||
remoteCandidate.setLocalIp(localIp);
|
||||
|
||||
localCandidate.setSymmetric(remoteCandidate);
|
||||
remoteCandidate.setSymmetric(localCandidate);
|
||||
|
||||
localCandidate.setPassword(rtpBridge.getPass());
|
||||
remoteCandidate.setPassword(rtpBridge.getPass());
|
||||
|
||||
localCandidate.setSessionId(rtpBridge.getSid());
|
||||
remoteCandidate.setSessionId(rtpBridge.getSid());
|
||||
|
||||
localCandidate.setConnection(this.connection);
|
||||
remoteCandidate.setConnection(this.connection);
|
||||
|
||||
addCandidate(localCandidate);
|
||||
|
||||
}
|
||||
catch (UtilityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.setResolveEnd();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ import java.util.List;
|
|||
public abstract class TransportResolver {
|
||||
|
||||
public enum Type {
|
||||
|
||||
rawupd, ice
|
||||
}
|
||||
|
||||
|
|
@ -91,7 +92,7 @@ public abstract class TransportResolver {
|
|||
public static final int CHECK_TIMEOUT = 2000;
|
||||
|
||||
// Listeners for events
|
||||
private final ArrayList listeners = new ArrayList();
|
||||
private final ArrayList<TransportResolverListener> listeners = new ArrayList<TransportResolverListener>();
|
||||
|
||||
// TRue if the resolver is working
|
||||
private boolean resolving;
|
||||
|
|
@ -105,10 +106,7 @@ public abstract class TransportResolver {
|
|||
// We store a list of candidates internally, just in case there are several
|
||||
// possibilities. When the user asks for a transport, we return the best
|
||||
// one.
|
||||
protected final List candidates = new ArrayList();
|
||||
|
||||
// Remote candidates that are being checked
|
||||
private final static ArrayList candidatesChecking = new ArrayList();
|
||||
protected final List<TransportCandidate> candidates = new ArrayList<TransportCandidate>();
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
|
|
@ -355,7 +353,7 @@ public abstract class TransportResolver {
|
|||
*
|
||||
* @return the list of transport candidates
|
||||
*/
|
||||
public List getCandidatesList() {
|
||||
public List<TransportCandidate> getCandidatesList() {
|
||||
ArrayList result = null;
|
||||
|
||||
synchronized (candidates) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue