davidliu
Committed by GitHub

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

  1 +---
  2 +"client-sdk-android": patch
  3 +---
  4 +
  5 +Fix not being able to publish immediately after connecting
@@ -117,7 +117,7 @@ internal constructor( @@ -117,7 +117,7 @@ internal constructor(
117 } 117 }
118 when (newVal) { 118 when (newVal) {
119 ConnectionState.CONNECTED -> { 119 ConnectionState.CONNECTED -> {
120 - if (oldVal == ConnectionState.DISCONNECTED) { 120 + if (oldVal == ConnectionState.DISCONNECTED || oldVal == ConnectionState.CONNECTING) {
121 LKLog.d { "primary ICE connected" } 121 LKLog.d { "primary ICE connected" }
122 listener?.onEngineConnected() 122 listener?.onEngineConnected()
123 } else if (oldVal == ConnectionState.RECONNECTING) { 123 } else if (oldVal == ConnectionState.RECONNECTING) {
@@ -209,6 +209,9 @@ internal constructor( @@ -209,6 +209,9 @@ internal constructor(
209 options: ConnectOptions, 209 options: ConnectOptions,
210 roomOptions: RoomOptions, 210 roomOptions: RoomOptions,
211 ): JoinResponse = coroutineScope { 211 ): JoinResponse = coroutineScope {
  212 + if (connectionState == ConnectionState.DISCONNECTED) {
  213 + connectionState = ConnectionState.CONNECTING
  214 + }
212 val joinResponse = client.join(url, token, options, roomOptions) 215 val joinResponse = client.join(url, token, options, roomOptions)
213 ensureActive() 216 ensureActive()
214 217
1 /* 1 /*
2 - * Copyright 2023-2024 LiveKit, Inc. 2 + * Copyright 2023-2025 LiveKit, Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License. 5 * you may not use this file except in compliance with the License.
@@ -17,9 +17,10 @@ @@ -17,9 +17,10 @@
17 package io.livekit.android.room 17 package io.livekit.android.room
18 18
19 import io.livekit.android.test.MockE2ETest 19 import io.livekit.android.test.MockE2ETest
  20 +import io.livekit.android.test.events.FlowCollector
20 import io.livekit.android.test.mock.TestData 21 import io.livekit.android.test.mock.TestData
21 -import io.livekit.android.test.util.toOkioByteString  
22 import io.livekit.android.test.util.toPBByteString 22 import io.livekit.android.test.util.toPBByteString
  23 +import io.livekit.android.util.flow
23 import io.livekit.android.util.toOkioByteString 24 import io.livekit.android.util.toOkioByteString
24 import kotlinx.coroutines.ExperimentalCoroutinesApi 25 import kotlinx.coroutines.ExperimentalCoroutinesApi
25 import livekit.LivekitModels 26 import livekit.LivekitModels
@@ -44,6 +45,18 @@ class RTCEngineMockE2ETest : MockE2ETest() { @@ -44,6 +45,18 @@ class RTCEngineMockE2ETest : MockE2ETest() {
44 } 45 }
45 46
46 @Test 47 @Test
  48 + fun connectionState() = runTest {
  49 + val collector = FlowCollector(rtcEngine::connectionState.flow, coroutineRule.scope)
  50 + connect()
  51 + val events = collector.stopCollecting()
  52 + println(events)
  53 + assertEquals(3, events.size)
  54 + assertEquals(ConnectionState.DISCONNECTED, events[0])
  55 + assertEquals(ConnectionState.CONNECTING, events[1])
  56 + assertEquals(ConnectionState.CONNECTED, events[2])
  57 + }
  58 +
  59 + @Test
47 fun iceServersSetOnJoin() = runTest { 60 fun iceServersSetOnJoin() = runTest {
48 connect() 61 connect()
49 val sentIceServers = TestData.JOIN.join.iceServersList 62 val sentIceServers = TestData.JOIN.join.iceServersList
@@ -143,6 +156,7 @@ class RTCEngineMockE2ETest : MockE2ETest() { @@ -143,6 +156,7 @@ class RTCEngineMockE2ETest : MockE2ETest() {
143 assertEquals(PeerConnection.IceTransportsType.RELAY, subPeerConnection.rtcConfig.iceTransportsType) 156 assertEquals(PeerConnection.IceTransportsType.RELAY, subPeerConnection.rtcConfig.iceTransportsType)
144 } 157 }
145 158
  159 + @Test
146 fun participantIdOnReconnect() = runTest { 160 fun participantIdOnReconnect() = runTest {
147 connect() 161 connect()
148 wsFactory.listener.onFailure(wsFactory.ws, Exception(), null) 162 wsFactory.listener.onFailure(wsFactory.ws, Exception(), null)