diff --git a/app/build.gradle b/app/build.gradle index 484a258..098ee1b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -61,7 +61,7 @@ dependencies { implementation('com.google.android.material:material:1.11.0') implementation("androidx.constraintlayout:constraintlayout:2.1.4") implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0") - implementation('com.squareup.okhttp3:okhttp-sse:4.12.0') + implementation('com.squareup.okhttp3:okhttp-sse:5.0.0.SSEPATCH1-SNAPSHOT') implementation("com.github.nextcloud:Android-SingleSignOn:0.8.1") implementation("com.squareup.retrofit2:retrofit:$retrofitVersion") implementation("com.squareup.retrofit2:converter-gson:$retrofitVersion") diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt index c073512..ca443b9 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/SSEListener.kt @@ -30,6 +30,8 @@ import kotlin.concurrent.schedule class SSEListener(val context: Context) : EventSourceListener() { + override var timeout: Long? = AppCompanion.keepalive.get().toLong() + TIMEOUT_TOLERANCE + override fun onOpen(eventSource: EventSource, response: Response) { FailureHandler.newEventSource(context, eventSource) StartingTimer.scheduleNewTimer(context, eventSource) @@ -63,6 +65,7 @@ class SSEListener(val context: Context) : EventSourceListener() { val message = Gson().fromJson(data, SSEResponse::class.java) message.keepalive.let { AppCompanion.keepalive.set(it) + timeout = it.toLong() + TIMEOUT_TOLERANCE Log.d(TAG, "New keepalive: $it") if (it < 25) { LowKeepAliveNotification(context, it).showSingle() @@ -193,4 +196,8 @@ class SSEListener(val context: Context) : EventSourceListener() { startingTimer.getAndSet(null)?.cancel() } } + + private companion object { + private const val TIMEOUT_TOLERANCE = 5L // 5 seconds + } } diff --git a/build.gradle b/build.gradle index b3ce9c5..dc8a7f1 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,13 @@ allprojects { includeModule 'com.github.nextcloud', 'Android-SingleSignOn' } } + maven { + url "https://codeberg.org/NextPush/maven/raw/branch/main/okhttp-sse/releases/" + content { + includeModule "com.squareup.okhttp3", "okhttp-sse" + } + } + mavenLocal() } apply plugin: "org.jlleitschuh.gradle.ktlint" }