Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start sync when receive m.call.invite. #2058

Merged
merged 4 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Improvements 🙌:
Bugfix 🐛:
- Fixed ringtone handling (#2100 & #2246)
- 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)
- Search Result | scroll jumps after pagination (#2238)

Translations 🗣:
Expand Down
3 changes: 3 additions & 0 deletions vector/src/main/java/im/vector/app/VectorApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ package im.vector.app.features.call
import android.content.Context
import android.hardware.camera2.CameraManager
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
Expand Down Expand Up @@ -72,7 +76,7 @@ import javax.inject.Singleton
class WebRtcPeerConnectionManager @Inject constructor(
private val context: Context,
private val activeSessionDataSource: ActiveSessionDataSource
) : CallsListener {
) : CallsListener, LifecycleObserver {

private val currentSession: Session?
get() = activeSessionDataSource.currentValue?.orNull()
Expand Down Expand Up @@ -170,6 +174,8 @@ class WebRtcPeerConnectionManager @Inject constructor(

private var currentCaptureMode: CaptureFormat = CaptureFormat.HD

private var isInBackground: Boolean = true

var capturerIsInError = false
set(value) {
field = value
Expand Down Expand Up @@ -201,6 +207,16 @@ 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
Expand Down Expand Up @@ -702,6 +718,18 @@ class WebRtcPeerConnectionManager @Inject constructor(
)

callContext.offerSdp = callInviteContent.offer

// 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() {
Expand Down Expand Up @@ -849,6 +877,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 {
Expand Down