Skip to content

Display error dialog if Element Call can't be joined #4919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ data class WidgetMessage(

@Serializable
enum class Action {
@SerialName("io.element.join")
Join,

@SerialName("im.vector.hangup")
HangUp,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ import io.element.android.services.appnavstate.api.ActiveRoomsHolder
import io.element.android.services.appnavstate.api.AppForegroundStateService
import io.element.android.services.toolbox.api.systemclock.SystemClock
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import timber.log.Timber
import java.util.UUID
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -91,6 +89,8 @@ class CallScreenPresenter @AssistedInject constructor(
var webViewError by remember { mutableStateOf<String?>(null) }
val languageTag = languageTagProvider.provideLanguageTag()
val theme = if (ElementTheme.isLightTheme) "light" else "dark"
var loadCallTimeoutJob by remember { mutableStateOf<Job?>(null) }

DisposableEffect(Unit) {
coroutineScope.launch {
// Sets the call as joined
Expand Down Expand Up @@ -121,6 +121,15 @@ class CallScreenPresenter @AssistedInject constructor(

callWidgetDriver.value?.let { driver ->
LaunchedEffect(Unit) {
loadCallTimeoutJob = launch {
// Wait for the call to be loaded, if it takes too long, we display an error
delay(10.seconds)

Timber.w("The call took too long to be joined. Displaying an error before exiting.")

// This will display a simple 'Sorry, an error occurred' dialog
webViewError = ""
}
driver.incomingMessages
.onEach {
// Relay message to the WebView
Expand All @@ -145,12 +154,10 @@ class CallScreenPresenter @AssistedInject constructor(
if (parsedMessage?.direction == WidgetMessage.Direction.FromWidget) {
if (parsedMessage.action == WidgetMessage.Action.Close) {
close(callWidgetDriver.value, navigator)
} else if (parsedMessage.action == WidgetMessage.Action.SendEvent) {
// This event is received when a member joins the call, the first one will be the current one
val type = parsedMessage.data?.jsonObject?.get("type")?.jsonPrimitive?.contentOrNull
if (type == "org.matrix.msc3401.call.member") {
isJoinedCall = true
}
Comment on lines -148 to -153
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the VOIP team, this should work the same. I didn't see any changes in behaviour when I tested it.

} else if (parsedMessage.action == WidgetMessage.Action.Join) {
// This action is received when the call is joined, we can stop the timeout job
isJoinedCall = true
loadCallTimeoutJob?.cancel()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ import kotlin.time.Duration.Companion.seconds
}

@Test
fun `present - a received room member message makes the call to be active`() = runTest {
fun `present - a received 'joined' action makes the call to be active`() = runTest {
val navigator = FakeCallScreenNavigator()
val widgetDriver = FakeMatrixWidgetDriver()
val presenter = createCallScreenPresenter(
Expand All @@ -248,13 +248,10 @@ import kotlin.time.Duration.Companion.seconds
messageInterceptor.givenInterceptedMessage(
"""
{
"action":"send_event",
"action":"io.element.join",
"api":"fromWidget",
"widgetId":"1",
"requestId":"1",
"data":{
"type":"org.matrix.msc3401.call.member"
}
"requestId":"1"
}
""".trimIndent()
)
Expand Down
Loading