diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ActiveCallActionProcessorDelegate.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ActiveCallActionProcessorDelegate.java index e42bcec55a..7027f3a3b3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ActiveCallActionProcessorDelegate.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ActiveCallActionProcessorDelegate.java @@ -86,7 +86,7 @@ public class ActiveCallActionProcessorDelegate extends WebRtcActionProcessor { .build(); if (currentState.getCallInfoState().getCallState() == WebRtcViewModel.State.CALL_CONNECTED) { - boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled(); + boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled() || currentState.getLocalDeviceState().isScreenSharing(); webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, localVideoEnabled, enable)); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ConnectedCallActionProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ConnectedCallActionProcessor.java index 8c0ea0aa24..4c59001b39 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ConnectedCallActionProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/ConnectedCallActionProcessor.java @@ -58,7 +58,7 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor { .cameraState(currentState.getVideoState().requireRouter().getCameraState()) .build(); - boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled(); + boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled() || currentState.getLocalDeviceState().isScreenSharing(); boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, localVideoEnabled, remoteVideoEnabled)); @@ -155,11 +155,16 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor { return callFailure(currentState, "setVideoEnable() after screen share failed: ", e); } - return currentState.builder() - .changeLocalDeviceState() - .isScreenSharing(false) - .setMediaProjectionIntent(null) - .build(); + currentState = currentState.builder() + .changeLocalDeviceState() + .isScreenSharing(false) + .setMediaProjectionIntent(null) + .build(); + + boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); + webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, cameraWasEnabled, remoteVideoEnabled)); + + return currentState; } } @@ -189,10 +194,16 @@ public class ConnectedCallActionProcessor extends DeviceAwareActionProcessor { } router.startScreenShare(mediaProjectionIntent); - return currentState.builder() - .changeLocalDeviceState() - .isScreenSharing(true) - .build(); + currentState = currentState.builder() + .changeLocalDeviceState() + .isScreenSharing(true) + .build(); + + boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); + webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, true, remoteVideoEnabled)); + WebRtcUtil.enableSpeakerPhoneIfNeeded(webRtcInteractor, currentState); + + return currentState; } @Override diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/DeviceAwareActionProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/DeviceAwareActionProcessor.java index 418d866817..7afaa0d7fa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/DeviceAwareActionProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/DeviceAwareActionProcessor.java @@ -29,7 +29,7 @@ public abstract class DeviceAwareActionProcessor extends WebRtcActionProcessor { Log.i(tag, "handleAudioDeviceChanged(): active: " + activeDevice + " available: " + availableDevices); if (currentState.getCallInfoState().getCallState() == WebRtcViewModel.State.CALL_CONNECTED) { - boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled(); + boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled() || currentState.getLocalDeviceState().isScreenSharing(); boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, localVideoEnabled, remoteVideoEnabled)); } else { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/GroupConnectedActionProcessor.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/GroupConnectedActionProcessor.java index 2de305e98d..e9a72f4dc8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/GroupConnectedActionProcessor.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/GroupConnectedActionProcessor.java @@ -105,7 +105,7 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor { .cameraState(router.getCameraState()) .build(); - boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled(); + boolean localVideoEnabled = currentState.getLocalDeviceState().getCameraState().isEnabled() || currentState.getLocalDeviceState().isScreenSharing(); boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, localVideoEnabled, remoteVideoEnabled)); @@ -144,11 +144,16 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor { return groupCallFailure(currentState, "Unable to restore video mute after screen share", e); } - return currentState.builder() - .changeLocalDeviceState() - .isScreenSharing(false) - .setMediaProjectionIntent(null) - .build(); + currentState = currentState.builder() + .changeLocalDeviceState() + .isScreenSharing(false) + .setMediaProjectionIntent(null) + .build(); + + boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); + webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, cameraWasEnabled, remoteVideoEnabled)); + + return currentState; } } @@ -180,10 +185,16 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor { } router.startScreenShare(mediaProjectionIntent); - return currentState.builder() - .changeLocalDeviceState() - .isScreenSharing(true) - .build(); + currentState = currentState.builder() + .changeLocalDeviceState() + .isScreenSharing(true) + .build(); + + boolean remoteVideoEnabled = currentState.getCallInfoState().getRemoteCallParticipantsMap().values().stream().anyMatch(CallParticipant::isVideoEnabled); + webRtcInteractor.updatePhoneState(WebRtcUtil.getInCallPhoneState(context, true, remoteVideoEnabled)); + WebRtcUtil.enableSpeakerPhoneIfNeeded(webRtcInteractor, currentState); + + return currentState; } @Override diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcUtil.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcUtil.java index fb10fd9b0a..342bbcabb3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/WebRtcUtil.java @@ -86,7 +86,7 @@ public final class WebRtcUtil { } public static void enableSpeakerPhoneIfNeeded(@NonNull WebRtcInteractor webRtcInteractor, WebRtcServiceState currentState) { - if (!currentState.getLocalDeviceState().getCameraState().isEnabled()) { + if (!currentState.getLocalDeviceState().getCameraState().isEnabled() && !currentState.getLocalDeviceState().isScreenSharing()) { return; }