feat(IVideoDevice): add GetPreviewData method#5965
Conversation
Reviewer's GuideThis pull request introduces functionality to download captured video frames. It adds a Sequence diagram for downloading a captured video framesequenceDiagram
actor User
participant Razor as VideoDevices (Razor)
participant CSharp as VideoDevices (C#)
participant VDS as VideoDeviceService (IVideoDevice)
participant DMD as DefaultMediaDevices (IMediaDevices)
participant JSI as JS Interop
participant JS as media.js
participant DS as DownloadService
User->>Razor: Click Download Button
Razor->>CSharp: OnDownload()
CSharp->>VDS: GetPreviewData()
VDS->>DMD: GetPreviewData()
DMD->>JSI: InvokeAsync("getPreviewData")
JSI->>JS: getPreviewData()
JS-->>JSI: Return previewBlob (as JSStreamReference)
JSI-->>DMD: Return JSStreamReference
DMD-->>VDS: Return Stream
VDS-->>CSharp: Return Stream
CSharp->>DS: DownloadFromStreamAsync("preview.png", stream)
DS-->>User: Initiate file download
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull Request Overview
This pull request introduces a new GetPreviewData method to allow users to download captured video frames as image files, updating both backend and frontend components while extending test coverage.
- Added a download button and OnDownload handler in the UI component.
- Updated the video device and media services (both interfaces and implementations) to include GetPreviewData.
- Enhanced the JavaScript module to support retrieval of preview data and adjusted unit tests accordingly.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTest/Services/VideoDeviceTest.cs | Added unit tests for GetPreviewData functionality. |
| src/BootstrapBlazor/wwwroot/modules/media.js | Modified functions to handle preview data retrieval and updated error handling. |
| src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs, IMediaDevices.cs | Updated interfaces with the new GetPreviewData method. |
| src/BootstrapBlazor/Services/MediaDevices/DefaultVideoDevice.cs, DefaultMediaDevices.cs | Implemented GetPreviewData method, delegating to the underlying device service and JS module. |
| src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs, VideoDevices.razor | Added download button and OnDownload handler to support the new feature. |
Co-Authored-By: pomeara <8163710+pomeara@users.noreply.github.com>
There was a problem hiding this comment.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- The
GetPreviewDatamethod relies onGetPreviewUrlhaving been called previously to store the image blob in JavaScript; consider making this dependency clearer or allowingGetPreviewDatato capture the image independently if needed. - Consider disabling the download button until a preview image has actually been captured (e.g.,
_previewUrlis not null), not just when the video stream is open.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟡 Testing: 2 issues found
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5965 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 670 670
Lines 30576 30589 +13
Branches 4350 4351 +1
=========================================
+ Hits 30576 30589 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Link issues
fixes #5964
Summary By Copilot
This pull request introduces functionality to download captured video frames as image files, along with related updates to services, interfaces, and tests. The most important changes include adding a download button to the UI, implementing a method to retrieve image data from the video stream, and updating the JavaScript module and unit tests to support this feature.
UI Enhancements:
VideoDevices.razor, allowing users to download captured frames as images. The button is disabled when no video is active (src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor).Backend Service Updates:
DownloadServiceinto theVideoDevicescomponent to handle file downloads (src/BootstrapBlazor.Server/Components/Samples/VideoDevices.razor.cs).GetPreviewDatamethod in theDefaultMediaDevicesservice to retrieve the image data as a stream (src/BootstrapBlazor/Services/MediaDevices/DefaultMediaDevices.cs).IVideoDeviceandIMediaDevicesinterfaces to include the newGetPreviewDatamethod (src/BootstrapBlazor/Services/MediaDevices/IVideoDevice.cs,src/BootstrapBlazor/Services/MediaDevices/IMediaDevices.cs). [1] [2]JavaScript Module Enhancements:
getPreviewDatafunction to themedia.jsmodule to retrieve the captured image blob for download (src/BootstrapBlazor/wwwroot/modules/media.js).src/BootstrapBlazor/wwwroot/modules/media.js). [1] [2] [3]Unit Tests:
VideoDeviceTestunit tests to verify the newGetPreviewDatafunctionality, ensuring that the data stream is correctly retrieved and validated (test/UnitTest/Services/VideoDeviceTest.cs). [1] [2]Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add functionality to download captured video frames as image files in the video device component
New Features:
Enhancements:
Tests: