-
Notifications
You must be signed in to change notification settings - Fork 344
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
Barcode scanner issue fixed #721
Conversation
WalkthroughThe changes update the Changes
Sequence Diagram(s)sequenceDiagram
participant U as User/Component Lifecycle
participant C as CameraUpload
participant M as MediaStream
participant T as Track
U->>C: Component unmounts or cancelCamera() called
C->>C: Execute beforeUnmount() / cancelCamera()
C->>C: Call cleanupCurrentStream()
C->>M: Retrieve mediaStream & getTracks()
loop For each track
M->>T: Stop track
end
Poem
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
client/components/forms/components/CameraUpload.vue (1)
173-194
: Consider additional error handling in cleanup method.The
cleanupCurrentStream
method is now the central place for resource cleanup, but it doesn't have try/catch blocks to handle potential errors during cleanup operations. Media API operations can sometimes throw exceptions that should be caught to prevent them from interrupting the cleanup process.async cleanupCurrentStream() { + try { if (this.quaggaInitialized) { Quagga.stop() this.quaggaInitialized = false } if (this.mediaStream) { this.mediaStream.getTracks().forEach(track => track.stop()) this.mediaStream = null } if (this.webcam) { this.webcam.stop() } const webcamElement = document.getElementById("webcam") if (webcamElement && webcamElement.srcObject) { const tracks = webcamElement.srcObject.getTracks() tracks.forEach(track => track.stop()) webcamElement.srcObject = null } + } catch (error) { + console.error('Error during stream cleanup:', error) + } },
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
client/components/forms/components/CameraUpload.vue
(4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Build the Nuxt app
🔇 Additional comments (4)
client/components/forms/components/CameraUpload.vue (4)
168-170
: Good addition of lifecycle hook for resource cleanup!Adding the
beforeUnmount
lifecycle hook ensures that media resources are properly cleaned up when the component is unmounted, preventing potential memory leaks and resource issues. This is a critical improvement for proper resource management.
190-192
: Enhanced stream cleanup implementation.Stopping each track individually before setting srcObject to null is the correct approach for thoroughly releasing camera resources. Without this explicit track stopping, users might experience issues like the camera light remaining on after navigation or component destruction.
235-235
: Good practice storing stream reference.Storing the media stream in a component property allows for proper cleanup later. This is a key part of the fix that enables more reliable resource management.
299-301
: Improved camera cancellation flow.Simplifying the
cancelCamera
method to rely on the centralizedcleanupCurrentStream
method reduces code duplication and ensures consistent cleanup behavior across different component lifecycle events. This is a good refactoring approach.
Summary by CodeRabbit