[Android] Add a 3 second timeout to the long polling to avoid blocking other queries
Nicolas Pomepuy
git at videolan.org
Tue Aug 13 16:56:02 UTC 2024
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Aug 13 14:43:56 2024 +0200| [eb0bdbbe7c84311688987a91740a9602ea8d9563] | committer: Duncan McNamara
Add a 3 second timeout to the long polling to avoid blocking other queries
> https://code.videolan.org/videolan/vlc-android/commit/eb0bdbbe7c84311688987a91740a9602ea8d9563
---
.../src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
index d345637507..cd8fdadbf8 100644
--- a/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
+++ b/application/webserver/src/main/java/org/videolan/vlc/webserver/RemoteAccessRouting.kt
@@ -59,6 +59,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
+import kotlinx.coroutines.withTimeout
import org.json.JSONArray
import org.json.JSONObject
import org.videolan.medialibrary.MLServiceLocator
@@ -448,7 +449,8 @@ fun Route.setupRouting(appContext: Context, scope: CoroutineScope) {
return at get
}
//block the request until a message is received
- val message = RemoteAccessWebSockets.onPlaybackEventChannel.receive()
+ // The 3 second timeout is to avoid blocking forever
+ val message = withTimeout(3000) { RemoteAccessWebSockets.onPlaybackEventChannel.receive() }
if (message.contains("\"type\":\"browser-description\"")) {
call.respondText("[$message]")
return at get
More information about the Android
mailing list