From f53cb610d3387fce41832c45759e1881095790c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 12 Oct 2022 11:05:27 +0200 Subject: [PATCH 1/4] Fuse declaration and initial assignment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../main/java/com/nextcloud/talk/activities/CallActivity.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 4b65a8fb1..30875389b 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1851,13 +1851,12 @@ public class CallActivity extends CallBaseActivity { for (HashMap participant : users) { long inCallFlag = (long) participant.get("inCall"); if (!participant.get("sessionId").equals(currentSessionId)) { - boolean isNewSession; Log.d(TAG, " inCallFlag of participant " + participant.get("sessionId").toString().substring(0, 4) + " : " + inCallFlag); - isNewSession = inCallFlag != 0; + boolean isNewSession = inCallFlag != 0; if (isNewSession) { newSessions.add(participant.get("sessionId").toString()); } else { From 1ba6e293b23fd25d980c9fc79d01dc8291ab0d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 12 Oct 2022 11:06:05 +0200 Subject: [PATCH 2/4] Rename to a more accurate name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- .../main/java/com/nextcloud/talk/activities/CallActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 30875389b..5693d7517 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1856,8 +1856,8 @@ public class CallActivity extends CallBaseActivity { + " : " + inCallFlag); - boolean isNewSession = inCallFlag != 0; - if (isNewSession) { + boolean isInCall = inCallFlag != 0; + if (isInCall) { newSessions.add(participant.get("sessionId").toString()); } else { oldSessions.add(participant.get("sessionId").toString()); From f84a6217805437e26c60b5176a57d4a691b4676a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 12 Oct 2022 11:06:32 +0200 Subject: [PATCH 3/4] Do not store sessions not in call as old sessions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old sessions are used to know which connections need to be ended because they are no longer in the call. However, if a participant is no longer in the call but there was no connection yet then there is no connection that needs to be ended; any existing connection will be added when looping through the connection list, and if it needs to be stopped it will be found when substracting the sessions that are currently in the call. The old sessions are also used to find the new sessions in the call. Due to an issue in how that is computed "newSessions" currently store the sessions in the call rather than only the new sessions (this will be addressed in a following commit). Nevertheless, in both cases any session not in the call for which there is no connection either will not make any difference in the computed "newSessions" (as they are mutually exclusive, so they will never be removed from "newSessions" when substracting the old sessions). Due to all that it is not needed to store sessions not in call as old sessions / sessions to end. Signed-off-by: Daniel Calviño Sánchez --- .../main/java/com/nextcloud/talk/activities/CallActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 5693d7517..53b0c8116 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1859,8 +1859,6 @@ public class CallActivity extends CallBaseActivity { boolean isInCall = inCallFlag != 0; if (isInCall) { newSessions.add(participant.get("sessionId").toString()); - } else { - oldSessions.add(participant.get("sessionId").toString()); } // The property is "userId" when not using the external signaling server and "userid" when using it. From 3278829dba7770405bdfe9ea265d8696a841acc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 12 Oct 2022 11:07:11 +0200 Subject: [PATCH 4/4] Fix computing new sessions in a call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new sessions are computed by substracting the old sessions (those for which a PeerConnectionWrapper exists) from the sessions currently in the call. However, when "oldSessions" was used for that it no longer contained the old sessions, it only contained the sessions which were no longer in the call. As those sessions are mutually exclusive with the sessions currently in the call nothing was substracted from "newSessions", and it ended being the sessions currently in the call instead. When the HPB is not used the list of participants in the conversation is periodically updated every 30 seconds if no other signaling message was received in the meantime. As the layout for a participant overrides any previous layout for that participant this periodically reset the layout of all participants in the call, as they were all treated as new sessions. When the HPB is used the list of participants in the conversation is updated only when something changed. However, similarly to the previous case, when that happens the layout of all participants in the call is also reset for the same reason. To solve that now "oldSessions" is not modified, so it contains the sessions for which a PeerConnectionWrapper exists, and substracting it from "newSessions" now gives only the new sessions. The other usages of "newSessions" besides creating the connection and setting up the layout, that is, getting the peers in the call and changing the call status to "In conversation", should be safe if executed only when there are new sessions rather than when there are participants in the call but they did not change. Resolves: #2486 Signed-off-by: Daniel Calviño Sánchez --- .../java/com/nextcloud/talk/activities/CallActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index 53b0c8116..22f9406d5 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1885,7 +1885,8 @@ public class CallActivity extends CallBaseActivity { } // Calculate sessions that left the call - oldSessions.removeAll(newSessions); + List disconnectedSessions = new ArrayList<>(oldSessions); + disconnectedSessions.removeAll(newSessions); // Calculate sessions that join the call newSessions.removeAll(oldSessions); @@ -1923,7 +1924,7 @@ public class CallActivity extends CallBaseActivity { setCallState(CallStatus.IN_CONVERSATION); } - for (String sessionId : oldSessions) { + for (String sessionId : disconnectedSessions) { Log.d(TAG, " oldSession that will be removed is: " + sessionId); endPeerConnection(sessionId, false); }