Skip to content

Commit

Permalink
add null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
niyatim23 committed Apr 10, 2024
1 parent 2520e98 commit 5ba4db0
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,10 @@ private void handlePendingIceCandidates(final String clientId) {
while (pendingIceCandidatesQueueByClientId != null && !pendingIceCandidatesQueueByClientId.isEmpty()) {
final IceCandidate iceCandidate = pendingIceCandidatesQueueByClientId.peek();
final PeerConnection peer = peerConnectionFoundMap.get(clientId);
assert peer != null;
final boolean addIce = peer.addIceCandidate(iceCandidate);
Log.d(TAG, "Added ice candidate after SDP exchange " + iceCandidate + " " + (addIce ? "Successfully" : "Failed"));
if (peer != null) {
final boolean addIce = peer.addIceCandidate(iceCandidate);
Log.d(TAG, "Added ice candidate after SDP exchange " + iceCandidate + " " + (addIce ? "Successfully" : "Failed"));
}
pendingIceCandidatesQueueByClientId.remove();
}
// After sending pending ICE candidates, the client ID's peer connection need not be tracked
Expand All @@ -374,9 +375,10 @@ private void checkAndAddIceCandidate(final Event message, final IceCandidate ice
pendingIceCandidatesQueueByClientId = new LinkedList<>();
}

assert pendingIceCandidatesQueueByClientId != null;
pendingIceCandidatesQueueByClientId.add(iceCandidate);
pendingIceCandidatesMap.put(message.getSenderClientId(), pendingIceCandidatesQueueByClientId);
if (pendingIceCandidatesQueueByClientId != null) {
pendingIceCandidatesQueueByClientId.add(iceCandidate);
pendingIceCandidatesMap.put(message.getSenderClientId(), pendingIceCandidatesQueueByClientId);
}
}

// This is the case where peer connection is established and ICE candidates are received for the established
Expand All @@ -385,10 +387,10 @@ private void checkAndAddIceCandidate(final Event message, final IceCandidate ice
Log.d(TAG, "Peer connection found already");
// Remote sent us ICE candidates, add to local peer connection
final PeerConnection peer = peerConnectionFoundMap.get(message.getSenderClientId());
assert peer != null;
final boolean addIce = peer.addIceCandidate(iceCandidate);

Log.d(TAG, "Added ice candidate " + iceCandidate + " " + (addIce ? "Successfully" : "Failed"));
if (peer != null){
final boolean addIce = peer.addIceCandidate(iceCandidate);
Log.d(TAG, "Added ice candidate " + iceCandidate + " " + (addIce ? "Successfully" : "Failed"));
}
}
}

Expand Down Expand Up @@ -504,15 +506,15 @@ protected void onCreate(final Bundle savedInstanceState) {
if (mUrisList != null) {
for (int i = 0; i < mUrisList.size(); i++) {
final String turnServer = mUrisList.get(i).toString();
assert mUserNames != null;
assert mPasswords != null;
final IceServer iceServer = IceServer.builder(turnServer.replace("[", "").replace("]", ""))
.setUsername(mUserNames.get(i))
.setPassword(mPasswords.get(i))
.createIceServer();

Log.d(TAG, "IceServer details (TURN) = " + iceServer.toString());
peerIceServers.add(iceServer);
if (mUserNames != null && mPasswords != null) {
final IceServer iceServer = IceServer.builder(turnServer.replace("[", "").replace("]", ""))
.setUsername(mUserNames.get(i))
.setPassword(mPasswords.get(i))
.createIceServer();

Log.d(TAG, "IceServer details (TURN) = " + iceServer.toString());
peerIceServers.add(iceServer);
}
}
}

Expand Down

0 comments on commit 5ba4db0

Please sign in to comment.