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

View file

@ -62,6 +62,7 @@ sealed class VectorCallViewActions : VectorViewModelAction {
object ToggleVideo : VectorCallViewActions()
data class ChangeAudioDevice(val device: CallAudioManager.SoundDevice) : VectorCallViewActions()
object SwitchSoundDevice : VectorCallViewActions()
object HeadSetButtonPressed: VectorCallViewActions()
}
sealed class VectorCallViewEvents : VectorViewEvents {
@ -224,6 +225,17 @@ class VectorCallViewModel @AssistedInject constructor(
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
}