Skip to content

regression: mobile app shows incorrect "on hold" state on voice calls#40299

Open
pierre-lehnen-rc wants to merge 1 commit intorelease-8.4.0from
regression/remote-held-mobile
Open

regression: mobile app shows incorrect "on hold" state on voice calls#40299
pierre-lehnen-rc wants to merge 1 commit intorelease-8.4.0from
regression/remote-held-mobile

Conversation

@pierre-lehnen-rc
Copy link
Copy Markdown
Contributor

@pierre-lehnen-rc pierre-lehnen-rc commented Apr 24, 2026

Proposed changes (including videos or screenshots)

We update the "on hold" status whenever an internal webrtc state changes and we determine if the call is on hold based on the currentDirection attribute of the RTCRtpTransceiver.
This works fine on web, but on the mobile implementation of webrtc, the transceiver's currentDirection is only updated after the state change event is emitted, so we were updating the "on hold" status based on the previous direction instead of the current one.

This PR changes it so that the "on hold" status is always updated at the end of any negotiation, instead of immediately after it becomes stable.

Issue(s)

VMUX-94

Steps to test or reproduce

Further comments

Summary by CodeRabbit

  • Improvements

    • Enhanced detection of remote-held state in WebRTC connections.
  • Performance

    • Optimized remote-held state tracking.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot Bot commented Apr 24, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 24, 2026

⚠️ No Changeset found

Latest commit: 2aca7de

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 24, 2026

Walkthrough

The WebRTC processor adds cached remote-held state tracking by introducing a _remoteHeld field and extending the internal state map with a remoteHeld: boolean property. The isRemoteHeld() method now returns the cached value instead of computing it dynamically. Offer/answer negotiation handling is refactored to delegate direction updates through pre/post-negotiation methods, with post-negotiation additionally recalculating remote-held status.

Changes

Cohort / File(s) Summary
Remote-held state tracking
packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts, packages/media-signaling/src/lib/services/webrtc/Processor.ts
Added cached _remoteHeld field and remoteHeld property to internal state map. Implemented updateRemoteHeld() and setRemoteHeld() methods to derive held state from audio transceiver currentDirection. Refactored offer/answer handling to delegate pre/post-negotiation direction updates and recalculate remote-held status post-negotiation. Changed isRemoteHeld() to return cached value with state change events and logging.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main issue being fixed: incorrect 'on hold' state display on mobile voice calls, which directly matches the regression fix described in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • VMUX-94: Request failed with status code 401

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pierre-lehnen-rc pierre-lehnen-rc added this to the 8.4.0 milestone Apr 24, 2026
@pierre-lehnen-rc pierre-lehnen-rc added the stat: QA assured Means it has been tested and approved by a company insider label Apr 24, 2026
@dionisio-bot dionisio-bot Bot added the stat: ready to merge PR tested and approved waiting for merge label Apr 24, 2026
@pierre-lehnen-rc pierre-lehnen-rc marked this pull request as ready for review April 24, 2026 16:48
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/media-signaling/src/lib/services/webrtc/Processor.ts (1)

603-629: Consider renaming anyTransceiverNotSending for clarity.

The loop returns false as soon as any audio transceiver is still sending, so the flag only ever represents "at least one non-stopped audio transceiver exists and none of them are sending" — effectively the held condition itself. A name like hasHeldAudioTransceiver (or simply computing once at the end) would read closer to intent. Non-blocking.

♻️ Optional rename
-		let anyTransceiverNotSending = false;
+		let hasHeldAudioTransceiver = false;
 		const transceivers = this.getTransceivers('audio');
 
 		for (const transceiver of transceivers) {
 			if (!transceiver.currentDirection || transceiver.currentDirection === 'stopped') {
 				continue;
 			}
 
 			if (transceiver.currentDirection.includes('send')) {
 				this.setRemoteHeld(false);
 				return;
 			}
 
-			anyTransceiverNotSending = true;
+			hasHeldAudioTransceiver = true;
 		}
 
