accept/hangup on press on headset button

This commit is contained in:
Valere 2020-06-18 12:19:20 +02:00
parent 3e2d892fb5
commit 9653f082a3
2 changed files with 22 additions and 12 deletions

View file

@ -24,6 +24,7 @@ import android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.view.KeyEvent
import android.view.View import android.view.View
import android.view.Window import android.view.Window
import android.view.WindowManager import android.view.WindowManager
@ -324,18 +325,15 @@ class VectorCallActivity : VectorBaseActivity(), CallControlsView.InteractionLis
intent.getStringExtra(EXTRA_MODE)?.takeIf { isFirstCreation() }) intent.getStringExtra(EXTRA_MODE)?.takeIf { isFirstCreation() })
} }
// override fun onResume() { override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
// super.onResume() when (keyCode) {
// withState(callViewModel) { KeyEvent.KEYCODE_HEADSETHOOK -> {
// if(it.callState.invoke() == CallState.CONNECTED) { callViewModel.handle(VectorCallViewActions.HeadSetButtonPressed)
// peerConnectionManager.attachViewRenderers(pipRenderer, fullscreenRenderer) return true
// } }
// } }
// } return super.onKeyDown(keyCode, event)
// override fun onPause() { }
// peerConnectionManager.detachRenderers()
// super.onPause()
// }
private fun handleViewEvents(event: VectorCallViewEvents?) { private fun handleViewEvents(event: VectorCallViewEvents?) {
Timber.v("## VOIP handleViewEvents $event") Timber.v("## VOIP handleViewEvents $event")

View file

@ -62,6 +62,7 @@ sealed class VectorCallViewActions : VectorViewModelAction {
object ToggleVideo : VectorCallViewActions() object ToggleVideo : VectorCallViewActions()
data class ChangeAudioDevice(val device: CallAudioManager.SoundDevice) : VectorCallViewActions() data class ChangeAudioDevice(val device: CallAudioManager.SoundDevice) : VectorCallViewActions()
object SwitchSoundDevice : VectorCallViewActions() object SwitchSoundDevice : VectorCallViewActions()
object HeadSetButtonPressed: VectorCallViewActions()
} }
sealed class VectorCallViewEvents : VectorViewEvents { sealed class VectorCallViewEvents : VectorViewEvents {
@ -224,6 +225,17 @@ class VectorCallViewModel @AssistedInject constructor(
VectorCallViewEvents.ShowSoundDeviceChooser(state.availableSoundDevices, state.soundDevice) VectorCallViewEvents.ShowSoundDeviceChooser(state.availableSoundDevices, state.soundDevice)
) )
} }
VectorCallViewActions.HeadSetButtonPressed -> {
if (state.callState.invoke() is CallState.LocalRinging) {
// accept call
webRtcPeerConnectionManager.acceptIncomingCall()
}
if (state.callState.invoke() is CallState.Connected) {
// end call?
webRtcPeerConnectionManager.endCall()
}
Unit
}
}.exhaustive }.exhaustive
} }