From 989fabdd333bca3cba160c1555929972c037c9df Mon Sep 17 00:00:00 2001 From: S1m Date: Wed, 24 Nov 2021 20:06:49 +0100 Subject: [PATCH] Restart once SSEListener on Failure --- .../distributor/nextpush/services/SSEListener.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt index d7d1b02..880867b 100644 --- a/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt +++ b/app/src/main/java/org/unifiedpush/distributor/nextpush/services/SSEListener.kt @@ -16,8 +16,11 @@ import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered private const val TAG = "SSEListener" class SSEListener (val context: Context) : EventSourceListener() { + private var failed = false + override fun onOpen(eventSource: EventSource, response: Response) { deleteWarningNotification(context) + failed = false try { Log.d(TAG, "onOpen: " + response.code) } catch (e: Exception) { @@ -59,8 +62,13 @@ class SSEListener (val context: Context) : EventSourceListener() { } override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) { + Log.d(TAG, "onFailure") isServiceStarted = false createWarningNotification(context) + if (!failed) { + failed = true + startListener(context) + } t?.let { Log.d(TAG, "An error occurred: $t") return