-		this.setRemoteHeld(anyTransceiverNotSending);
+		this.setRemoteHeld(hasHeldAudioTransceiver);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/media-signaling/src/lib/services/webrtc/Processor.ts` around lines
603 - 629, The variable anyTransceiverNotSending in updateRemoteHeld is
misleading; change it to a clearer name like hasHeldAudioTransceiver (or compute
the held condition directly) so the intent matches the logic that if any audio
transceiver is sending we call setRemoteHeld(false) and otherwise we call
setRemoteHeld(true); update references in updateRemoteHeld and keep the same
behavior with getTransceivers('audio') and setRemoteHeld.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/media-signaling/src/lib/services/webrtc/Processor.ts`:
- Around line 603-629: The variable anyTransceiverNotSending in updateRemoteHeld
is misleading; change it to a clearer name like hasHeldAudioTransceiver (or
compute the held condition directly) so the intent matches the logic that if any
audio transceiver is sending we call setRemoteHeld(false) and otherwise we call
setRemoteHeld(true); update references in updateRemoteHeld and keep the same
behavior with getTransceivers('audio') and setRemoteHeld.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1c034ffa-6d05-4f8f-8fe3-1f5a28d8a96a

📥 Commits

Reviewing files that changed from the base of the PR and between 92dbb53 and 2aca7de.

📒 Files selected for processing (2)
  • packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: 📦 Build Packages
  • GitHub Check: CodeQL-Build
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: pierre-lehnen-rc
Repo: RocketChat/Rocket.Chat PR: 36718
File: packages/media-signaling/src/lib/Call.ts:633-642
Timestamp: 2025-09-23T00:27:05.438Z
Learning: In PR `#36718`, pierre-lehnen-rc prefers to maintain consistency with the old architecture patterns for DTMF handling rather than implementing immediate validation improvements, deferring enhancements to future work.
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts
  • packages/media-signaling/src/lib/services/webrtc/Processor.ts
🔇 Additional comments (5)
packages/media-signaling/src/definition/services/webrtc/IWebRTCProcessor.ts (1)

16-16: LGTM!

Adding remoteHeld: boolean to WebRTCInternalStateMap cleanly aligns the public internal-state surface with the new cached value emitted by MediaCallWebRTCProcessor through internalStateChange. getInternalState('remoteHeld') in Processor.ts and the updateRemoteStates() consumer in Call.ts become properly typed.

packages/media-signaling/src/lib/services/webrtc/Processor.ts (4)

49-49: Caching _remoteHeld and routing reads through it looks correct.

The field is initialized to false, exposed via both isRemoteHeld() and getInternalState('remoteHeld'), and only mutated through setRemoteHeld() which emits internalStateChange. This matches the Call.updateRemoteStates() consumer that reads isRemoteHeld() off the same internalStateChange event, so the cached value is guaranteed to be observed in sync.

Also applies to: 234-235, 249-251


110-110: Pre/post-negotiation wiring covers both offer and answer paths.

  • Outgoing: createOfferprocessPreNegotiation; setRemoteDescription(answer)processPostNegotiation.
  • Incoming: setRemoteDescription(offer)processPreNegotiation; setLocalDescription(answer)processPostNegotiation.

Running updateRemoteHeld() only from processPostNegotiation (after the await peer.setLocal/RemoteDescription resolves) rather than from arbitrary onsignalingstatechange/onconnectionstatechange callbacks is the right fix for the mobile case where transceiver.currentDirection lags the state-change event.

Also applies to: 190-192, 207-214


577-585: setRemoteHeld short-circuit and emit pattern are consistent with setRemoteMute.

Early return on no-change prevents spurious internalStateChange emissions (and therefore redundant trackStateChange emissions via Call.updateRemoteStates()). Good symmetry with setRemoteMute above.


603-610: The connectionState guard is correct and will not swallow hold updates during mid-call renegotiation. During initial setup, connectionState is 'new' and nothing is held yet, so early return is safe. During mid-call renegotiation, the connection is already established, so connectionState remains 'connected' and updateRemoteHeld() executes normally to apply transceiver-based hold state. The guard only prevents hold updates if the connection has actually transitioned to 'closed', 'failed', or (unlikely) back to 'new' via explicit ICE restart, which is correct behavior.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.79%. Comparing base (7d63387) to head (2aca7de).
⚠️ Report is 7 commits behind head on release-8.4.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-8.4.0   #40299      +/-   ##
=================================================
+ Coverage          69.78%   69.79%   +0.01%     
=================================================
  Files               3296     3298       +2     
  Lines             119186   119292     +106     
  Branches           21517    21489      -28     
=================================================
+ Hits               83171    83258      +87     
- Misses             32715    32734      +19     
  Partials            3300     3300              
Flag Coverage Δ
e2e 59.69% <ø> (-0.07%) ⬇️
e2e-api 46.24% <ø> (-0.02%) ⬇️
unit 70.55% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant