Skip to content

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

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

fix(voip): gate incoming answer on microphone permission#7354
diegolmello wants to merge 2 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.

Issue(s)

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.

Made with Cursor

Summary by CodeRabbit

  • Improvements
    • Refined microphone permission flow for VoIP on iOS and Android with clearer grant/ask-repeat handling.
    • Permission prompts are requested before accepting or starting calls.
  • Bug Fixes
    • Calls now end gracefully when microphone permission is denied; users see a tailored alert directing next steps.
  • Tests
    • Expanded test coverage for permission scenarios and denied-alert behavior.

Review Change Stack

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

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ccd4112b-2b50-42d5-a5ef-70e5bd3e8aa8

📥 Commits

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

📒 Files selected for processing (1)
  • app/lib/methods/voipCallPermissions.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/lib/methods/voipCallPermissions.test.ts

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 request contract and implementation
app/lib/methods/voipCallPermissions.ts, app/lib/methods/voipCallPermissions.test.ts
VoipCallPermissionResult type added. requestVoipCallPermissions now returns { granted, canAskAgain }, handling Android (PermissionsAndroid.request) and non-Android (expo-av) flows. showVoipMicrophoneDeniedAlert(canAskAgain) added to show dismiss-only or settings-prompt alerts. Tests cover iOS and Android states with full mocks and verify Alert calls.
MediaSessionInstance permission handling
app/lib/services/voip/MediaSessionInstance.ts, app/lib/services/voip/MediaSessionInstance.test.ts
answerCall and startCall now await permissions and end/abort flows or show denial alerts based on permission.granted and permission.canAskAgain. Tests update mocks, defaults, and add cases for startCall denial and answerCall recovery.
Integration test alignment
app/containers/NewMediaCall/VoipCallLifecycle.integration.test.tsx
Updated requestVoipCallPermissions mock to return { granted: true, canAskAgain: true }.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

type: bug

Suggested reviewers

  • OtavioStasiak
🚥 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 'fix(voip): gate incoming answer on microphone permission' clearly and specifically describes the main change: gating the acceptance of incoming VoIP calls on microphone permission checks.
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.


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 on lines +13 to +37
export const requestVoipCallPermissions = async (): Promise<VoipCallPermissionResult> => {
if (Platform.OS === 'android') {
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO);
if (result === PermissionsAndroid.RESULTS.GRANTED) {
return { granted: true, canAskAgain: true };
}
return {
granted: false,
canAskAgain: result !== PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN
};
}

const { granted, status, canAskAgain } = await Audio.getPermissionsAsync();
if (granted) {
return { granted: true, canAskAgain: true };
}
if (status === PermissionStatus.UNDETERMINED || canAskAgain) {
const requested = await Audio.requestPermissionsAsync();
return {
granted: requested.granted,
canAskAgain: requested.canAskAgain ?? false
};
}
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO);
return result === PermissionsAndroid.RESULTS.GRANTED;
return { granted: false, canAskAgain: false };
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Add defensive error handling around permission API calls.

If any permission API rejects, this helper throws and can break call flows instead of failing closed with a controlled denial UX. Wrap this function body in try/catch and return a safe denied result (plus logging) on failure.

As per coding guidelines, "Use explicit error handling with try/catch blocks for async operations".

🤖 Prompt for 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.

In `@app/lib/methods/voipCallPermissions.ts` around lines 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.

@github-actions
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

iOS Build Available

Rocket.Chat 4.73.0.108986

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