Skip to content

Commit

Permalink
Improve candidate collection
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Aug 21, 2024
1 parent 7082648 commit a4c942f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,24 @@ public void receiveOffer(BigInteger from, String sessionId, String message) {
}
}

boolean hadFirstCandidate = false;
long lastCandidateTime = 0;
public void addCandidate(String message) {
component.addRemoteCandidate(parseCandidate(message, component.getParentStream()));

if (component.getRemoteCandidateCount() == 4) {
agent.startConnectivityEstablishment();
lastCandidateTime = System.currentTimeMillis();

if (!hadFirstCandidate) {
hadFirstCandidate = true;
new Thread(() -> {
try {
while (System.currentTimeMillis() - lastCandidateTime < 200) {
Thread.sleep(200);
}
agent.startConnectivityEstablishment();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ private void handleConnectRequest(BigInteger from, String sessionId, String mess
}

private void handleCandidateAdd(String sessionId, String message) {
activeSessions.get(sessionId).addCandidate(message);
// Check the session exists, sometimes we get candidates after the session has been disconnected
PeerSession session = activeSessions.get(sessionId);
if (session != null) {
session.addCandidate(message);
}
}

public void handleDisconnect(String sessionId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public SctpAssociationListener(SessionInfo sessionInfo, Logger logger, Runnable

@Override
public void onAssociated(Association association) {
logger.debug("SCTP session associated");
// System.out.println("Association associated: " + association.toString());
}

Expand Down

0 comments on commit a4c942f

Please sign in to comment.