Restart once SSEListener on Failure
This commit is contained in:
parent
c0022ddd09
commit
989fabdd33
|
@ -16,8 +16,11 @@ import org.unifiedpush.distributor.nextpush.distributor.sendUnregistered
|
||||||
private const val TAG = "SSEListener"
|
private const val TAG = "SSEListener"
|
||||||
|
|
||||||
class SSEListener (val context: Context) : EventSourceListener() {
|
class SSEListener (val context: Context) : EventSourceListener() {
|
||||||
|
private var failed = false
|
||||||
|
|
||||||
override fun onOpen(eventSource: EventSource, response: Response) {
|
override fun onOpen(eventSource: EventSource, response: Response) {
|
||||||
deleteWarningNotification(context)
|
deleteWarningNotification(context)
|
||||||
|
failed = false
|
||||||
try {
|
try {
|
||||||
Log.d(TAG, "onOpen: " + response.code)
|
Log.d(TAG, "onOpen: " + response.code)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -59,8 +62,13 @@ class SSEListener (val context: Context) : EventSourceListener() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {
|
override fun onFailure(eventSource: EventSource, t: Throwable?, response: Response?) {
|
||||||
|
Log.d(TAG, "onFailure")
|
||||||
isServiceStarted = false
|
isServiceStarted = false
|
||||||
createWarningNotification(context)
|
createWarningNotification(context)
|
||||||
|
if (!failed) {
|
||||||
|
failed = true
|
||||||
|
startListener(context)
|
||||||
|
}
|
||||||
t?.let {
|
t?.let {
|
||||||
Log.d(TAG, "An error occurred: $t")
|
Log.d(TAG, "An error occurred: $t")
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue