Skip to content

fix(voip): gate incoming answer on microphone permission#7354

Open
diegolmello wants to merge 3 commits into
developfrom
fix/voip-incoming-mic-permission-gate
Open

fix(voip): gate incoming answer on microphone permission#7354
diegolmello wants to merge 3 commits into
developfrom
fix/voip-incoming-mic-permission-gate

Conversation

@diegolmello
Copy link
Copy Markdown
Member

@diegolmello diegolmello commented May 27, 2026

Proposed changes

Incoming VoIP calls could hang until the 10s signaling timeout when microphone permission was not granted. The accept path now requests mic permission before accept() runs on both iOS and Android.

When permission is denied, the call is hung up immediately and the user sees an appropriate alert. Permanent denial offers a shortcut to OS settings (same pattern as audio message recording).

Outgoing calls use the same improved denial UX.

requestVoipCallPermissions never rejects — a failing permission check (e.g. an Android request throw when a call is answered locked/backgrounded) is logged and treated as denied, so the call ends promptly instead of re-introducing the hang. answerCall is also de-duplicated per callId (an in-flight guard cleared in finally) so concurrent accept paths can't double-accept or double-end.

Issue(s)

https://rocketchat.atlassian.net/browse/NATIVE-1139

How to test or reproduce

  1. Fresh install or revoke microphone permission for Rocket.Chat.
  2. Receive an incoming VoIP call and accept it from CallKit/Telecom.
  3. Deny the microphone prompt → call should end promptly with an informational alert (no ~10s hang).
  4. Repeat with permission permanently denied (Android "Don't ask again" / iOS denied in Settings) → accept call → alert should offer Settings.
  5. Grant permission when prompted → call should connect normally.
  6. Outgoing call without permission → should not place the call and should show the same denial alert.

Screenshots

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change which improves a current function)
  • New feature (non-breaking change which adds functionality)
  • Documentation update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works (if applicable)
  • I have added necessary documentation (if applicable)
  • Any dependent changes have been merged and published in downstream modules

Further comments

  • Hangs up on denial rather than keeping CallKit active without audio.
  • No countdown UI; no server-side timeout extension.
  • Future proactive permission at VoIP init can build on the shared requestVoipCallPermissions helper.
  • Addressed self-review + CodeRabbit feedback: never-reject permission helper, answerCall idempotency guard, simplified permission branch, collapsed denial-alert variants, and expanded tests (iOS live-prompt denial, permission-throw paths, concurrency, denied-answer wire signal).
  • Cross-file dedup with MicOrSendButton (shared alert + microphone-request helper) is tracked in NATIVE-1198; the locked/backgrounded iOS prompt limitation is inherent to a reactive gate and left to a future proactive init-time gate.

Made with Cursor

Summary by CodeRabbit

  • Improvements

    • Unified cross-platform microphone permission flow returning structured grant info; prompts occur before accepting or starting calls.
    • Added deduplication to prevent concurrent answer/start race conditions.
  • New Features

    • Context-aware microphone-denied alert with different buttons/behavior depending on whether users can be prompted again.
  • Bug Fixes

    • Calls now end cleanly when permissions are denied and avoid erroneous accept/start behavior.
  • Tests

    • Expanded unit and integration coverage for permission scenarios, alert behavior, and concurrency.

Request mic access before accept() so denied permissions hang up immediately
instead of stalling signaling until the 10s timeout. Adds settings redirect
for permanent denial on both platforms.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

Review Change Stack

Walkthrough

Refactors VoIP microphone permission handling to return { granted, canAskAgain } instead of a boolean, adds showVoipMicrophoneDeniedAlert, implements cross-platform permission requests, and updates MediaSessionInstance flows and tests to use the new contract.

Changes

VoIP Permissions API Refactor

