Start buffered response check onOpen

This commit is contained in:
sim 2023-04-03 12:49:34 +02:00
parent 8727c11837
commit e5e566ab71
2 changed files with 8 additions and 14 deletions

View File

@ -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.")
}

View File

@ -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)
}
}
}
}