diff --git a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt index 58e5559b6f..ee133e640c 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/events/WebRtcViewModel.kt @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.events import com.annimon.stream.OptionalLong import org.thoughtcrime.securesms.components.webrtc.BroadcastVideoSink -import org.thoughtcrime.securesms.events.CallParticipant.Companion.HAND_LOWERED import org.thoughtcrime.securesms.events.CallParticipant.Companion.createLocal import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.recipients.RecipientId @@ -113,11 +112,11 @@ class WebRtcViewModel(state: WebRtcServiceState) { val availableDevices: Set = state.localDeviceState.availableDevices val bluetoothPermissionDenied: Boolean = state.localDeviceState.bluetoothPermissionDenied - val localParticipant: CallParticipant = state.callInfoState.localParticipant ?: createLocal( + val localParticipant: CallParticipant = createLocal( state.localDeviceState.cameraState, (if (state.videoState.localSink != null) state.videoState.localSink else BroadcastVideoSink())!!, state.localDeviceState.isMicrophoneEnabled, - HAND_LOWERED + state.localDeviceState.handRaisedTimestamp ) val isCellularConnection: Boolean = when (state.localDeviceState.networkConnectionType) { 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 f91451d7cb..773f4243d4 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 @@ -260,10 +260,10 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor { protected @NonNull WebRtcServiceState handleGroupCallRaisedHand(@NonNull WebRtcServiceState currentState, List raisedHands) { Log.i(TAG, "handleGroupCallRaisedHand():"); - boolean playSound = !raisedHands.isEmpty(); - long now = System.currentTimeMillis(); - WebRtcServiceStateBuilder.CallInfoStateBuilder builder = currentState.builder().changeCallInfoState(); - Long localDemuxId = currentState.getCallInfoState().requireGroupCall().getLocalDeviceState().getDemuxId(); + boolean playSound = !raisedHands.isEmpty(); + long now = System.currentTimeMillis(); + WebRtcServiceStateBuilder.CallInfoStateBuilder callInfoBuilder = currentState.builder().changeCallInfoState(); + Long localDemuxId = currentState.getCallInfoState().requireGroupCall().getLocalDeviceState().getDemuxId(); List participants = currentState.getCallInfoState().getRemoteCallParticipants(); @@ -276,31 +276,25 @@ public class GroupConnectedActionProcessor extends GroupActionProcessor { } if (raisedHandIndex >= 0 && !wasHandAlreadyRaised) { - builder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(now + raisedHandIndex)); + callInfoBuilder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(now + raisedHandIndex)); } else if (raisedHandIndex < 0 && wasHandAlreadyRaised) { - builder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(CallParticipant.HAND_LOWERED)); + callInfoBuilder.putParticipant(updatedParticipant.getCallParticipantId(), updatedParticipant.withHandRaisedTimestamp(CallParticipant.HAND_LOWERED)); } } + currentState = callInfoBuilder.build(); + if (localDemuxId != null) { - if (raisedHands.contains(localDemuxId)) { - builder.setLocalParticipant(CallParticipant.createLocal(currentState.getLocalDeviceState().getCameraState(), - currentState.getVideoState().requireLocalSink(), - currentState.getLocalDeviceState().isMicrophoneEnabled(), - now, - new CallParticipantId(localDemuxId, Recipient.self().getId()))); - } else { - builder.setLocalParticipant(CallParticipant.createLocal(currentState.getLocalDeviceState().getCameraState(), - currentState.getVideoState().requireLocalSink(), - currentState.getLocalDeviceState().isMicrophoneEnabled(), - CallParticipant.HAND_LOWERED, - new CallParticipantId(localDemuxId, Recipient.self().getId()))); - } + currentState = currentState.builder() + .changeLocalDeviceState() + .setHandRaisedTimestamp(raisedHands.contains(localDemuxId) ? now : CallParticipant.HAND_LOWERED) + .build(); } + if (playSound) { webRtcInteractor.playStateChangeUp(); } - return builder.build(); + return currentState; } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.kt b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.kt index 81a8be220e..511aa45993 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/CallInfoState.kt @@ -22,7 +22,6 @@ data class CallInfoState( var callRecipient: Recipient = Recipient.UNKNOWN, var callConnectedTime: Long = -1, @get:JvmName("getRemoteCallParticipantsMap") var remoteParticipants: MutableMap = mutableMapOf(), - var localParticipant: CallParticipant? = null, var peerMap: MutableMap = mutableMapOf(), var activePeer: RemotePeer? = null, var groupCall: GroupCall? = null, diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/LocalDeviceState.kt b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/LocalDeviceState.kt index 05300c71f6..82422bd3e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/LocalDeviceState.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/LocalDeviceState.kt @@ -1,6 +1,7 @@ package org.thoughtcrime.securesms.service.webrtc.state import org.thoughtcrime.securesms.components.sensors.Orientation +import org.thoughtcrime.securesms.events.CallParticipant import org.thoughtcrime.securesms.ringrtc.CameraState import org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager import org.webrtc.PeerConnection @@ -8,7 +9,7 @@ import org.webrtc.PeerConnection /** * Local device specific state. */ -data class LocalDeviceState constructor( +data class LocalDeviceState( var cameraState: CameraState = CameraState.UNKNOWN, var isMicrophoneEnabled: Boolean = true, var orientation: Orientation = Orientation.PORTRAIT_BOTTOM_EDGE, @@ -17,7 +18,8 @@ data class LocalDeviceState constructor( var activeDevice: SignalAudioManager.AudioDevice = SignalAudioManager.AudioDevice.NONE, var availableDevices: Set = emptySet(), var bluetoothPermissionDenied: Boolean = false, - var networkConnectionType: PeerConnection.AdapterType = PeerConnection.AdapterType.UNKNOWN + var networkConnectionType: PeerConnection.AdapterType = PeerConnection.AdapterType.UNKNOWN, + var handRaisedTimestamp: Long = CallParticipant.HAND_LOWERED ) { fun duplicate(): LocalDeviceState { diff --git a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java index 714e6c05b6..773c21fed6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java +++ b/app/src/main/java/org/thoughtcrime/securesms/service/webrtc/state/WebRtcServiceStateBuilder.java @@ -137,6 +137,11 @@ public class WebRtcServiceStateBuilder { toBuild.setNetworkConnectionType(type); return this; } + + public @NonNull LocalDeviceStateBuilder setHandRaisedTimestamp(long handRaisedTimestamp) { + toBuild.setHandRaisedTimestamp(handRaisedTimestamp); + return this; + } } public class CallSetupStateBuilder { @@ -364,10 +369,5 @@ public class WebRtcServiceStateBuilder { toBuild.setCallLinkDisconnectReason(callLinkDisconnectReason); return this; } - - public @NonNull CallInfoStateBuilder setLocalParticipant(@NonNull CallParticipant callParticipant) { - toBuild.setLocalParticipant(callParticipant); - return this; - } } }