From 215dbf502f5cebab17dc6f926baa646c859158b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Sun, 4 Dec 2022 13:45:48 +0100 Subject: [PATCH] Start and end connections based on "inCall" flags changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Until now the connections were started when a participant joined with audio and/or video (or, if there was no HPB, if the self participant had audio and/or video), and ended when a participant left the call. If a participant starts or stops publishing while being in the call, either because the user now selected a microphone or camera or because the participant was granted permissions, the participant force reconnected to the call (leave and join it again), which ensured that all other participants started or ended the connections as needed. To avoid having to force reconnect and have a smoother call experience now the clients are expected to keep track of the "inCall" flags and start and end the connections as needed with the existing session. Note that if the client is used against an older Talk version everything would still work as before; as the other participant leaves and joins the call again with a different session when needed the call flags would not be updated for the previous session (other than to leave it), so the new code to handle the updated call flags should have no effect (and, even if it does, the connection would be established as needed against the new session once the participant joins again). Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 49fcb6d6a..6d964a013 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1903,6 +1903,31 @@ public class CallActivity extends CallBaseActivity { setCallState(CallStatus.IN_CONVERSATION); } + for (Participant participant : updated) { + String sessionId = participant.getSessionId(); + + if (sessionId.equals(currentSessionId)) { + continue; + } + + boolean participantHasAudioOrVideo = participantInCallFlagsHaveAudioOrVideo(participant); + PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(sessionId, "video"); + + if (hasMCU) { + if (participantHasAudioOrVideo && peerConnectionWrapper == null) { + getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, "video", false); + } else if (!participantHasAudioOrVideo && peerConnectionWrapper != null) { + endPeerConnection(sessionId, "video"); + } + } else { + if ((participantHasAudioOrVideo || selfParticipantHasAudioOrVideo) && peerConnectionWrapper == null) { + getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, "video", false); + } else if (!participantHasAudioOrVideo && !selfParticipantHasAudioOrVideo && peerConnectionWrapper != null) { + endPeerConnection(sessionId, "video"); + } + } + } + for (Participant participant : left) { String sessionId = participant.getSessionId(); Log.d(TAG, " oldSession that will be removed is: " + sessionId);