From 20d5c853e1e031a6f3ab0966e7648e2027544c7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 10 Oct 2022 01:48:58 +0200 Subject: Fix crash when setting participant layout before receiving the data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When setting the participant layout, if the HPB is not used, the user ID is got from the participant list data fetched when a new participant is found. However, as the participant layout is setup as soon as a new participant is found the data may have not been received yet, which ended in a crash (NullPointerException). Now the access to the participant object is guarded to prevent that. Signed-off-by: Daniel Calviño Sánchez --- app/src/main/java/com/nextcloud/talk/activities/CallActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9085f6abe..0339b33cd 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -2361,7 +2361,7 @@ public class CallActivity extends CallBaseActivity { String userId = ""; if (hasMCU) { userId = webSocketClient.getUserIdForSession(session); - } else if (participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) { + } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) { userId = participantMap.get(session).getCalculatedActorId(); } -- cgit v1.2.3 From 404ddc8c2790e37dad015ed4cf7e519641df4c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 10 Oct 2022 01:54:12 +0200 Subject: Fix avatar when setting participant layout before receiving the data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a new participant is found and the layout for that participant is set up the participant data might have not been fetched yet. If that happens the user ID can not be got from the data and therefore a guest avatar would be shown for that participant, even if that participant is a normal user. However, the signaling message that is used to find new participants already includes the user ID, so it is now explicitly given and, if not, then it is got from the participant data (which is needed when handling the establishment of a connection, as in that case the event does not contain the user ID). Signed-off-by: Daniel Calviño Sánchez --- .../nextcloud/talk/activities/CallActivity.java | 35 +++++++++++++++++----- 1 file changed, 27 insertions(+), 8 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 0339b33cd..4b65a8fb1 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -1835,6 +1835,7 @@ public class CallActivity extends CallBaseActivity { Log.d(TAG, "processUsersInRoom"); List newSessions = new ArrayList<>(); Set oldSessions = new HashSet<>(); + Map userIdsBySessionId = new HashMap<>(); hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU(); Log.d(TAG, " hasMCU is " + hasMCU); @@ -1862,6 +1863,15 @@ public class CallActivity extends CallBaseActivity { } else { oldSessions.add(participant.get("sessionId").toString()); } + + // The property is "userId" when not using the external signaling server and "userid" when using it. + String userId = null; + if (participant.get("userId") != null) { + userId = participant.get("userId").toString(); + } else if (participant.get("userid") != null) { + userId = participant.get("userid").toString(); + } + userIdsBySessionId.put(participant.get("sessionId").toString(), userId); } else { Log.d(TAG, " inCallFlag of currentSessionId: " + inCallFlag); if (inCallFlag == 0 && !CallStatus.LEAVING.equals(currentCallStatus) && ApplicationWideCurrentRoomHolder.getInstance().isInCall()) { @@ -1900,10 +1910,13 @@ public class CallActivity extends CallBaseActivity { Log.d(TAG, " newSession joined: " + sessionId); getOrCreatePeerConnectionWrapperForSessionIdAndType(sessionId, VIDEO_STREAM_TYPE_VIDEO, false); + String userId = userIdsBySessionId.get(sessionId); + runOnUiThread(() -> { setupVideoStreamForLayout( null, sessionId, + userId, false, VIDEO_STREAM_TYPE_VIDEO); }); @@ -2243,12 +2256,14 @@ public class CallActivity extends CallBaseActivity { setupVideoStreamForLayout( mediaStreamEvent.getMediaStream(), mediaStreamEvent.getSession(), + null, hasAtLeastOneVideoStream, mediaStreamEvent.getVideoStreamType()); } else { setupVideoStreamForLayout( null, mediaStreamEvent.getSession(), + null, false, mediaStreamEvent.getVideoStreamType()); } @@ -2339,6 +2354,7 @@ public class CallActivity extends CallBaseActivity { private void setupVideoStreamForLayout(@Nullable MediaStream mediaStream, String session, + String userId, boolean videoStreamEnabled, String videoStreamType) { PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session, @@ -2358,17 +2374,20 @@ public class CallActivity extends CallBaseActivity { nick = peerConnectionWrapper != null ? peerConnectionWrapper.getNick() : ""; } - String userId = ""; - if (hasMCU) { - userId = webSocketClient.getUserIdForSession(session); - } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) { - userId = participantMap.get(session).getCalculatedActorId(); + String userId4Usage = userId; + + if (userId4Usage == null) { + if (hasMCU) { + userId4Usage = webSocketClient.getUserIdForSession(session); + } else if (participantMap.get(session) != null && participantMap.get(session).getCalculatedActorType() == Participant.ActorType.USERS) { + userId4Usage = participantMap.get(session).getCalculatedActorId(); + } } String urlForAvatar; - if (!TextUtils.isEmpty(userId)) { + if (!TextUtils.isEmpty(userId4Usage)) { urlForAvatar = ApiUtils.getUrlForAvatar(baseUrl, - userId, + userId4Usage, true); } else { urlForAvatar = ApiUtils.getUrlForGuestAvatar(baseUrl, @@ -2376,7 +2395,7 @@ public class CallActivity extends CallBaseActivity { true); } - ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId, + ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(userId4Usage, session, connected, nick, -- cgit v1.2.3