Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented May 3, 2025

Link issues

fixes #5954

Summary By Copilot

This pull request introduces a new AudioDevices component to the BootstrapBlazor project, enabling audio device management and recording capabilities. It also includes updates to the existing VideoDevices component and shared media device interfaces to support both audio and video operations. The changes span across UI components, service interfaces, and JavaScript modules.

New AudioDevices Component:

  • Added AudioDevices.razor to provide a UI for listing, opening, and closing audio devices. The component integrates with the IAudioDevice service for device management.
  • Implemented AudioDevices.razor.cs with methods for requesting devices, opening audio streams, and handling disposal.
  • Introduced CSS styles in AudioDevices.razor.css for audio device UI elements.

Shared Media Device Enhancements:

  • Added IAudioDevice interface and DefaultAudioDevice implementation for audio device operations, including methods for listing, opening, and closing devices. [1] [2]
  • Updated IMediaDevices and DefaultMediaDevices to support both audio and video operations by introducing a type parameter for Open and Close methods. [1] [2]
  • Modified IVideoDevice and DefaultVideoDevice to align with the updated IMediaDevices interface. [1] [2]

JavaScript Module Updates:

  • Enhanced media.js to support audio recording via a new record function and added methods for stopping audio streams. Refactored video-related methods to accommodate the shared interface. [1] [2]

Localization and Documentation:

  • Updated en-US.json and zh-CN.json localization files with new strings for the AudioDevices component. [1] [2] [3] [4]
  • Added audio-device to docs.json for documentation purposes.

Minor Updates to VideoDevices:

  • Renamed VideoSelector to Selector in MediaTrackConstraints for consistency with audio operations.
  • Adjusted method signatures and logic in VideoDevices.razor and VideoDevices.razor.cs to align with the updated IMediaDevices interface. [1] [2] [3]

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add support for audio device management and recording in the BootstrapBlazor framework, extending the existing media device capabilities to include audio input devices

New Features:

  • Introduced IAudioDevice service for managing audio input devices
  • Added AudioDevices component for listing, opening, and closing audio devices
  • Implemented audio recording functionality in the media JavaScript module

Enhancements:

  • Updated media device interfaces to support both audio and video operations
  • Refactored existing video device methods to use a more generic approach
  • Added type parameter to media device open and close methods

Documentation:

  • Updated localization files with new audio device strings
  • Added audio device documentation entry

Tests:

  • Added unit tests for AudioDevice service
  • Updated existing video device tests to support new interface

@ArgoZhang ArgoZhang requested a review from Copilot May 3, 2025 11:32
@bb-auto bb-auto bot added the enhancement New feature or request label May 3, 2025
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 3, 2025

Reviewer's Guide

This pull request introduces audio device functionality by adding the IAudioDevice service and the AudioDevices Razor component. It refactors the core IMediaDevices service and corresponding JavaScript module (media.js) to handle both audio and video devices through a unified interface, updating the existing VideoDevices component accordingly.

File-Level Changes

Change Details Files
Added the IAudioDevice service, DefaultAudioDevice implementation, AudioDevices component, and unit tests.
  • Defined the IAudioDevice interface for audio device operations.
  • Implemented DefaultAudioDevice using the shared IMediaDevices service.
  • Created the AudioDevices.razor component for UI interaction.
  • Added unit tests for the AudioDevice service.
src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultAudioDevice.cs
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.cs
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.css
test/UnitTest/Services/AudioDeviceTest.cs
Generalized IMediaDevices and IVideoDevice to support both audio and video types.
  • Added a 'type' parameter ('audio' or 'video') to IMediaDevices.Open and IMediaDevices.Close.
  • Updated DefaultMediaDevices implementation to use the 'type' parameter.
  • Modified IVideoDevice and DefaultVideoDevice to call the generalized IMediaDevices methods with type 'video'.
  • Renamed MediaTrackConstraints.VideoSelector to Selector for general use.
  • Updated VideoDevices component and tests to use the generalized interface and renamed property.
