From 29117e8b1b6a1304d949e496bb229583f59c4622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Sun, 27 Nov 2022 14:38:11 +0100 Subject: [PATCH] Get user ID from signaling message when creating ParticipantDisplayItem MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The user ID set when creating the ParticipantDisplayItem was got from the join event when the external signaling server was used, and from an API call when the internal signaling server was used. However, the user ID is already known from the signaling message that updates the participant list, and is the one set on the ParticipantDisplayItems when a participant joins the call. Therefore the other sources are not needed, so now it is unified to always use the value from the signaling message. Note that in the rare cases in which a ParticipantDisplayItem is created before the participant is seen as in the call the user ID will be temporary unknown, although it will be automatically fixed once the participant list update is received. Moreover, even if the other sources were used it was not guaranteed that the user ID was known, so this should not be a problem. Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 53 ++----------------- .../talk/webrtc/MagicWebSocketInstance.java | 11 ---- 2 files changed, 3 insertions(+), 61 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 d8e9dfb09..cb07bc62a 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -74,7 +74,6 @@ import com.nextcloud.talk.models.json.conversations.RoomOverall; import com.nextcloud.talk.models.json.conversations.RoomsOverall; import com.nextcloud.talk.models.json.generic.GenericOverall; import com.nextcloud.talk.models.json.participants.Participant; -import com.nextcloud.talk.models.json.participants.ParticipantsOverall; import com.nextcloud.talk.models.json.signaling.DataChannelMessage; import com.nextcloud.talk.models.json.signaling.NCMessagePayload; import com.nextcloud.talk.models.json.signaling.NCSignalingMessage; @@ -236,7 +235,7 @@ public class CallActivity extends CallBaseActivity { private MediaStream localStream; private String credentials; private List peerConnectionWrapperList = new ArrayList<>(); - private Map participantMap = new HashMap<>(); + private Map userIdsBySessionId = new HashMap<>(); private boolean videoOn = false; private boolean microphoneOn = false; @@ -1775,7 +1774,7 @@ public class CallActivity extends CallBaseActivity { Log.d(TAG, "processUsersInRoom"); List newSessions = new ArrayList<>(); Set oldSessions = new HashSet<>(); - Map userIdsBySessionId = new HashMap<>(); + userIdsBySessionId = new HashMap<>(); hasMCU = hasExternalSignalingServer && webSocketClient != null && webSocketClient.hasMCU(); Log.d(TAG, " hasMCU is " + hasMCU); @@ -1844,10 +1843,6 @@ public class CallActivity extends CallBaseActivity { return; } - if (newSessions.size() > 0 && !hasMCU) { - getPeersForCall(); - } - if (hasMCU) { // Ensure that own publishing peer is set up. getOrCreatePeerConnectionWrapperForSessionIdAndType(webSocketClient.getSessionId(), VIDEO_STREAM_TYPE_VIDEO, true); @@ -1886,43 +1881,6 @@ public class CallActivity extends CallBaseActivity { } } - private void getPeersForCall() { - Log.d(TAG, "getPeersForCall"); - int apiVersion = ApiUtils.getCallApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1}); - - ncApi.getPeersForCall( - credentials, - ApiUtils.getUrlForCall( - apiVersion, - baseUrl, - roomToken)) - .subscribeOn(Schedulers.io()) - .subscribe(new Observer() { - @Override - public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) { - // unused atm - } - - @Override - public void onNext(@io.reactivex.annotations.NonNull ParticipantsOverall participantsOverall) { - participantMap = new HashMap<>(); - for (Participant participant : participantsOverall.getOcs().getData()) { - participantMap.put(participant.getSessionId(), participant); - } - } - - @Override - public void onError(@io.reactivex.annotations.NonNull Throwable e) { - Log.e(TAG, "error while executing getPeersForCall", e); - } - - @Override - public void onComplete() { - // unused atm - } - }); - } - private void deletePeerConnection(PeerConnectionWrapper peerConnectionWrapper) { peerConnectionWrapper.removePeerConnection(); peerConnectionWrapperList.remove(peerConnectionWrapper); @@ -2291,12 +2249,7 @@ public class CallActivity extends CallBaseActivity { nick = offerAnswerNickProviders.get(session) != null ? offerAnswerNickProviders.get(session).getNick() : ""; } - String userId = null; - 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 userId = userIdsBySessionId.get(session); String defaultGuestNick = getResources().getString(R.string.nc_nick_guest); diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java index 49df4b00e..da98e27f3 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java +++ b/app/src/main/java/com/nextcloud/talk/webrtc/MagicWebSocketInstance.java @@ -386,17 +386,6 @@ public class MagicWebSocketInstance extends WebSocketListener { return ""; } - public String getUserIdForSession(String session) { - Participant participant = usersHashMap.get(session); - if (participant != null) { - if (participant.getCalculatedActorType() == USERS) { - return participant.getCalculatedActorId(); - } - } - - return ""; - } - @Subscribe(threadMode = ThreadMode.BACKGROUND) public void onMessageEvent(NetworkEvent networkEvent) { if (networkEvent.getNetworkConnectionEvent() == NetworkEvent.NetworkConnectionEvent.NETWORK_CONNECTED && !isConnected()) {