-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(IVideoDevice): add IVideoDevice service #5940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis pull request introduces services ( 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.
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 separating media device enumeration logic from media stream control logic (open/close/capture) into distinct services.
- Passing DOM selectors from C# services to JavaScript tightly couples the service logic to specific UI implementations.
- Remove the empty
DisplayMediaOptionsandMediaStreamclasses if they are placeholders for future work.
Here's what I looked at during the review
- 🟡 General issues: 3 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 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.
| const stream = await navigator.mediaDevices.getUserMedia(constrains); | ||
| video.srcObject = stream; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Consider handling errors in open() function.
Wrap the navigator.mediaDevices.getUserMedia call in a try-catch to handle permission denials and other errors gracefully.
| const stream = await navigator.mediaDevices.getUserMedia(constrains); | |
| video.srcObject = stream; | |
| try { | |
| const stream = await navigator.mediaDevices.getUserMedia(constrains); | |
| video.srcObject = stream; | |
| } catch (error) { | |
| console.error("Error accessing media devices:", error); | |
| } |
| } | ||
| } | ||
|
|
||
| export async function capture(videoSelector) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Check for existence of target element in capture().
Ensure document.querySelector('.b-video-image') returns a non-null element before use to avoid runtime errors.
Suggested implementation:
export async function capture(videoSelector) {
const video = document.querySelector(videoSelector);
if (video) {
const bVideoImage = document.querySelector('.b-video-image');
if (!bVideoImage) {
console.error("The element with class 'b-video-image' was not found.");
return;
}If the capture() function uses the bVideoImage element later to display a captured image, ensure that further logic (e.g., drawing from a canvas and setting bVideoImage.src) is placed after this check.
|
|
||
| class DefaultMediaDevices(IJSRuntime jsRuntime) : IMediaDevices | ||
| { | ||
| private DotNetObjectReference<DefaultMediaDevices>? _interop = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Dispose DotNetObjectReference to prevent memory leaks.
Implement IAsyncDisposable (or manually dispose) to release the _interop DotNetObjectReference created in LoadModule when the service is disposed.
Suggested implementation:
class DefaultMediaDevices(IJSRuntime jsRuntime) : IMediaDevices, IAsyncDisposable private DotNetObjectReference<DefaultMediaDevices>? _interop = null; // ... existing code ... private async Task<JSModule> LoadModule()
{
_interop ??= DotNetObjectReference.Create(this); // Other existing methods...
public async ValueTask DisposeAsync()
{
if (_module is not null)
{
await _module.DisposeAsync();
_module = null;
}
if (_interop is not null)
{
_interop.Dispose();
_interop = null;
}
}
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #5940 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 665 669 +4
Lines 30485 30551 +66
Branches 4345 4347 +2
=========================================
+ Hits 30485 30551 +66 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-Authored-By: Vincent <[email protected]>
Link issues
fixes #5939
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add media device support to the BootstrapBlazor library, introducing services and components for interacting with media devices like cameras
New Features:
Enhancements: