From 0a3f515bb6e1bfd5475177f716b53590577e46db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Mon, 28 Nov 2022 10:01:33 +0100 Subject: [PATCH] Observe only the self peer connection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The observers were created for any peer connection, but after recent changes they ignored all changes but those from the self peer connection. Therefore it is enough to just add an explicit listener on that peer connection rather than on all of them. Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 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 f342be713..df89f8b0b 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -264,7 +264,7 @@ public class CallActivity extends CallBaseActivity { private Map callParticipantMessageListeners = new HashMap<>(); - private Map peerConnectionObservers = new HashMap<>(); + private PeerConnectionWrapper.PeerConnectionObserver selfPeerConnectionObserver = new CallActivitySelfPeerConnectionObserver(); private Map callParticipants = new HashMap<>(); @@ -1970,11 +1970,6 @@ public class CallActivity extends CallBaseActivity { peerConnectionWrapperList.add(peerConnectionWrapper); - PeerConnectionWrapper.PeerConnectionObserver peerConnectionObserver = - new CallActivityPeerConnectionObserver(sessionId); - peerConnectionObservers.put(sessionId + "-" + type, peerConnectionObserver); - peerConnectionWrapper.addObserver(peerConnectionObserver); - if (!publisher) { CallParticipant callParticipant = callParticipants.get(sessionId); if (callParticipant == null) { @@ -2013,6 +2008,8 @@ public class CallActivity extends CallBaseActivity { } if (publisher) { + peerConnectionWrapper.addObserver(selfPeerConnectionObserver); + startSendingNick(); } @@ -2036,11 +2033,12 @@ public class CallActivity extends CallBaseActivity { 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) { - PeerConnectionWrapper.PeerConnectionObserver peerConnectionObserver = peerConnectionObservers.remove(sessionId + "-" + videoStreamType); - peerConnectionWrapper.removeObserver(peerConnectionObserver); - CallParticipant callParticipant = callParticipants.get(sessionId); if (callParticipant != null) { if ("screen".equals(videoStreamType)) { @@ -2563,13 +2561,7 @@ public class CallActivity extends CallBaseActivity { } } - private class CallActivityPeerConnectionObserver implements PeerConnectionWrapper.PeerConnectionObserver { - - private final String sessionId; - - private CallActivityPeerConnectionObserver(String sessionId) { - this.sessionId = sessionId; - } + private class CallActivitySelfPeerConnectionObserver implements PeerConnectionWrapper.PeerConnectionObserver { @Override public void onStreamAdded(MediaStream mediaStream) { @@ -2582,18 +2574,12 @@ public class CallActivity extends CallBaseActivity { @Override public void onIceConnectionStateChanged(PeerConnection.IceConnectionState iceConnectionState) { runOnUiThread(() -> { - if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) { - updateSelfVideoViewIceConnectionState(iceConnectionState); - } + updateSelfVideoViewIceConnectionState(iceConnectionState); if (iceConnectionState == PeerConnection.IceConnectionState.FAILED) { - if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) { - setCallState(CallStatus.PUBLISHER_FAILED); - webSocketClient.clearResumeId(); - hangup(false); - } - - return; + setCallState(CallStatus.PUBLISHER_FAILED); + webSocketClient.clearResumeId(); + hangup(false); } }); }