/** takes the remote candidates passed by the JingleIQ and incorporates that information into this ice agent. */
public void addRemoteCandidates(JingleIQ jiq) {
try {
for (ContentPacketExtension contentpe : jiq.getContentList()) {
String name = contentpe.getName();
IceMediaStream ims = agent.getStream(name);
if (ims != null) {
for (IceUdpTransportPacketExtension tpe : contentpe.getChildExtensionsOfType(IceUdpTransportPacketExtension.class)) {
System.out.println( "\t" + tpe );
if (tpe.getPassword() != null)
ims.setRemotePassword(tpe.getPassword());
if (tpe.getUfrag() != null)
ims.setRemoteUfrag(tpe.getUfrag());
List<CandidatePacketExtension> candidates = tpe.getChildExtensionsOfType(CandidatePacketExtension.class);
if (candidates == null || candidates.size() == 0)
continue;
// Sorts the remote candidates (host < reflexive <
// relayed) in
// order to create first host, then reflexive, the
// relayed
// candidates, to be able to set the relative-candidate
// matching the rel-addr/rel-port attribute.
Collections.sort(candidates);
for (CandidatePacketExtension cpe : candidates) {
if (cpe.getGeneration() != agent.getGeneration())
continue;
InetAddress ia;
try {
ia = InetAddress.getByName(cpe.getIP());
} catch (UnknownHostException uhe) {
continue;
}
TransportAddress relatedAddr = null;
if (cpe.getRelAddr() != null && cpe.getRelPort() != -1) {
relatedAddr = new TransportAddress(cpe.getRelAddr(), cpe.getRelPort(), Transport.parse(cpe.getProtocol().toLowerCase()));
}
Component component = ims.getComponent(cpe.getComponent());
if (component != null) {
// we should always be able to find this if there is one b/c of the sorting we did.
RemoteCandidate relatedCandidate = relatedAddr != null ? component.findRemoteCandidate(relatedAddr) : null;
TransportAddress ta = new TransportAddress(ia, cpe.getPort(), Transport.parse(cpe.getProtocol().toLowerCase()));
RemoteCandidate rc = new RemoteCandidate( ta,