From 33a962b72155cc433c9e2fc498b2b66d07cf8df4 Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Fri, 4 Sep 2020 17:55:29 +0300 Subject: [PATCH 1/3] Start sync when receive m.call.invite. --- CHANGES.md | 1 + .../im/vector/app/features/call/WebRtcPeerConnectionManager.kt | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index f5a0d5dbb1..f276d12497 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -17,6 +17,7 @@ Improvements 🙌: Bugfix 🐛: - Messages encrypted with no way to decrypt after SDK update from 0.18 to 1.0.0 (#2252) + - Incoming call continues to ring if call is answered on another device (#1921) Translations 🗣: - diff --git a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt index c70b52b09b..9f3e4cb910 100644 --- a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt @@ -702,6 +702,8 @@ class WebRtcPeerConnectionManager @Inject constructor( ) callContext.offerSdp = callInviteContent.offer + + currentSession?.startSync(true) } private fun createAnswer() { From 1de1ddd49631e1cc6dbf499d5c6bd17eb6be4314 Mon Sep 17 00:00:00 2001 From: Valere Date: Fri, 30 Oct 2020 11:52:59 +0100 Subject: [PATCH 2/3] Fix / bg sync for received by other session + dismiss full screen intent --- .../java/im/vector/app/VectorApplication.kt | 3 ++ .../app/features/call/VectorCallViewModel.kt | 5 +++ .../call/WebRtcPeerConnectionManager.kt | 44 +++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/VectorApplication.kt b/vector/src/main/java/im/vector/app/VectorApplication.kt index 4f89763cda..5be313d719 100644 --- a/vector/src/main/java/im/vector/app/VectorApplication.kt +++ b/vector/src/main/java/im/vector/app/VectorApplication.kt @@ -42,6 +42,7 @@ import im.vector.app.core.di.HasVectorInjector import im.vector.app.core.di.VectorComponent import im.vector.app.core.extensions.configureAndStart import im.vector.app.core.rx.RxConfig +import im.vector.app.features.call.WebRtcPeerConnectionManager import im.vector.app.features.configuration.VectorConfiguration import im.vector.app.features.disclaimer.doNotShowDisclaimerDialog import im.vector.app.features.lifecycle.VectorActivityLifecycleCallbacks @@ -89,6 +90,7 @@ class VectorApplication : @Inject lateinit var rxConfig: RxConfig @Inject lateinit var popupAlertManager: PopupAlertManager @Inject lateinit var pinLocker: PinLocker + @Inject lateinit var webRtcPeerConnectionManager: WebRtcPeerConnectionManager lateinit var vectorComponent: VectorComponent @@ -173,6 +175,7 @@ class VectorApplication : }) ProcessLifecycleOwner.get().lifecycle.addObserver(appStateHandler) ProcessLifecycleOwner.get().lifecycle.addObserver(pinLocker) + ProcessLifecycleOwner.get().lifecycle.addObserver(webRtcPeerConnectionManager) // This should be done as early as possible // initKnownEmojiHashSet(appContext) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index edb75441c8..445f40e5b1 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -88,6 +88,11 @@ class VectorCallViewModel @AssistedInject constructor( private val currentCallListener = object : WebRtcPeerConnectionManager.CurrentCallListener { override fun onCurrentCallChange(call: MxCall?) { + // we need to check the state + if (call == null) { + // we should dismiss, e.g handled by other session? + _viewEvents.post(VectorCallViewEvents.DismissNoCall) + } } override fun onCaptureStateChanged() { diff --git a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt index 9f3e4cb910..0b844f36d3 100644 --- a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt @@ -18,11 +18,16 @@ package im.vector.app.features.call import android.content.Context import android.hardware.camera2.CameraManager +import android.os.SystemClock import androidx.core.content.getSystemService +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.LifecycleObserver +import androidx.lifecycle.OnLifecycleEvent import im.vector.app.ActiveSessionDataSource import im.vector.app.core.services.BluetoothHeadsetReceiver import im.vector.app.core.services.CallService import im.vector.app.core.services.WiredHeadsetStateReceiver +import im.vector.app.push.fcm.FcmHelper import io.reactivex.disposables.Disposable import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.ReplaySubject @@ -71,8 +76,8 @@ import javax.inject.Singleton @Singleton class WebRtcPeerConnectionManager @Inject constructor( private val context: Context, - private val activeSessionDataSource: ActiveSessionDataSource -) : CallsListener { + private val activeSessionDataSource: ActiveSessionDataSource, +) : CallsListener, LifecycleObserver { private val currentSession: Session? get() = activeSessionDataSource.currentValue?.orNull() @@ -170,6 +175,8 @@ class WebRtcPeerConnectionManager @Inject constructor( private var currentCaptureMode: CaptureFormat = CaptureFormat.HD + private var isInBackground: Boolean = true + var capturerIsInError = false set(value) { field = value @@ -201,6 +208,17 @@ class WebRtcPeerConnectionManager @Inject constructor( } } + @OnLifecycleEvent(Lifecycle.Event.ON_RESUME) + fun entersForeground() { + isInBackground = false + } + + @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE) + fun entersBackground() { + isInBackground = true + } + + var currentCall: CallContext? = null set(value) { field = value @@ -703,7 +721,17 @@ class WebRtcPeerConnectionManager @Inject constructor( callContext.offerSdp = callInviteContent.offer - currentSession?.startSync(true) + // If this is received while in background, the app will not sync, + // and thus won't be able to received events. For example if the call is + // accepted on an other session this device will continue ringing + if (isInBackground) { + if (FcmHelper.isPushSupported()) { + // only for push version as fdroid version is already doing it? + currentSession?.startAutomaticBackgroundSync(30, 0) + } else { + // Maybe increase sync freq? but how to set back to default values? + } + } } private fun createAnswer() { @@ -851,6 +879,16 @@ class WebRtcPeerConnectionManager @Inject constructor( Timber.v("## VOIP onCallManagedByOtherSession: $callId") currentCall = null CallService.onNoActiveCall(context) + + // did we start background sync? so we should stop it + if (isInBackground) { + if (FcmHelper.isPushSupported()) { + currentSession?.stopAnyBackgroundSync() + } else { + // for fdroid we should not stop, it should continue syncing + // maybe we should restore default timeout/delay though? + } + } } private inner class StreamObserver(val callContext: CallContext) : PeerConnection.Observer { From 9ff78051a913ab9689e734ee1622365087b3512e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 2 Nov 2020 14:15:27 +0100 Subject: [PATCH 3/3] Cleanup --- .../vector/app/features/call/WebRtcPeerConnectionManager.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt index 0b844f36d3..86b38c1158 100644 --- a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt @@ -18,7 +18,6 @@ package im.vector.app.features.call import android.content.Context import android.hardware.camera2.CameraManager -import android.os.SystemClock import androidx.core.content.getSystemService import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleObserver @@ -76,7 +75,7 @@ import javax.inject.Singleton @Singleton class WebRtcPeerConnectionManager @Inject constructor( private val context: Context, - private val activeSessionDataSource: ActiveSessionDataSource, + private val activeSessionDataSource: ActiveSessionDataSource ) : CallsListener, LifecycleObserver { private val currentSession: Session? @@ -218,7 +217,6 @@ class WebRtcPeerConnectionManager @Inject constructor( isInBackground = true } - var currentCall: CallContext? = null set(value) { field = value