From 339d65dff87dc173cc5b0800140a353ba5181c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Thu, 24 Nov 2022 12:15:10 +0100 Subject: [PATCH] Handle the raw ICE connection state in the views MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rather than just providing a coarse "connected" or "not connected" value now the views receive the raw ICE connection state. Combined with other properties this will make possible to show a finer grained status (like done in the WebUI), although for now just "connected" or "not connected" is still shown as before. Signed-off-by: Daniel Calviño Sánchez --- .../talk/activities/CallActivity.java | 55 ++++--------------- .../talk/adapters/ParticipantDisplayItem.java | 14 +++-- 2 files changed, 20 insertions(+), 49 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 81c1030d2..abff92925 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java @@ -2072,7 +2072,10 @@ public class CallActivity extends CallBaseActivity { updateSelfVideoViewPosition(); } - private void updateSelfVideoViewConnected(boolean connected) { + private void updateSelfVideoViewIceConnectionState(PeerConnection.IceConnectionState iceConnectionState) { + boolean connected = iceConnectionState == PeerConnection.IceConnectionState.CONNECTED || + iceConnectionState == PeerConnection.IceConnectionState.COMPLETED; + // FIXME In voice only calls there is no video view, so the progress bar would appear floating in the middle of // nowhere. However, a way to signal that the local participant is not connected to the HPB is still need in // that case. @@ -2133,28 +2136,6 @@ public class CallActivity extends CallBaseActivity { } } - private void handlePeerConnected(String sessionId, String videoStreamType) { - String participantDisplayItemId = sessionId + "-" + videoStreamType; - - if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) { - updateSelfVideoViewConnected(true); - } else if (participantDisplayItems.get(participantDisplayItemId) != null) { - participantDisplayItems.get(participantDisplayItemId).setConnected(true); - participantsAdapter.notifyDataSetChanged(); - } - } - - private void handlePeerDisconnected(String sessionId, String videoStreamType) { - String participantDisplayItemId = sessionId + "-" + videoStreamType; - - if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) { - updateSelfVideoViewConnected(false); - } else if (participantDisplayItems.get(participantDisplayItemId) != null) { - participantDisplayItems.get(participantDisplayItemId).setConnected(false); - participantsAdapter.notifyDataSetChanged(); - } - } - private void startSendingNick() { DataChannelMessage dataChannelMessage = new DataChannelMessage(); dataChannelMessage.setType("nickChanged"); @@ -2211,11 +2192,9 @@ public class CallActivity extends CallBaseActivity { PeerConnectionWrapper peerConnectionWrapper = getPeerConnectionWrapperForSessionIdAndType(session, videoStreamType); - boolean connected = false; + PeerConnection.IceConnectionState iceConnectionState = null; if (peerConnectionWrapper != null) { - PeerConnection.IceConnectionState iceConnectionState = peerConnectionWrapper.getPeerConnection().iceConnectionState(); - connected = iceConnectionState == PeerConnection.IceConnectionState.CONNECTED || - iceConnectionState == PeerConnection.IceConnectionState.COMPLETED; + iceConnectionState = peerConnectionWrapper.getPeerConnection().iceConnectionState(); } String nick; @@ -2232,7 +2211,7 @@ public class CallActivity extends CallBaseActivity { ParticipantDisplayItem participantDisplayItem = new ParticipantDisplayItem(baseUrl, userId, session, - connected, + iceConnectionState, nick, defaultGuestNick, mediaStream, @@ -2692,19 +2671,11 @@ public class CallActivity extends CallBaseActivity { @Override public void onIceConnectionStateChanged(PeerConnection.IceConnectionState iceConnectionState) { runOnUiThread(() -> { - if (iceConnectionState == PeerConnection.IceConnectionState.CONNECTED || - iceConnectionState == PeerConnection.IceConnectionState.COMPLETED) { - handlePeerConnected(sessionId, videoStreamType); - - return; - } - - if (iceConnectionState == PeerConnection.IceConnectionState.DISCONNECTED || - iceConnectionState == PeerConnection.IceConnectionState.NEW || - iceConnectionState == PeerConnection.IceConnectionState.CHECKING) { - handlePeerDisconnected(sessionId, videoStreamType); - - return; + if (webSocketClient != null && webSocketClient.getSessionId() != null && webSocketClient.getSessionId().equals(sessionId)) { + updateSelfVideoViewIceConnectionState(iceConnectionState); + } else if (participantDisplayItems.get(participantDisplayItemId) != null) { + participantDisplayItems.get(participantDisplayItemId).setIceConnectionState(iceConnectionState); + participantsAdapter.notifyDataSetChanged(); } if (iceConnectionState == PeerConnection.IceConnectionState.CLOSED) { @@ -2718,8 +2689,6 @@ public class CallActivity extends CallBaseActivity { setCallState(CallStatus.PUBLISHER_FAILED); webSocketClient.clearResumeId(); hangup(false); - } else { - handlePeerDisconnected(sessionId, videoStreamType); } return; diff --git a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java index 34fa963ac..63a0d3ef5 100644 --- a/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java +++ b/app/src/main/java/com/nextcloud/talk/adapters/ParticipantDisplayItem.java @@ -6,12 +6,13 @@ import com.nextcloud.talk.utils.ApiUtils; import org.webrtc.EglBase; import org.webrtc.MediaStream; +import org.webrtc.PeerConnection; public class ParticipantDisplayItem { private String baseUrl; private String userId; private String session; - private boolean connected; + private PeerConnection.IceConnectionState iceConnectionState; private String nick; private final String defaultGuestNick; private String urlForAvatar; @@ -21,11 +22,11 @@ public class ParticipantDisplayItem { private EglBase rootEglBase; private boolean isAudioEnabled; - public ParticipantDisplayItem(String baseUrl, String userId, String session, boolean connected, String nick, String defaultGuestNick, MediaStream mediaStream, String streamType, boolean streamEnabled, EglBase rootEglBase) { + public ParticipantDisplayItem(String baseUrl, String userId, String session, PeerConnection.IceConnectionState iceConnectionState, String nick, String defaultGuestNick, MediaStream mediaStream, String streamType, boolean streamEnabled, EglBase rootEglBase) { this.baseUrl = baseUrl; this.userId = userId; this.session = session; - this.connected = connected; + this.iceConnectionState = iceConnectionState; this.nick = nick; this.defaultGuestNick = defaultGuestNick; this.mediaStream = mediaStream; @@ -55,11 +56,12 @@ public class ParticipantDisplayItem { } public boolean isConnected() { - return connected; + return iceConnectionState == PeerConnection.IceConnectionState.CONNECTED || + iceConnectionState == PeerConnection.IceConnectionState.COMPLETED; } - public void setConnected(boolean connected) { - this.connected = connected; + public void setIceConnectionState(PeerConnection.IceConnectionState iceConnectionState) { + this.iceConnectionState = iceConnectionState; } public String getNick() {