fix: tear down nest session on host Close the Room

The host-leave confirmation dialog's Close the Room button only called
finish(), relying on VM.onCleared() to release the AudioRecord. That
runs late in the destroy lifecycle, so the system mic-in-use indicator
stayed lit while the activity was queued for destruction.

Adds NestViewModel.leave(), which mirrors onCleared() (sets closed,
runs both teardowns with finalCleanup=true so closes route through
cleanupScope/GlobalScope and survive Activity destruction). Wires it
into the Close the Room callback only — the Just Leave and non-host
Leave paths are unchanged per request.
This commit is contained in:
Claude
2026-05-01 21:47:33 +00:00
parent 6610683a20
commit 36152243ab
2 changed files with 29 additions and 0 deletions
@@ -545,6 +545,24 @@ class NestViewModel(
teardown(targetState = ConnectionUiState.Idle, finalCleanup = false)
}
/**
* User-driven leave-the-activity teardown. Mirrors [onCleared]: marks
* the VM closed and routes both the speaker handle close (which
* releases the AudioRecord and clears the system mic indicator) and
* the listener close to [cleanupScope] so the teardown survives
* Activity destruction. Call this from the leave-the-room button
* BEFORE finishing the activity; relying on [onCleared] alone leaves
* a window where the AudioRecord stays held while the activity is
* paused / queued for destruction.
*/
fun leave() {
if (closed) return
closed = true
requestedSpeakers = emptySet()
teardownBroadcast(BroadcastUiState.Idle, finalCleanup = true)
teardown(targetState = ConnectionUiState.Closed, finalCleanup = true)
}
override fun onCleared() {
closed = true
teardownBroadcast(BroadcastUiState.Idle, finalCleanup = true)