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() .get()
.build() .build()
SSEListener.starting(context)
syncSource = EventSources.createFactory(client).newEventSource(request, SSEListener(context)) syncSource = EventSources.createFactory(client).newEventSource(request, SSEListener(context))
Log.d(TAG, "cSync done.") Log.d(TAG, "cSync done.")
} }

View File

@ -27,7 +27,10 @@ class SSEListener(val context: Context) : EventSourceListener() {
override fun onOpen(eventSource: EventSource, response: Response) { override fun onOpen(eventSource: EventSource, response: Response) {
FailureHandler.newEventSource(context, eventSource) FailureHandler.newEventSource(context, eventSource)
startingTimer?.cancel() startingTimer = Timer().schedule(30_000L /* 30secs */) {
StartService.stopService()
showStartErrorNotification(context)
}
StartService.wakeLock?.let { StartService.wakeLock?.let {
while (it.isHeld) { while (it.isHeld) {
it.release() it.release()
@ -46,7 +49,10 @@ class SSEListener(val context: Context) : EventSourceListener() {
lastEventDate = Calendar.getInstance() lastEventDate = Calendar.getInstance()
when (type) { when (type) {
"start" -> started = true "start" -> {
started = true
startingTimer?.cancel()
}
"ping" -> { "ping" -> {
pinged = true pinged = true
FailureHandler.newPing() FailureHandler.newPing()
@ -143,16 +149,5 @@ class SSEListener(val context: Context) : EventSourceListener() {
private set private set
var started = false var started = false
private set 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)
}
}
} }
} }