src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs
src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs
src/BootstrapBlazor/Services/MediaDevices/MediaTrackConstraints.cs
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs
test/UnitTest/Services/VideoDeviceTest.cs
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor
Enhanced media.js to handle audio recording and unified device interactions.
  • Added a new record function for audio recording using MediaRecorder.
  • Added a stop function to stop audio recording.
  • Refactored open and close functions to accept a 'type' parameter and delegate to type-specific functions (openVideoDevice, closeVideoDevice, record, stop).
src/BootstrapBlazor/wwwroot/modules/media.js
Registered the new service and updated localization and documentation.
  • Registered IAudioDevice and DefaultAudioDevice in service collection.
  • Added localization strings for the AudioDevices component.
  • Added 'audio-device' entry to documentation configuration.
  • Updated menu localization.
src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
src/BootstrapBlazor.Server/docs.json
src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5954 Add IAudioDevice service to the BootstrapBlazor project.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto bot added this to the v9.6.0 milestone May 3, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces audio device management to the BootstrapBlazor project by adding a new IAudioDevice service and AudioDevices component while updating existing media device interfaces and samples for unified audio/video operations.

  • Introduces AudioDevices component and IAudioDevice/DefaultAudioDevice implementation for audio management.
  • Updates media interfaces, DefaultMediaDevices, and related JS modules to support a unified "Selector" property across audio and video devices.
  • Provides new tests and documentation updates to validate the audio device functionality.

Reviewed Changes

Copilot reviewed 16 out of 20 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/UnitTest/Services/VideoDeviceTest.cs Updated tests for video device, replacing VideoSelector with Selector and adding an audio device in the enumeration.
test/UnitTest/Services/AudioDeviceTest.cs New tests verifying audio device functionality using the new IAudioDevice interface.
src/BootstrapBlazor/wwwroot/modules/media.js Enhanced JS module to support open(type, options) and audio recording; refactored close handling for device streams.
src/BootstrapBlazor/Services/MediaDevices/MediaTrackConstraints.cs Replaced the VideoSelector property with a unified Selector property.
src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs Updated parameter name to Selector for consistency.
src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs Modified the Open and Close methods to include a type parameter.
src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs New interface for managing audio devices.
src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs Adjusted to call Open with a type parameter ("video") and use Selector.
src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs Updated open/close calls to support the type parameter and Selector.
src/BootstrapBlazor/Services/MediaDevices/DefaultAudioDevice.cs New implementation for audio device management using the updated media service.
src/BootstrapBlazor/Extensions/BootstrapBlazorServiceCollectionExtensions.cs Registered the new IAudioDevice service.
src/BootstrapBlazor/Server/Extensions/MenusLocalizerExtensions.cs Updated menu entries to include audio device routes.
src/BootstrapBlazor/Server/Components/Samples/VideoDevices.razor(.cs) Updated samples for video devices to use Selector instead of VideoSelector.
src/BootstrapBlazor/Server/Components/Samples/AudioDevices.razor(.cs) Added new audio device sample component and page.
Files not reviewed (4)
  • src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.css: Language not supported
  • src/BootstrapBlazor.Server/Locales/en-US.json: Language not supported
  • src/BootstrapBlazor.Server/Locales/zh-CN.json: Language not supported
  • src/BootstrapBlazor.Server/docs.json: Language not supported

sourcery-ai[bot]
sourcery-ai bot previously approved these changes May 3, 2025
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @ArgoZhang - I've reviewed your changes - here's some feedback:

  • Consider if the shared IMediaDevices interface could be refactored to avoid using string parameters ('audio', 'video') for differentiating device types in the Open and Close methods.
  • In media.js, consider renaming the record function to openAudioDevice for better naming consistency with openVideoDevice.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov
Copy link

codecov bot commented May 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (9fccdad) to head (2e1ac21).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5955   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          669       670    +1     
  Lines        30559     30576   +17     
  Branches      4349      4350    +1     
=========================================
+ Hits         30559     30576   +17     

☔ 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.

@ArgoZhang ArgoZhang merged commit 2f518f9 into main May 3, 2025
5 checks passed
@ArgoZhang ArgoZhang deleted the feat-audio branch May 3, 2025 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(IAudioDevice): add IAudioDevice service

2 participants