diff --git a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt index 394282e551..d1d446f1d9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/calls/WebRtcCallActivity.kt @@ -18,7 +18,9 @@ import dagger.hilt.android.AndroidEntryPoint import kotlinx.android.synthetic.main.activity_conversation_v2.* import kotlinx.android.synthetic.main.activity_webrtc.* import kotlinx.coroutines.Job +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import network.loki.messenger.R import org.session.libsession.avatars.ProfileContactPhoto @@ -33,6 +35,7 @@ import org.thoughtcrime.securesms.webrtc.AudioManagerCommand import org.thoughtcrime.securesms.webrtc.CallViewModel import org.thoughtcrime.securesms.webrtc.CallViewModel.State.* import org.thoughtcrime.securesms.webrtc.audio.SignalAudioManager.AudioDevice.* +import java.time.Duration import java.util.* @AndroidEntryPoint @@ -44,6 +47,8 @@ class WebRtcCallActivity: PassphraseRequiredActionBarActivity() { const val ACTION_END = "end-call" const val BUSY_SIGNAL_DELAY_FINISH = 5500L + + val CALL_DURATION_FORMAT = } private val viewModel by viewModels() @@ -186,6 +191,20 @@ class WebRtcCallActivity: PassphraseRequiredActionBarActivity() { } } + launch { + while (isActive) { + val startTime = viewModel.callStartTime + if (startTime == -1L) { + callTime.isVisible = false + } else { + callTime.isVisible = true + callTime.text = Duration.Duration.ofMillis(startTime) + } + + delay(5_000) // update the call duration less frequently + } + } + launch { viewModel.localAudioEnabledState.collect { isEnabled -> // change drawable background to enabled or not diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt index d1264ec21d..738af276d1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallManager.kt @@ -27,6 +27,7 @@ import org.thoughtcrime.securesms.webrtc.locks.LockManager import org.thoughtcrime.securesms.webrtc.video.CameraEventListener import org.thoughtcrime.securesms.webrtc.video.CameraState import org.webrtc.* +import org.webrtc.PeerConnection.IceConnectionState import java.nio.ByteBuffer import java.util.* import java.util.concurrent.Executors @@ -104,8 +105,6 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va val currentConnectionState get() = (_connectionEvents.value as CallStateUpdate).state - private val networkExecutor = Executors.newSingleThreadExecutor() - private var eglBase: EglBase? = null var pendingOffer: String? = null @@ -117,6 +116,7 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va field = value _recipientEvents.value = RecipientUpdate(value) } + var callStartTime: Long = -1 var isReestablishing: Boolean = false private var peerConnection: PeerConnectionWrapper? = null @@ -209,8 +209,11 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va peerConnectionObservers.forEach { listener -> listener.onSignalingChange(newState) } } - override fun onIceConnectionChange(newState: PeerConnection.IceConnectionState) { + override fun onIceConnectionChange(newState: IceConnectionState) { peerConnectionObservers.forEach { listener -> listener.onIceConnectionChange(newState) } + if (newState == IceConnectionState.CONNECTED) { + callStartTime = System.currentTimeMillis() + } } override fun onIceConnectionReceivingChange(receiving: Boolean) { @@ -340,6 +343,9 @@ class CallManager(context: Context, audioManager: AudioManagerCompat, private va localCameraState = CameraState.UNKNOWN recipient = null callId = null + pendingOfferTime = -1 + pendingOffer = null + callStartTime = -1 _audioEvents.value = AudioEnabled(false) _videoEvents.value = VideoEnabled(false) _remoteVideoEvents.value = VideoEnabled(false) diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt index f1265fee40..93667ed92e 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallViewModel.kt @@ -11,6 +11,23 @@ import javax.inject.Inject @HiltViewModel class CallViewModel @Inject constructor(private val callManager: CallManager): ViewModel() { + enum class State { + CALL_PENDING, + + CALL_PRE_INIT, + CALL_INCOMING, + CALL_OUTGOING, + CALL_CONNECTED, + CALL_RINGING, + CALL_BUSY, + CALL_DISCONNECTED, + + NETWORK_FAILURE, + RECIPIENT_UNAVAILABLE, + NO_SUCH_USER, + UNTRUSTED_IDENTITY, + } + val localRenderer: SurfaceViewRenderer? get() = callManager.localRenderer @@ -31,24 +48,6 @@ class CallViewModel @Inject constructor(private val callManager: CallManager): V val isSpeaker: Boolean get() = _isSpeaker - - enum class State { - CALL_PENDING, - - CALL_PRE_INIT, - CALL_INCOMING, - CALL_OUTGOING, - CALL_CONNECTED, - CALL_RINGING, - CALL_BUSY, - CALL_DISCONNECTED, - - NETWORK_FAILURE, - RECIPIENT_UNAVAILABLE, - NO_SUCH_USER, - UNTRUSTED_IDENTITY, - } - val audioDeviceState get() = callManager.audioDeviceEvents .onEach { @@ -73,4 +72,7 @@ class CallViewModel @Inject constructor(private val callManager: CallManager): V val recipient get() = callManager.recipientEvents + val callStartTime: Long + get() = callManager.callStartTime + } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_webrtc.xml b/app/src/main/res/layout/activity_webrtc.xml index f1fcc0ebf4..8197415205 100644 --- a/app/src/main/res/layout/activity_webrtc.xml +++ b/app/src/main/res/layout/activity_webrtc.xml @@ -1,5 +1,6 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index c895f8c4c3..c7a03ad4f1 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -137,8 +137,7 @@