From e5e566ab713be655ef2695f4cb12850f28475f11 Mon Sep 17 00:00:00 2001 From: sim Date: Mon, 3 Apr 2023 12:49:34 +0200 Subject: [PATCH] Start buffered response check onOpen --- .../distributor/nextpush/api/Api.kt | 1 - .../distributor/nextpush/api/SSEListener.kt | 21 +++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt index f550cbd..1cd979f 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/api/Api.kt @@ -91,7 +91,6 @@ class Api(val context: Context) { .get() .build() - SSEListener.starting(context) syncSource = EventSources.createFactory(client).newEventSource(request, SSEListener(context)) Log.d(TAG, "cSync done.") } 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 46a43d4..6903df3 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 @@ -27,7 +27,10 @@ class SSEListener(val context: Context) : EventSourceListener() { override fun onOpen(eventSource: EventSource, response: Response) { FailureHandler.newEventSource(context, eventSource) - startingTimer?.cancel() + startingTimer = Timer().schedule(30_000L /* 30secs */) { + StartService.stopService() + showStartErrorNotification(context) + } StartService.wakeLock?.let { while (it.isHeld) { it.release() @@ -46,7 +49,10 @@ class SSEListener(val context: Context) : EventSourceListener() { lastEventDate = Calendar.getInstance() when (type) { - "start" -> started = true + "start" -> { + started = true + startingTimer?.cancel() + } "ping" -> { pinged = true FailureHandler.newPing() @@ -143,16 +149,5 @@ class SSEListener(val context: Context) : EventSourceListener() { private set var started = false private set - - fun starting(context: Context) { - // The request timeout after 10seconds - // If it doesn't, and onOpen hasn't been called, then - // the response is very probably buffered. - // +20secs for a margin - startingTimer = Timer().schedule(30_000L /* 30secs */) { - StartService.stopService() - showStartErrorNotification(context) - } - } } }