Skip to content

Commit

Permalink
Improve candidate loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rtm516 committed Aug 20, 2024
1 parent 50eb8ab commit d707bea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
api("org.bouncycastle:bctls-jdk18on:1.78.1")
api("org.bouncycastle:bcpkix-jdk18on:1.78.1")

// For sctp4j
// Needs https://github.com/steely-glint/srtplight and https://github.com/pipe/sctp4j to be installed locally
api("pe.pi:sctp4j:1.0.6")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public int getSendLimit() {
@Override
public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException {
System.out.println("receive! " + new String(buf, off, len));
// System.out.println("receive! " + bytesToHex(buf));

DatagramPacket packet = new DatagramPacket(buf, off, len);
socket.receive(packet);
return packet.getLength();
Expand All @@ -42,11 +44,23 @@ public int receive(byte[] buf, int off, int len, int waitMillis) throws IOExcept
@Override
public void send(byte[] buf, int off, int len) throws IOException {
System.out.println("send! " + new String(buf, off, len));
// System.out.println("send! " + bytesToHex(buf));
socket.send(new DatagramPacket(buf, off, len, component.getDefaultCandidate().getTransportAddress()));
}

@Override
public void close() {
socket.close();
}

private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
char[] hexChars = new char[bytes.length * 2];
for (int j = 0; j < bytes.length; j++) {
int v = bytes[j] & 0xFF;
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
}
return new String(hexChars);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void handleCandidateAdd(String sessionId, String message) throws Unknown
// agent.candidate
// activeSessions.get(sessionId).addCandidate(message);
component.addUpdateRemoteCandidates(parseCandidate(message, component.getParentStream()));
// component.updateRemoteCandidates();
component.updateRemoteCandidates();
}


Expand Down Expand Up @@ -397,18 +397,6 @@ public static RemoteCandidate parseCandidate(String value, IceMediaStream stream
private void initialize(JsonObject message) {
var turnAuthServers = message.getAsJsonArray("TurnAuthServers");

// rtcConfig = new RTCConfiguration();
// for (JsonElement authServerElement : turnAuthServers) {
// var authServer = authServerElement.getAsJsonObject();
// var server = new RTCIceServer();
// server.username = authServer.get("Username").getAsString();
// server.password = authServer.get("Password").getAsString();
// authServer.getAsJsonArray("Urls").forEach(url -> server.urls.add(url.getAsString()));
// rtcConfig.iceServers.add(server);
// }
//
// pendingSession = new PeerSession(this, rtcConfig);

agent = new Agent();
agent.setTrickling(true);

Expand Down

0 comments on commit d707bea

Please sign in to comment.