Skip to content

Commit cc38651

Browse files
authored
When joining a call, wait for the content_loaded action (#5399)
* When joining a call, wait for the `content_loaded` action This ensures the widget won't be disposed when the user joins a call and loads the lobby screen for room calls
1 parent 0a5c178 commit cc38651

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

features/call/impl/src/main/kotlin/io/element/android/features/call/impl/data/WidgetMessage.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,8 @@ data class WidgetMessage(
4141

4242
@SerialName("send_event")
4343
SendEvent,
44+
45+
@SerialName("content_loaded")
46+
ContentLoaded,
4447
}
4548
}

features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/CallScreenPresenter.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class CallScreenPresenter(
7979
val urlState = remember { mutableStateOf<AsyncData<String>>(AsyncData.Uninitialized) }
8080
val callWidgetDriver = remember { mutableStateOf<MatrixWidgetDriver?>(null) }
8181
val messageInterceptor = remember { mutableStateOf<WidgetMessageInterceptor?>(null) }
82-
var isJoinedCall by rememberSaveable { mutableStateOf(false) }
82+
var isWidgetLoaded by rememberSaveable { mutableStateOf(false) }
8383
var ignoreWebViewError by rememberSaveable { mutableStateOf(false) }
8484
var webViewError by remember { mutableStateOf<String?>(null) }
8585
val languageTag = languageTagProvider.provideLanguageTag()
@@ -139,8 +139,8 @@ class CallScreenPresenter(
139139
if (parsedMessage?.direction == WidgetMessage.Direction.FromWidget) {
140140
if (parsedMessage.action == WidgetMessage.Action.Close) {
141141
close(callWidgetDriver.value, navigator)
142-
} else if (parsedMessage.action == WidgetMessage.Action.Join) {
143-
isJoinedCall = true
142+
} else if (parsedMessage.action == WidgetMessage.Action.ContentLoaded) {
143+
isWidgetLoaded = true
144144
}
145145
}
146146
}
@@ -151,8 +151,8 @@ class CallScreenPresenter(
151151
// Wait for the call to be joined, if it takes too long, we display an error
152152
delay(10.seconds)
153153

154-
if (!isJoinedCall) {
155-
Timber.w("The call took too long to be joined. Displaying an error before exiting.")
154+
if (!isWidgetLoaded) {
155+
Timber.w("The call took too long to load. Displaying an error before exiting.")
156156

157157
// This will display a simple 'Sorry, an error occurred' dialog and force the user to exit the call
158158
webViewError = ""
@@ -165,10 +165,10 @@ class CallScreenPresenter(
165165
is CallScreenEvents.Hangup -> {
166166
val widgetId = callWidgetDriver.value?.id
167167
val interceptor = messageInterceptor.value
168-
if (widgetId != null && interceptor != null && isJoinedCall) {
168+
if (widgetId != null && interceptor != null && isWidgetLoaded) {
169169
// If the call was joined, we need to hang up first. Then the UI will be dismissed automatically.
170170
sendHangupMessage(widgetId, interceptor)
171-
isJoinedCall = false
171+
isWidgetLoaded = false
172172

173173
coroutineScope.launch {
174174
// Wait for a couple of seconds to receive the hangup message
@@ -198,7 +198,7 @@ class CallScreenPresenter(
198198
urlState = urlState.value,
199199
webViewError = webViewError,
200200
userAgent = userAgent,
201-
isCallActive = isJoinedCall,
201+
isCallActive = isWidgetLoaded,
202202
isInWidgetMode = isInWidgetMode,
203203
eventSink = { handleEvents(it) },
204204
)

features/call/impl/src/test/kotlin/io/element/android/features/call/ui/CallScreenPresenterTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ import kotlin.time.Duration.Companion.seconds
215215
}
216216

217217
@Test
218-
fun `present - a received 'joined' action makes the call to be active`() = runTest {
218+
fun `present - a received 'content loaded' action makes the call to be active`() = runTest {
219219
val navigator = FakeCallScreenNavigator()
220220
val widgetDriver = FakeMatrixWidgetDriver()
221221
val presenter = createCallScreenPresenter(
@@ -238,7 +238,7 @@ import kotlin.time.Duration.Companion.seconds
238238
messageInterceptor.givenInterceptedMessage(
239239
"""
240240
{
241-
"action":"io.element.join",
241+
"action":"content_loaded",
242242
"api":"fromWidget",
243243
"widgetId":"1",
244244
"requestId":"1"

0 commit comments

Comments
 (0)