Skip to content

Conversation

@Brazol
Copy link
Contributor

@Brazol Brazol commented Sep 7, 2025

resolves FLU-245, #1057

This PR fixes an issue on iOS where rapidly toggling the camera could trigger an error related to AVCaptureMultiCamSession. The multitasking camera is now enabled once and remains enabled, rather than being repeatedly toggled with each camera switch.

Summary by CodeRabbit

  • Bug Fixes

    • Improved iOS camera behavior in multitasking: it’s now enabled once and retained, preventing errors when rapidly toggling the camera during calls. Enhances stability and reliability in multitasking scenarios.
  • Documentation

    • Added an Unreleased section to the changelog noting the iOS multitasking camera fix.

@Brazol Brazol requested a review from a team as a code owner September 7, 2025 15:58
@coderabbitai
Copy link

coderabbitai bot commented Sep 7, 2025

Walkthrough

Adds an Unreleased changelog entry documenting an iOS camera multitasking fix. In code, updates setCameraEnabled to conditionally enable iOS multitasking camera access only once and persist its state, preventing repeated enable calls when toggling the camera.

Changes

Cohort / File(s) Summary
Changelog Update
packages/stream_video/CHANGELOG.md
Adds Unreleased section with a Fixed note about iOS multitasking camera enablement behavior during quick camera toggles.
Call Flow: iOS Multitasking Guard
packages/stream_video/lib/src/call/call.dart
Wraps iOS multitasking camera access enabling in a conditional executed only when turning on the camera and not yet enabled; tracks result locally and updates state accordingly.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Call UI
  participant Call as Call.setCameraEnabled
  participant iOS as iOS Camera API
  participant SM as StateManager

  User->>UI: Toggle Camera (on/off)
  UI->>Call: setCameraEnabled(enabled)
  alt enabled == true
    Call->>SM: Read iOSMultitaskingCameraAccessEnabled
    opt if not enabled yet
      Call->>iOS: setMultitaskingCameraAccessEnabled(true)
      iOS-->>Call: result (enabled/err)
      Call->>SM: Update multitaskingEnabled state
    end
    Call->>SM: participantSetCameraEnabled(true, multitaskingEnabled)
  else enabled == false
    Call->>SM: participantSetCameraEnabled(false, current multitaskingEnabled)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Assessment against linked issues

Objective Addressed Explanation
FLU-245: Prevent iOS exception when rapidly toggling camera by not re-enabling multitasking repeatedly (#1057)

Assessment against linked issues: Out-of-scope changes

(None)

Possibly related PRs

Suggested reviewers

  • renefloor

Poem

I flipped the cam with hoppy glee,
No more crashes—what a spree!
One enable, held just right,
Multitask moon in gentle light.
Tap-tap joy, no frantic frights—
Bunny dev ships calmer nights. 🐇✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • Failed to retrieve linked issues from the platform client.
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fix-multitasking-camera-enabling

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.

Copy link

@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: 0

🧹 Nitpick comments (3)
packages/stream_video/CHANGELOG.md (1)

3-4: Polish the entry for clarity and consistency.

Minor grammar and style tweak; also cross-reference the issue.

-🐞 Fixed
-* Multitasking camera on iOS is now enabled only once and kept enabled. This fixes potential errors when quickly toggling camera.
+🐞 Fixed
+* Multitasking camera on iOS is now enabled only once and kept enabled, preventing errors when rapidly toggling the camera. See #1057.
packages/stream_video/lib/src/call/call.dart (2)

2604-2612: Avoid unnecessary platform call and preserve previous state on failure.

  • Skip the helper call when we know we won’t enable (mute-in-background).
  • Don’t overwrite to false on failure; retain previous state to avoid UI/state drift.
-      var multitaskingEnabled = state.value.iOSMultitaskingCameraAccessEnabled;
-      if (enabled && !multitaskingEnabled) {
-        // Set multitasking camera access for iOS
-        final multitaskingResult = await setMultitaskingCameraAccessEnabled(
-          enabled && !_streamVideo.options.muteVideoWhenInBackground,
-        );
-
-        multitaskingEnabled = multitaskingResult.getDataOrNull() ?? false;
-      }
+      var multitaskingEnabled = state.value.iOSMultitaskingCameraAccessEnabled;
+      final shouldEnableMultitasking = enabled &&
+          !multitaskingEnabled &&
+          !_streamVideo.options.muteVideoWhenInBackground;
+      if (shouldEnableMultitasking) {
+        // Set multitasking camera access for iOS
+        final multitaskingResult =
+            await setMultitaskingCameraAccessEnabled(true);
+        // Preserve previous value if the call fails.
+        multitaskingEnabled =
+            multitaskingResult.getDataOrNull() ?? multitaskingEnabled;
+      }

2632-2634: Correct permission error message.

Minor copy fix: it’s audio, not video.

-    if (enabled && !hasPermission(CallPermission.sendAudio)) {
-      return Result.error('Missing permission to send video');
+    if (enabled && !hasPermission(CallPermission.sendAudio)) {
+      return Result.error('Missing permission to send audio');
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e583759 and e94dbcc.

📒 Files selected for processing (2)
  • packages/stream_video/CHANGELOG.md (1 hunks)
  • packages/stream_video/lib/src/call/call.dart (1 hunks)
⏰ 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). (8)
  • GitHub Check: stream_video_screen_sharing
  • GitHub Check: stream_video_noise_cancellation
  • GitHub Check: stream_video_push_notification
  • GitHub Check: stream_video_flutter
  • GitHub Check: stream_video
  • GitHub Check: build
  • GitHub Check: analyze_legacy_version
  • GitHub Check: analyze
🔇 Additional comments (1)
packages/stream_video/lib/src/call/call.dart (1)

2604-2617: Good fix: enable once, keep enabled.

This guards against repeated enable/disable flapping on iOS and should mitigate the AVCaptureMultiCamSession exception during rapid toggles.

@codecov
Copy link

codecov bot commented Sep 7, 2025

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 4.83%. Comparing base (e583759) to head (e94dbcc).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
packages/stream_video/lib/src/call/call.dart 0.00% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #1061      +/-   ##
========================================
- Coverage   4.83%   4.83%   -0.01%     
========================================
  Files        577     577              
  Lines      38830   38831       +1     
========================================
  Hits        1877    1877              
- Misses     36953   36954       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Brazol Brazol merged commit 873dc55 into main Sep 16, 2025
13 of 15 checks passed
@Brazol Brazol deleted the fix/fix-multitasking-camera-enabling branch September 16, 2025 09:18
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.

3 participants