Skip to content

Commit 08ecf59

Browse files
committed
bugfix: After fixing the failure of RTC reconnection and WebSocket connection, no notification was sent to the upper-layer application.
1 parent 25451cf commit 08ecf59

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

livekit-android-sdk/src/main/java/io/livekit/android/room/RTCEngine.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ internal constructor(
142142
ConnectionState.DISCONNECTED -> {
143143
LKLog.d { "primary ICE disconnected" }
144144
if (oldVal == ConnectionState.CONNECTED) {
145+
LKLog.d { "ready call reconnect()" }
146+
reconnect()
147+
} else if (oldVal == ConnectionState.RESUMING || oldVal == ConnectionState.RECONNECTING) {
148+
LKLog.d { "ICE disconnected during reconnect, retrying reconnect()" }
145149
reconnect()
146150
}
147151
}
@@ -307,7 +311,14 @@ internal constructor(
307311
if (newState.isConnected()) {
308312
connectionState = ConnectionState.CONNECTED
309313
} else if (newState.isDisconnected()) {
310-
connectionState = ConnectionState.DISCONNECTED
314+
// Only transition to DISCONNECTED when not already in a reconnection
315+
// intermediate state (RESUMING/RECONNECTING). In those states the
316+
// reconnect flow owns connectionState; overwriting it here would
317+
// silently swallow the disconnect and prevent the app from being notified.
318+
val current = connectionState
319+
if (current != ConnectionState.RESUMING && current != ConnectionState.RECONNECTING) {
320+
connectionState = ConnectionState.DISCONNECTED
321+
}
311322
}
312323
}
313324

livekit-android-sdk/src/main/java/io/livekit/android/room/SignalClient.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ constructor(
349349
LKLog.e(e) { "failed to validate connection" }
350350
}
351351

352+
val wasConnected = isConnected
353+
val wasConnecting = joinContinuation != null
354+
352355
if (reason != null) {
353356
LKLog.e(t) { "websocket failure: $reason" }
354357
val error = Exception(reason)
@@ -361,11 +364,11 @@ constructor(
361364
}
362365
joinContinuation = null
363366

364-
val wasConnected = isConnected
365-
366-
if (wasConnected) {
367+
if (wasConnected || wasConnecting) {
367368
// onClosing/onClosed will not be called after onFailure.
368369
// Handle websocket closure here.
370+
// Also handle the case where failure occurs during a reconnect attempt (wasConnecting),
371+
// where isConnected is already false but the upper layer still needs to be notified.
369372
handleWebSocketClose(
370373
reason = reason ?: response?.toString() ?: t.localizedMessage ?: "websocket failure",
371374
code = response?.code ?: CLOSE_REASON_WEBSOCKET_FAILURE,

0 commit comments

Comments
 (0)