Skip to content

fix: send local state when ICE connects instead of at participant-add time#6086

Open
alauzon wants to merge 2 commits intonextcloud:masterfrom
alauzon:fix/local-state-not-sent-after-ice-connected
Open

fix: send local state when ICE connects instead of at participant-add time#6086
alauzon wants to merge 2 commits intonextcloud:masterfrom
alauzon:fix/local-state-not-sent-after-ice-connected

Conversation

@alauzon
Copy link
Copy Markdown

@alauzon alauzon commented Apr 16, 2026

Fixes #6037

Problem

When a remote participant was added to a call (no MCU), LocalStateBroadcasterNoMcu.handleCallParticipantAdded was called with a snapshot of the current ParticipantUiState. At that moment the PeerConnectionWrapper did not yet exist, so the data channel was unavailable and all state messages (audioOn/videoOn/speaking) were silently dropped.

After setPeerConnection() was called and ICE negotiation completed (isConnected became true), nobody called handleCallParticipantAdded again — so the remote participant never learned the local audio/video state.

Consequence: the remote participant saw a grey/unknown icon for local audio and video until the local user manually toggled their mic or camera. Guests joining with audio-only could appear as "connecting" with no audio permanently.

Fix

LocalStateBroadcasterNoMcu now accepts a live StateFlow<ParticipantUiState> and collects it internally via an IceConnectionStateObserver coroutine. State is sent on every false → true transition of isConnected, i.e. exactly when the data channel becomes ready.

CallActivity.addCallParticipant now passes the live StateFlow (one line) instead of the snapshot .value.

A non-abstract default overload is added to LocalStateBroadcaster so that LocalStateBroadcasterMcu continues to work unchanged.

Tests

Three test classes are added or rewritten:

  • LocalStateBroadcasterNoMcuTest — drives isConnected via MutableStateFlow; fails without the fix because updates after handleCallParticipantAdded are never observed
  • CallParticipantStateBroadcastIntegrationTest — full pipeline test through CallViewModel → ParticipantHandler → LocalStateBroadcasterNoMcu with a mocked PeerConnectionWrapper driving ICE transitions
  • CallActivityAddParticipantTest — Robolectric test verifying that CallActivity passes the live StateFlow object (not a snapshot) to the broadcaster

All tests were validated to fail without the fix and pass with it.

@mahibi
Copy link
Copy Markdown
Collaborator

mahibi commented Apr 17, 2026

Thank you for contributing @alauzon
The code base which you worked on is quite outdated. Could you please rebase on the latest master?

Please also solve the DCO warning be following https://github.com/nextcloud/talk-android/pull/6086/checks?check_run_id=71734417320

@alauzon alauzon force-pushed the fix/local-state-not-sent-after-ice-connected branch 2 times, most recently from 046eef9 to b05d8f8 Compare April 17, 2026 11:39
@mahibi mahibi self-requested a review April 17, 2026 11:40
… time

When a participant was added, LocalStateBroadcasterNoMcu.handleCallParticipantAdded
was called with a snapshot of the current ParticipantUiState. At that moment the
PeerConnectionWrapper did not yet exist, so the data channel was unavailable and
all state messages (audioOn/videoOn/speaking) were silently dropped. Subsequent
ICE transitions were never observed, so the remote participant never learned the
local audio/video state.

Fix: LocalStateBroadcasterNoMcu now accepts a live StateFlow<ParticipantUiState>
and collects it internally via IceConnectionStateObserver. State is sent on every
false→true transition of isConnected, i.e. exactly when the data channel becomes
ready. CallActivity passes the live StateFlow instead of the snapshot value.

A non-abstract default overload is added to LocalStateBroadcaster so that
LocalStateBroadcasterMcu continues to work unchanged.

Tests:
- LocalStateBroadcasterNoMcuTest: drives state via MutableStateFlow; fails
  without the fix because updates after handleCallParticipantAdded are never seen
- CallParticipantStateBroadcastIntegrationTest: full pipeline test through
  CallViewModel → ParticipantHandler → LocalStateBroadcasterNoMcu with a mocked
  PeerConnectionWrapper driving ICE transitions
- CallActivityAddParticipantTest: Robolectric test verifying that CallActivity
  passes the live StateFlow object (not a snapshot) to the broadcaster

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Alain Lauzon <alauzon@alainlauzon.com>
@alauzon alauzon force-pushed the fix/local-state-not-sent-after-ice-connected branch from b05d8f8 to 2c5d311 Compare April 17, 2026 11:51
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.

Guest users joining a call with audio-only are sometimes inaudible on app

2 participants