diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index 26fd91c2c..213587f8c 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -128,6 +128,8 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C } } + private var previousCallState = Call.State.Idle + private val coreListener = object : CoreListenerStub() { @WorkerThread override fun onGlobalStateChanged(core: Core, state: GlobalState, message: String) { @@ -176,8 +178,11 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C state: Call.State?, message: String ) { - Log.i("$TAG Call [${call.remoteAddress.asStringUriOnly()}] state changed [$state]") - when (state) { + val currentState = call.state + Log.i( + "$TAG Call [${call.remoteAddress.asStringUriOnly()}] state changed [$currentState]" + ) + when (currentState) { Call.State.OutgoingInit -> { val conferenceInfo = core.findConferenceInformationFromUri(call.remoteAddress) // Do not show outgoing call view for conference calls, wait for connected state @@ -196,6 +201,16 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C showCallActivity() } } + Call.State.StreamsRunning -> { + if (previousCallState == Call.State.Connected) { + if (corePreferences.automaticallyStartCallRecording && !call.params.isRecording) { + if (call.conference == null) { // TODO: FIXME: Conference recordings are currently disabled + Log.i("$TAG Auto record calls is enabled, starting it now") + call.startRecording() + } + } + } + } Call.State.Error -> { val errorInfo = call.errorInfo Log.w( @@ -209,6 +224,8 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C else -> { } } + + previousCallState = currentState } @WorkerThread diff --git a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt index 3f7ad3cd9..d32485047 100644 --- a/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt +++ b/app/src/main/java/org/linphone/ui/call/viewmodel/CurrentCallViewModel.kt @@ -313,6 +313,10 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { } else { conferenceModel.destroy() } + } else if (call.state == Call.State.StreamsRunning) { + if (corePreferences.automaticallyStartCallRecording) { + isRecording.postValue(call.params.isRecording) + } } } @@ -1103,9 +1107,12 @@ class CurrentCallViewModel @UiThread constructor() : GenericViewModel() { displayedName.postValue(model.friend.name) isRecording.postValue(call.params.isRecording) - isRemoteRecordingEvent.postValue( - Event(Pair(call.remoteParams?.isRecording ?: false, displayedName.value.orEmpty())) - ) + + val isRemoteRecording = call.remoteParams?.isRecording ?: false + if (isRemoteRecording) { + Log.w("$TAG Remote end [${displayedName.value.orEmpty()}] is recording the call") + isRemoteRecordingEvent.postValue(Event(Pair(true, displayedName.value.orEmpty()))) + } callDuration.postValue(call.duration) }