davidliu
Committed by GitHub

Fix RTCEngine not being set to connecting state (#706)

---
"client-sdk-android": patch
---
Fix not being able to publish immediately after connecting
... ...
... ... @@ -117,7 +117,7 @@ internal constructor(
}
when (newVal) {
ConnectionState.CONNECTED -> {
if (oldVal == ConnectionState.DISCONNECTED) {
if (oldVal == ConnectionState.DISCONNECTED || oldVal == ConnectionState.CONNECTING) {
LKLog.d { "primary ICE connected" }
listener?.onEngineConnected()
} else if (oldVal == ConnectionState.RECONNECTING) {
... ... @@ -209,6 +209,9 @@ internal constructor(
options: ConnectOptions,
roomOptions: RoomOptions,
): JoinResponse = coroutineScope {
if (connectionState == ConnectionState.DISCONNECTED) {
connectionState = ConnectionState.CONNECTING
}
val joinResponse = client.join(url, token, options, roomOptions)
ensureActive()
... ...
/*
* Copyright 2023-2024 LiveKit, Inc.
* Copyright 2023-2025 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
... ... @@ -17,9 +17,10 @@
package io.livekit.android.room
import io.livekit.android.test.MockE2ETest
import io.livekit.android.test.events.FlowCollector
import io.livekit.android.test.mock.TestData
import io.livekit.android.test.util.toOkioByteString
import io.livekit.android.test.util.toPBByteString
import io.livekit.android.util.flow
import io.livekit.android.util.toOkioByteString
import kotlinx.coroutines.ExperimentalCoroutinesApi
import livekit.LivekitModels
... ... @@ -44,6 +45,18 @@ class RTCEngineMockE2ETest : MockE2ETest() {
}
@Test
fun connectionState() = runTest {
val collector = FlowCollector(rtcEngine::connectionState.flow, coroutineRule.scope)
connect()
val events = collector.stopCollecting()
println(events)
assertEquals(3, events.size)
assertEquals(ConnectionState.DISCONNECTED, events[0])
assertEquals(ConnectionState.CONNECTING, events[1])
assertEquals(ConnectionState.CONNECTED, events[2])
}
@Test
fun iceServersSetOnJoin() = runTest {
connect()
val sentIceServers = TestData.JOIN.join.iceServersList
... ... @@ -143,6 +156,7 @@ class RTCEngineMockE2ETest : MockE2ETest() {
assertEquals(PeerConnection.IceTransportsType.RELAY, subPeerConnection.rtcConfig.iceTransportsType)
}
@Test
fun participantIdOnReconnect() = runTest {
connect()
wsFactory.listener.onFailure(wsFactory.ws, Exception(), null)
... ...