Skip to content

fix: keep the pre-connect audio buffer through a region failover on connect - #1215

Draft
hiroshihorie wants to merge 2 commits into
mainfrom
hiroshi/preconnect-audio-survives-failover
Draft

hiroshihorie wants to merge 2 commits into
mainfrom
hiroshi/preconnect-audio-survives-failover

Conversation

@hiroshihorie

Copy link
Copy Markdown
Member

Problem

When the first connect attempt fails, the engine reports a disconnect before Room.connect retries another Cloud region. The Room handled that disconnect like any other and reset the pre-connect audio buffer. The retry then connected with a buffer that was no longer recording, so the join response found no microphone track to publish. The participant ended up in the room, joined unmuted, with no microphone until they toggled it.

Since 2.13.0 a 403 rejection also fails over instead of failing the connect, so a first attempt that used to fail visibly now connects silently without the microphone.

Fix

  • Room.connect records that a connect attempt is running.
  • The engine disconnect handler passes that state to _cleanUp, which skips the pre-connect buffer reset when the disconnect belongs to a connect attempt.
  • A connect that fails for good still ends with the caller's own cleanup (withPreConnectAudio stops and resets the buffer on error), and a disconnect outside of a connect attempt still resets it.

Tests

test/core/preconnect_failover_test.dart:

  • first socket connect fails, the validate call answers 403, the retry connects: the buffer is still recording afterwards. Fails on main, passes here.
  • a server initiated leave while connected still resets the buffer.

Test-only additions: Room.regionUrlProviderForTesting, PreConnectAudioBuffer.markRecordingForTesting, sdkHttpClientFactoryForTesting, and a connectErrorOnce switch on the websocket mock so a first attempt fails and the retry gets through.

flutter analyze clean, test/core, test/preconnect and test/support green (171 tests).

…onnect

When the first connect attempt fails, the engine reports a disconnect
before Room.connect retries another region. The Room handled that
disconnect like any other and reset the pre-connect audio buffer, so the
retry connected without a recording buffer and the join response found
nothing to publish. The participant ended up in the room with no
microphone until they toggled it, even though they had joined unmuted.

Track whether Room.connect is running and leave the buffer alone when the
disconnect belongs to a connect attempt. A connect that fails for good
still ends with the caller's own cleanup, and a disconnect outside of a
connect attempt still resets the buffer.

Tests: a failover where the first socket connect fails and the validate
call answers 403 now keeps the buffer recording, and a server initiated
leave still resets it. Adds small test hooks for the region provider, the
buffer's recording state, the HTTP client and a fail-once websocket mock.
@github-actions

Copy link
Copy Markdown

Warning

No changeset found

If this PR includes user-facing changes, please add a changeset file in .changes/

Format: level type="kind" "description"

patch type="fixed" "Fix audio frame generation"
minor type="added" "Add support for custom audio processing"
major type="changed" "Breaking: Rename Room.connect() to Room.join()"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant