Skip to content

Commit

Permalink
Use ephemeral ports for the ICE data stream
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Aug 21, 2024
1 parent 45c02b1 commit cb1a145
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void receiveOffer(BigInteger from, String sessionId, String message) {
}
}

component = agent.createComponent(stream, 5000, 5000, 6000, KeepAliveStrategy.SELECTED_ONLY, true);
component = agent.createComponent(stream, KeepAliveStrategy.SELECTED_ONLY, true);

var transport = new CustomDatagramTransport();

Expand All @@ -93,7 +93,7 @@ public void receiveOffer(BigInteger from, String sessionId, String message) {
media.setAttribute("fingerprint", "sha-256 " + client.getClientFingerprint());
media.setAttribute("setup", "active");
media.setAttribute("mid", "0");
media.setAttribute("sctp-port", "5000");
media.setAttribute("sctp-port", String.valueOf(getComponentPort(5000)));
media.setAttribute("max-message-size", "262144");
answer.setMediaDescriptions(new Vector<>(Collections.of(media)));

Expand Down Expand Up @@ -194,4 +194,22 @@ private RemoteCandidate parseCandidate(String value, IceMediaStream stream) {

return new RemoteCandidate(transAddr, component, type, foundation, priority, relatedCandidate, ufrag);
}

/**
* Get the port of the first host candidate.
*
* @param fallback the port to return if no host candidate is found
* @return the port of the first host candidate or the fallback port
*/
private int getComponentPort(int fallback) {
int port = fallback;
for (LocalCandidate localCandidate : component.getLocalCandidates()) {
if (localCandidate.getType() == CandidateType.HOST_CANDIDATE) {
port = localCandidate.getTransportAddress().getPort();
break;
}
}

return port;
}
}

0 comments on commit cb1a145

Please sign in to comment.