Simplify ending the peer connections

The peer connections will be of either "video" or "screen" type, so they
can be simply removed based on the session id and an explicit type.

Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
This commit is contained in:
Daniel Calviño Sánchez 2022-11-29 20:49:29 +01:00 committed by Marcel Hibbe (Rebase PR Action)
parent 9ae969b0f8
commit 67e259f792

View file

@ -1726,7 +1726,8 @@ public class CallActivity extends CallBaseActivity {
peerConnectionIdsToEnd.add(wrapper.getSessionId());
}
for (String sessionId : peerConnectionIdsToEnd) {
endPeerConnection(sessionId, false);
endPeerConnection(sessionId, "video");
endPeerConnection(sessionId, "screen");
}
List<String> callParticipantIdsToEnd = new ArrayList<String>(peerConnectionWrapperList.size());
@ -1835,7 +1836,8 @@ public class CallActivity extends CallBaseActivity {
for (Participant participant : participantsInCall) {
String sessionId = participant.getSessionId();
Log.d(TAG, " session that will be removed is: " + sessionId);
endPeerConnection(sessionId, false);
endPeerConnection(sessionId, "video");
endPeerConnection(sessionId, "screen");
removeCallParticipant(sessionId);
}
@ -1904,7 +1906,8 @@ public class CallActivity extends CallBaseActivity {
for (Participant participant : left) {
String sessionId = participant.getSessionId();
Log.d(TAG, " oldSession that will be removed is: " + sessionId);
endPeerConnection(sessionId, false);
endPeerConnection(sessionId, "video");
endPeerConnection(sessionId, "screen");
removeCallParticipant(sessionId);
}
}
@ -1918,11 +1921,6 @@ public class CallActivity extends CallBaseActivity {
(!isVoiceOnlyCall && (participant.getInCall() & Participant.InCallFlags.WITH_VIDEO) > 0);
}
private void deletePeerConnection(PeerConnectionWrapper peerConnectionWrapper) {
peerConnectionWrapper.removePeerConnection();
peerConnectionWrapperList.remove(peerConnectionWrapper);
}
private PeerConnectionWrapper getPeerConnectionWrapperForSessionIdAndType(String sessionId, String type) {
for (PeerConnectionWrapper wrapper : peerConnectionWrapperList) {
if (wrapper.getSessionId().equals(sessionId)
@ -2057,42 +2055,27 @@ public class CallActivity extends CallBaseActivity {
return callParticipant;
}
private List<PeerConnectionWrapper> getPeerConnectionWrapperListForSessionId(String sessionId) {
List<PeerConnectionWrapper> internalList = new ArrayList<>();
for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrapperList) {
if (peerConnectionWrapper.getSessionId().equals(sessionId)) {
internalList.add(peerConnectionWrapper);
}
private void endPeerConnection(String sessionId, String type) {
PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(sessionId, type);
if (peerConnectionWrapper == null) {
return;
}
return internalList;
}
private void endPeerConnection(String sessionId, boolean justScreen) {
List<PeerConnectionWrapper> peerConnectionWrappers;
if (!(peerConnectionWrappers = getPeerConnectionWrapperListForSessionId(sessionId)).isEmpty()) {
for (PeerConnectionWrapper peerConnectionWrapper : peerConnectionWrappers) {
if (peerConnectionWrapper.getSessionId().equals(sessionId)) {
if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) {
peerConnectionWrapper.removeObserver(selfPeerConnectionObserver);
}
String videoStreamType = peerConnectionWrapper.getVideoStreamType();
if (VIDEO_STREAM_TYPE_SCREEN.equals(videoStreamType) || !justScreen) {
CallParticipant callParticipant = callParticipants.get(sessionId);
if (callParticipant != null) {
if ("screen".equals(videoStreamType)) {
if ("screen".equals(type)) {
callParticipant.setScreenPeerConnectionWrapper(null);
} else {
callParticipant.setPeerConnectionWrapper(null);
}
}
deletePeerConnection(peerConnectionWrapper);
}
}
}
}
peerConnectionWrapper.removePeerConnection();
peerConnectionWrapperList.remove(peerConnectionWrapper);
}
private void removeCallParticipant(String sessionId) {
@ -2599,7 +2582,7 @@ public class CallActivity extends CallBaseActivity {
@Override
public void onUnshareScreen() {
endPeerConnection(sessionId, true);
endPeerConnection(sessionId, "screen");
}
}