Added withContext(Dispatchers.IO) for network call
This commit is contained in:
+30
-19
@@ -20,6 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.home.live
|
package com.vitorpamplona.amethyst.ui.screen.loggedIn.home.live
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -36,7 +37,9 @@ import com.vitorpamplona.amethyst.model.emphChat.EphemeralChatChannel
|
|||||||
import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel
|
import com.vitorpamplona.amethyst.model.nip53LiveActivities.LiveActivitiesChannel
|
||||||
import com.vitorpamplona.amethyst.service.OnlineChecker
|
import com.vitorpamplona.amethyst.service.OnlineChecker
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LiveStatusIndicator(
|
fun LiveStatusIndicator(
|
||||||
@@ -75,26 +78,34 @@ private suspend fun checkChannelIsOnline(
|
|||||||
channel: Channel,
|
channel: Channel,
|
||||||
accountViewModel: AccountViewModel,
|
accountViewModel: AccountViewModel,
|
||||||
): Boolean =
|
): Boolean =
|
||||||
when (channel) {
|
withContext(Dispatchers.IO) {
|
||||||
is LiveActivitiesChannel -> {
|
try {
|
||||||
// Check if streaming URL is online, fall back to relay check
|
when (channel) {
|
||||||
val streamingUrl = channel.info?.streaming()
|
is LiveActivitiesChannel -> {
|
||||||
if (!streamingUrl.isNullOrBlank()) {
|
// Check if streaming URL is online, fall back to relay check
|
||||||
accountViewModel.checkVideoIsOnline(streamingUrl)
|
val streamingUrl = channel.info?.streaming()
|
||||||
} else {
|
if (!streamingUrl.isNullOrBlank()) {
|
||||||
// Check relay connection
|
accountViewModel.checkVideoIsOnline(streamingUrl)
|
||||||
val relayUrl = channel.relayHintUrl()
|
} else {
|
||||||
if (relayUrl != null) {
|
// Check relay connection
|
||||||
OnlineChecker.isOnline(relayUrl.url, accountViewModel.httpClientBuilder::okHttpClientForVideo)
|
val relayUrl = channel.relayHintUrl()
|
||||||
} else {
|
if (relayUrl != null) {
|
||||||
false
|
OnlineChecker.isOnline(relayUrl.url, accountViewModel.httpClientBuilder::okHttpClientForVideo)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
is EphemeralChatChannel -> {
|
||||||
|
// Check relay connection for ephemeral chat
|
||||||
|
val relayUrl = channel.roomId.relayUrl
|
||||||
|
OnlineChecker.isOnline(relayUrl.url, accountViewModel.httpClientBuilder::okHttpClientForVideo)
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
}
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.d("LiveStatusIndicator", "Network error checking channel ${channel.toBestDisplayName()}: ${e.message}")
|
||||||
|
// Return false if any network error occurs
|
||||||
|
false
|
||||||
}
|
}
|
||||||
is EphemeralChatChannel -> {
|
|
||||||
// Check relay connection for ephemeral chat
|
|
||||||
val relayUrl = channel.roomId.relayUrl
|
|
||||||
OnlineChecker.isOnline(relayUrl.url, accountViewModel.httpClientBuilder::okHttpClientForVideo)
|
|
||||||
}
|
|
||||||
else -> false
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user