Layer / File(s) Summary
Permission contract and implementation
app/lib/methods/voipCallPermissions.ts
VoipCallPermissionResult type added. requestVoipCallPermissions now returns { granted, canAskAgain }, handling Android (PermissionsAndroid.request) and non-Android (expo-av) flows. showVoipMicrophoneDeniedAlert(canAskAgain) added.
Permission tests and alert tests
app/lib/methods/voipCallPermissions.test.ts
Tests updated/mocked for expo-av, Android permission outcomes, and Alert behavior; assertions changed from boolean to { granted, canAskAgain }.
MediaSessionInstance integration and tests
app/lib/services/voip/MediaSessionInstance.ts, app/lib/services/voip/MediaSessionInstance.test.ts
answerCall and startCall now await permissions, use an idempotency guard for answers, end/abort flows or show denial alerts based on permission.granted and permission.canAskAgain. Tests updated with new mocks, added de-duplication and denied-permission cases.
Integration test alignment
app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
Integration mock updated so requestVoipCallPermissions resolves to { granted: true, canAskAgain: true }.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Suggested reviewers

  • OtavioStasiak
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately summarizes the main change: ensuring incoming VoIP call acceptance is gated on microphone permission request, which is the primary objective across all modified files.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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)
  • NATIVE-1139: 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.

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/lib/methods/voipCallPermissions.ts`:
- Around line 13-37: The requestVoipCallPermissions function currently calls
PermissionsAndroid.request, Audio.getPermissionsAsync, and
Audio.requestPermissionsAsync without handling rejections; wrap the entire body
of requestVoipCallPermissions in a try/catch, catch any thrown errors from
PermissionsAndroid, Audio, or permission calls, log the error (e.g. via
console.error or the app logger) including which API failed, and return a safe
denied result { granted: false, canAskAgain: false } on failure so callers get a
controlled denial UX; ensure references to PermissionsAndroid, Audio, and
PermissionStatus remain intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bcdcc091-13c0-4ccd-8875-cbb71589521d

📥 Commits

Reviewing files that changed from the base of the PR and between 3961d4d and b5309c7.

📒 Files selected for processing (5)
  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
  • app/lib/methods/voipCallPermissions.test.ts
  • app/lib/methods/voipCallPermissions.ts
  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
  • app/lib/methods/voipCallPermissions.ts
  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
  • app/lib/methods/voipCallPermissions.test.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Use TypeScript with strict mode and baseUrl set to app/ for import resolution

Files:

  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
  • app/lib/methods/voipCallPermissions.ts
  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
  • app/lib/methods/voipCallPermissions.test.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx,js,jsx}: Use Prettier with tabs, single quotes, 130 char width, no trailing commas, arrow parens avoid, bracket same line
Use @rocket.chat/eslint-config base with React, React Native, TypeScript, Jest plugins

Files:

  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
  • app/lib/methods/voipCallPermissions.ts
  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
  • app/lib/methods/voipCallPermissions.test.ts
app/containers/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Reusable UI components should be placed in app/containers/ directory

Files:

  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
app/lib/services/voip/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

VoIP service implementation should use Zustand stores (not Redux) and include native CallKit (iOS) and Telecom (Android) integration in app/lib/services/voip/

Files:

  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
🧠 Learnings (1)
📚 Learning: 2026-04-30T17:07:51.020Z
Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7274
File: app/lib/services/voip/MediaCallEvents.ts:0-0
Timestamp: 2026-04-30T17:07:51.020Z
Learning: In this Rocket.Chat React Native codebase, the ESLint rule `no-void: error` is enforced. When you see a promise returned from an async call that is not awaited (a “floating promise”), do not silence it with the `void somePromise()` pattern. Instead, handle the promise explicitly by attaching `.catch(...)` (or otherwise awaiting/handling the error) so unhandled-rejection risks are addressed in a way that satisfies the existing ESLint configuration.

Applied to files:

  • app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
  • app/lib/methods/voipCallPermissions.ts
  • app/lib/services/voip/MediaSessionInstance.test.ts
  • app/lib/services/voip/MediaSessionInstance.ts
  • app/lib/methods/voipCallPermissions.test.ts
🔇 Additional comments (5)
app/lib/methods/voipCallPermissions.test.ts (1)

1-144: LGTM!

app/lib/services/voip/MediaSessionInstance.ts (1)

36-37: LGTM!

Also applies to: 176-181, 238-241

app/lib/services/voip/MediaSessionInstance.test.ts (1)

132-137: LGTM!

Also applies to: 248-249, 700-709, 877-915

app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx (1)

142-142: LGTM!

app/lib/methods/voipCallPermissions.ts (1)

3-3: ⚡ Quick win

Expo-av Audio.getPermissionsAsync() status can be compared to expo-camera’s PermissionStatus
Audio.getPermissionsAsync() (expo-av) and PermissionStatus used by expo-camera both come from Expo’s shared expo-modules-core enum, so the comparison isn’t a brittle cross-package contract (app/lib/methods/voipCallPermissions.ts, lines 3 and 29). Optionally, import PermissionStatus from expo-modules-core for clarity.

			> Likely an incorrect or invalid review comment.

Comment thread app/lib/methods/voipCallPermissions.ts
@github-actions
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

iOS Build Available

Rocket.Chat 4.73.0.108986

Copy link
Copy Markdown
Member Author

@diegolmello diegolmello left a comment

Choose a reason for hiding this comment

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

Code review — incoming VoIP mic-permission gate

Solid fix on the happy path with good unit coverage. The main risks are on the error / background path of the incoming-answer flow (where the new await was inserted), plus some duplication with the existing audio-recording permission code in MicOrSendButton. Inline comments below, roughly highest-severity first.

Verified non-issues: PermissionStatus from expo-camera matches expo-av's status enum (both re-export from expo-modules-core; same pattern already ships in MicOrSendButton); Android result !== NEVER_ASK_AGAIN covers all return values; all i18n keys (Ok/Cancel/Settings/…) exist; no dead imports.

Comment thread app/lib/services/voip/MediaSessionInstance.ts Outdated
Comment thread app/lib/services/voip/MediaSessionInstance.ts Outdated
Comment thread app/lib/services/voip/MediaSessionInstance.ts Outdated
Comment thread app/lib/methods/voipCallPermissions.ts Outdated
Comment thread app/lib/methods/voipCallPermissions.ts
Comment thread app/lib/methods/voipCallPermissions.ts Outdated
Comment thread app/lib/methods/voipCallPermissions.ts Outdated
Comment thread app/lib/methods/voipCallPermissions.test.ts
Comment thread app/lib/services/voip/MediaSessionInstance.test.ts
- requestVoipCallPermissions never rejects: a thrown permission check is
  treated as denied + logged, so a locked/backgrounded answer ends promptly
  instead of hanging until the 10s signaling timeout
- answerCall dedupes concurrent invocations per callId (in-flight Set,
  cleared in finally) to restore the idempotency its doc comment claims
- simplify the iOS permission branch and collapse the denied-mic alert
  variants into a single Alert.alert call
- cover the iOS live-prompt denial and permission-throw paths; tighten the
  denied-answer test to assert the reject() wire signal and native teardown
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

iOS Build Available

Rocket.Chat 4.73.0.109006

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant