Skip to content

Conversation

@Brazol
Copy link
Contributor

@Brazol Brazol commented Jun 9, 2025

part of FLU-164

🎯 Goal

Audio interruptions occur when the system or other applications take control of the audio session, temporarily pausing or stopping your app's audio. By implementing this added method, we enable users to respond to those interruptions, such as muting the microphone during an ongoing call.

🛠 Implementation details

Added handleCallInterruptionCallbacks to RtcMediaDeviceNotifier
Added sample handling (muting the microphone) in the Dogfooding app

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Automatically manages microphone state during mobile call interruptions, muting and restoring as needed.
    • Requests phone permission on Android devices to support call interruption handling.
  • Improvements

    • Enhanced support for detecting and responding to system audio interruptions on Android and iOS.
    • Added new system permissions for improved phone and call state handling on Android.
  • Chores

    • Updated stream_webrtc_flutter dependency to version 1.0.7 across multiple packages for improved compatibility.

@Brazol Brazol requested a review from a team as a code owner June 9, 2025 11:41
@coderabbitai
Copy link

coderabbitai bot commented Jun 9, 2025

Walkthrough

The changes introduce system audio interruption handling for mobile calls by adding new permission declarations in the AndroidManifest, implementing microphone state management during interruptions in the app, and exposing new interruption event classes and callback registration methods in the WebRTC notifier. Android-specific phone permission requests are also added to the home screen initialization.

Changes

File(s) Change Summary
dogfooding/android/app/src/main/AndroidManifest.xml Added READ_PHONE_STATE and READ_CALL_STATE permissions.
dogfooding/lib/app/app_content.dart Added mobile audio interruption handling: disables/enables mic during system interruptions.
dogfooding/lib/screens/home_screen.dart Requests phone permission on Android during initialization.
packages/stream_video/lib/src/webrtc/rtc_media_device/rtc_media_device_notifier.dart Added InterruptionEvent classes and handleCallInterruptionCallbacks method with documentation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AppContent
    participant RtcMediaDeviceNotifier
    participant StreamVideo

    AppContent->>RtcMediaDeviceNotifier: handleCallInterruptionCallbacks(onBegin, onEnd)
    RtcMediaDeviceNotifier->>RtcMediaDeviceNotifier: Register interruption callbacks

    Note over AppContent,RtcMediaDeviceNotifier: During a mobile call...

    RtcMediaDeviceNotifier-->>AppContent: InterruptionBeginEvent
    AppContent->>StreamVideo: setMicrophoneEnabled(false)

    RtcMediaDeviceNotifier-->>AppContent: InterruptionEndEvent
    AppContent->>StreamVideo: setMicrophoneEnabled(true)
Loading

Assessment against linked issues

Objective Addressed Explanation
Mute livestream host microphone when SIM call is answered (FLU-164)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes detected.

Poem

In the land of code, where calls may roam,
Now interruptions won’t silence alone.
The mic bows down when a call comes through,
Then hops back up, as rabbits do!
With permissions in paw and events in the air,
Mobile calls handled with bunny care.
🐇🎤📱


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3ef02db and 6bd911e.

📒 Files selected for processing (2)
  • packages/stream_video/CHANGELOG.md (1 hunks)
  • packages/stream_video_flutter/CHANGELOG.md (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • packages/stream_video_flutter/CHANGELOG.md
  • packages/stream_video/CHANGELOG.md
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: stream_video_screen_sharing
  • GitHub Check: stream_video_flutter
  • GitHub Check: stream_video
  • GitHub Check: stream_video_push_notification
  • GitHub Check: analyze_legacy_version
  • GitHub Check: stream_video_noise_cancellation
  • GitHub Check: analyze
  • GitHub Check: build

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 1

🧹 Nitpick comments (3)
dogfooding/lib/screens/home_screen.dart (1)

52-54: LGTM! Proper platform-specific permission handling.

The conditional phone permission request for Android aligns correctly with the manifest permissions (READ_PHONE_STATE and READ_CALL_STATE) added in dogfooding/android/app/src/main/AndroidManifest.xml. The platform check ensures this only runs on Android where these permissions are relevant.

Consider handling permission denial gracefully to inform users if phone interruption features may not work:

  if (CurrentPlatform.isAndroid) {
-   Permission.phone.request();
+   final phonePermission = await Permission.phone.request();
+   if (phonePermission.isDenied) {
+     debugPrint('Phone permission denied - call interruption detection may not work');
+   }
  }
packages/stream_video/lib/src/webrtc/rtc_media_device/rtc_media_device_notifier.dart (2)

12-16: LGTM! Clean event class hierarchy.

The abstract InterruptionEvent base class with concrete InterruptionBeginEvent and InterruptionEndEvent implementations provides a solid foundation for interruption event handling.

Consider if these event classes will be exposed in the public API later, as they're currently defined but not used in the method signature. If they're for future use, consider adding documentation comments.


31-66: Excellent documentation and implementation!

The method provides comprehensive documentation covering platform-specific interruption sources and includes practical usage guidance. The delegation to the underlying RTC implementation is appropriate.

Consider mentioning that the READ_PHONE_STATE permission is required in the manifest for Android telephony interruptions:

  /// - With telephony:
- ///   - Phone calls (requires READ_PHONE_STATE permission)
+ ///   - Phone calls (requires READ_PHONE_STATE and READ_CALL_STATE permissions in AndroidManifest.xml)

Also consider documenting error handling expectations:

  /// This method allows you to pause the call, mute the audio, or perform any other
  /// necessary actions when interruptions occur.
  ///
+ /// Note: Ensure proper error handling in your callback implementations as they
+ /// will be called from the native platform layer.
+ ///
  /// For more details on handling call interruptions, refer to the
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ca6f77 and 66cc167.

📒 Files selected for processing (4)
  • dogfooding/android/app/src/main/AndroidManifest.xml (1 hunks)
  • dogfooding/lib/app/app_content.dart (3 hunks)
  • dogfooding/lib/screens/home_screen.dart (1 hunks)
  • packages/stream_video/lib/src/webrtc/rtc_media_device/rtc_media_device_notifier.dart (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: stream_video_flutter
  • GitHub Check: stream_video_push_notification
  • GitHub Check: stream_video_noise_cancellation
  • GitHub Check: stream_video_screen_sharing
  • GitHub Check: stream_video
  • GitHub Check: analyze_legacy_version
  • GitHub Check: build
  • GitHub Check: analyze
🔇 Additional comments (3)
dogfooding/android/app/src/main/AndroidManifest.xml (1)

14-15: LGTM! Permissions are appropriate for audio interruption handling.

The READ_PHONE_STATE and READ_CALL_STATE permissions are correctly added to support Android phone call interruption detection. These permissions align with the runtime permission request added in dogfooding/lib/screens/home_screen.dart at lines 52-54.

dogfooding/lib/app/app_content.dart (2)

16-16: LGTM! Appropriate import for WebRTC functionality.

The import with alias rtc is correctly used for accessing the underlying WebRTC interruption handling capabilities.


109-109: LGTM! Good placement for initialization.

Calling _handleMobileAudioInterruptions() in initState ensures the audio interruption handling is set up early in the app lifecycle.

@codecov
Copy link

codecov bot commented Jun 10, 2025

Codecov Report

Attention: Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.

Project coverage is 3.01%. Comparing base (426e1c7) to head (6bd911e).

Files with missing lines Patch % Lines
...tc/rtc_media_device/rtc_media_device_notifier.dart 0.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #984      +/-   ##
========================================
- Coverage   3.01%   3.01%   -0.01%     
========================================
  Files        571     571              
  Lines      38384   38386       +2     
========================================
  Hits        1156    1156              
- Misses     37228   37230       +2     

☔ 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 changed the title feat: added method with callbacks to handling audio interruptions (iOS, Android) feat(llc): added method with callbacks to handling audio interruptions (iOS, Android) Jun 12, 2025
@Brazol Brazol changed the title feat(llc): added method with callbacks to handling audio interruptions (iOS, Android) feat(llc, ui): added method with callbacks to handling audio interruptions (iOS, Android) Jun 12, 2025
Brazol added 2 commits June 12, 2025 17:45
…am/stream-video-flutter into feat/audio-interruption-handling
@Brazol Brazol merged commit da2f881 into main Jun 12, 2025
14 of 15 checks passed
@Brazol Brazol deleted the feat/audio-interruption-handling branch June 12, 2025 18:24
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