Skip to content

Conversation

@ArgoZhang
Copy link
Member

@ArgoZhang ArgoZhang commented May 5, 2025

Link issues

fixes #5966

Summary By Copilot

This pull request introduces functionality for downloading audio recordings, along with supporting changes to services, UI components, localization files, and unit tests. The most significant updates include adding a new "Download" button to the audio device UI, implementing the backend methods to retrieve audio data, and extending the localization files to support the new feature.

New Audio Download Feature:

  • UI Updates: Added a "Download" button to the AudioDevices.razor component, which is enabled after recording is stopped. (src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor)
  • Backend Service Changes:
    • Introduced GetData method in IAudioDevice and IMediaDevices interfaces to fetch audio streams. (src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs, src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs) [1] [2]
    • Implemented GetAudioData in DefaultAudioDevice and DefaultMediaDevices to handle audio stream retrieval. (src/BootstrapBlazor/Services/MediaDevices/DefaultAudioDevice.cs, src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs) [1] [2]
    • Added getAudioData function to media.js for JavaScript interop to retrieve the audio blob. (src/BootstrapBlazor/wwwroot/modules/media.js)

Localization and Test Updates:

  • Localization: Updated en-US.json and zh-CN.json files to include translations for the new "Download" button text. (src/BootstrapBlazor.Server/Locales/en-US.json, src/BootstrapBlazor.Server/Locales/zh-CN.json) [1] [2]
  • Unit Tests: Extended AudioDeviceTest to verify the new GetData functionality, including mocking the JavaScript stream reference and asserting the audio stream's length. (test/UnitTest/Services/AudioDeviceTest.cs) [1] [2]

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 audio download functionality to the media device services, enabling users to download recorded audio streams with a new download button in the UI.

New Features:

  • Implemented GetData method for audio devices to retrieve recorded audio streams
  • Added a download button to the audio devices UI
  • Introduced JavaScript interop to support audio data retrieval

Enhancements:

  • Extended media device interfaces to support audio data retrieval
  • Updated audio device components to enable download functionality

Tests:

  • Added unit tests to verify audio data retrieval functionality

@ArgoZhang ArgoZhang requested a review from Copilot May 5, 2025 08:18
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented May 5, 2025

Reviewer's Guide

This pull request introduces audio download functionality by adding a GetData method to the IAudioDevice interface. The implementation retrieves the recorded audio stream via JavaScript interop, exposes it through the DefaultMediaDevices service, and adds a download button to the AudioDevices component.

File-Level Changes

Change Details Files
Added GetData method to audio device interfaces and implemented it.
  • Defined GetData in IAudioDevice interface.
  • Defined GetAudioData in IMediaDevices interface.
  • Implemented GetData in DefaultAudioDevice by calling deviceService.GetAudioData().
  • Implemented GetAudioData in DefaultMediaDevices using JS interop to invoke getAudioData and return the stream.
src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs
src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultAudioDevice.cs
src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs
Added JavaScript function to retrieve the recorded audio blob.
  • Stored the recorded audio blob in media.audioBlob during the record function.
  • Added getAudioData function to return the stored media.audioBlob.
src/BootstrapBlazor/wwwroot/modules/media.js
Updated UI component to include a download button and associated logic.
  • Added a 'Download' button, enabled after recording stops.
  • Injected DownloadService.
  • Added OnDownload method to fetch the audio stream using AudioDeviceService.GetData() and trigger download via DownloadService.
  • Set a flag _isDownload when closing the audio device to control button state.
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.cs
Added unit tests for the new audio data retrieval functionality.
  • Mocked the getAudioData JS interop call to return a MockJSStreamReference.
  • Added assertions to verify that GetData returns a non-null stream with expected length.
test/UnitTest/Services/AudioDeviceTest.cs
Updated localization files with text for the new download button.
  • Added AudioDeviceDownloadText key and translations.
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
Updated video device sample to include timestamp in downloaded filename.
  • Modified filename format in OnDownload to include DateTime.Now:HHmmss.
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#5966 Add a GetData method to the IVideoDevice interface.

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 the enhancement New feature or request label May 5, 2025
@bb-auto bb-auto bot added this to the v9.6.0 milestone May 5, 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 adds a new audio download feature to the audio device functionality. Key changes include updates to service interfaces and implementations to expose audio stream data, modifications in the JavaScript module to support audio blob retrieval, and UI updates in both AudioDevices.razor and VideoDevices.razor to integrate download functionality.

Reviewed Changes

Copilot reviewed 9 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/UnitTest/Services/AudioDeviceTest.cs Added JSInterop setup for getAudioData and extended test assertions for stream data.
src/BootstrapBlazor/wwwroot/modules/media.js Introduced getAudioData function to return the recorded audio blob.
src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs Added GetAudioData method to retrieve audio stream data.
src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs Added GetData method mirroring the audio stream retrieval.
src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs Implemented GetAudioData leveraging JSInterop for stream access.
src/BootstrapBlazor/Services/MediaDevices/DefaultAudioDevice.cs Added GetData implementation delegating to the media devices service.
src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs Updated download filename generation in the OnDownload method.
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.cs Integrated download functionality and flag handling for audio.
src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor Added a new Download button with localization support.
Files not reviewed (2)
  • src/BootstrapBlazor.Server/Locales/en-US.json: Language not supported
  • src/BootstrapBlazor.Server/Locales/zh-CN.json: Language not supported
Comments suppressed due to low confidence (2)

src/BootstrapBlazor/Services/MediaDevices/IAudioDevice.cs:37

  • [nitpick] There is a naming inconsistency between this GetData() method and GetAudioData() in IMediaDevices. Consider aligning the method names across interfaces for clarity.
Task<Stream?> GetData();

src/BootstrapBlazor.Server/Components/Samples/AudioDevices.razor.cs:27

  • [nitpick] The variable name '_isDownload' might be less clear about its purpose. Consider renaming it to something more descriptive like '_downloadReady' to better indicate when the audio data is available for download.
private bool _isDownload = false;

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:

  • The PR title mentions IVideoDevice, but the primary feature appears focused on IAudioDevice.
  • Consider moving the filename change in VideoDevices.razor.cs to a separate pull request as it appears unrelated to the audio download feature.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 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 5, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (b7e0afe) to head (e0a85e9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #5967   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          670       670           
  Lines        30589     30602   +13     
  Branches      4351      4352    +1     
=========================================
+ Hits         30589     30602   +13     

☔ 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 897d657 into main May 5, 2025
6 checks passed
@ArgoZhang ArgoZhang deleted the feat-audio branch May 5, 2025 08:22
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(IVideoDevice): add GetData method

2 participants