Skip to content
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

Add live cam #93

Merged
merged 5 commits into from
May 6, 2024
Merged

Add live cam #93

merged 5 commits into from
May 6, 2024

Conversation

techeng322
Copy link
Collaborator

No description provided.

Copy link

vercel bot commented Apr 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
heno-website ✅ Ready (Inspect) Visit Preview May 6, 2024 6:31pm

Copy link

coderabbitai bot commented Apr 30, 2024

Walkthrough

The changes involve enhancing the WebCam component for media stream initialization and permission handling, along with improvements to camera initialization in the PageLoadProvider. These updates aim to streamline user experience by managing permissions, setting up streams, and ensuring proper cleanup.

Changes

File Path Change Summary
.../WebCam/WebCam.tsx Refactored to handle asynchronous media stream initialization, permission handling, and cleanup.
providers/PageLoadProvider.tsx Added handleTxError import, useEffect for camera initialization, and state for camera handling.

🐰✨
A hop, a skip, a code deploy,
The WebCam streams, oh what a joy!
Permissions checked, the stream is set,
On unmount, we clean up, no fret.
Camera initialized, changes in play,
CodeRabbit's work brightens the day! 🎉
🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Comment on lines 21 to 30
const init = async () => {
let mediaStream = null
if (granted) {
mediaStream = await navigator.mediaDevices.getUserMedia({ video: true, audio: true })
setStream(mediaStream)
}

if (!stream && !mediaStream) return

videoRef.current.srcObject = stream || mediaStream
Copy link

Choose a reason for hiding this comment

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

Consider handling the case where mediaStream is not initialized due to granted being false.

Currently, if granted is false, mediaStream remains null, and the subsequent code attempts to set videoRef.current.srcObject to null, which is not handled. This could lead to unexpected behavior or errors in the video playback logic.

videoRef.current.muted = true
videoRef.current.play()
}

if (!videoRef?.current) return
Copy link

Choose a reason for hiding this comment

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

Add a check to ensure videoRef.current is not null before proceeding with initialization.

The check if (!videoRef?.current) return uses optional chaining which will not throw but simply return undefined if videoRef is null. It's safer to explicitly check for null to avoid any potential issues with undefined behavior.

Comment on lines 37 to 38
init()
// eslint-disable-next-line consistent-return
Copy link

Choose a reason for hiding this comment

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

Consider moving the init function call inside the useEffect dependency array.

By moving the init function definition inside the useEffect hook, you can ensure that it has the most up-to-date closures over its dependencies, which is crucial for functions that depend on external state.

Comment on lines 38 to 44
// eslint-disable-next-line consistent-return
return () => {
if (stream) {
stream.getTracks().forEach((track) => track.stop())
}
}
}, [stream])
}, [stream, granted, videoRef])
Copy link

Choose a reason for hiding this comment

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

Refactor the cleanup function to handle potential null values more gracefully.

- if (stream) {
-   stream.getTracks().forEach((track) => track.stop())
- }
+ stream?.getTracks().forEach((track) => track.stop())

This change uses optional chaining to make the code more robust and concise, ensuring that it handles cases where stream might be null.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// eslint-disable-next-line consistent-return
return () => {
if (stream) {
stream.getTracks().forEach((track) => track.stop())
}
}
}, [stream])
}, [stream, granted, videoRef])
// eslint-disable-next-line consistent-return
return () => {
stream?.getTracks().forEach((track) => track.stop())
}
}, [stream, granted, videoRef])

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a093c65 and d1cab0f.
Files selected for processing (2)
  • components/WebCam/WebCam.tsx (1 hunks)
  • providers/PageLoadProvider.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • components/WebCam/WebCam.tsx
Additional comments not posted (2)
providers/PageLoadProvider.tsx (2)

14-22: The implementation of grantCamera function looks good. It properly handles the asynchronous request for user media and updates the state based on the outcome.


43-47: The dependencies of the useMemo hook are correctly set to include all relevant state setters and values. This ensures that the context value is recalculated only when necessary.

Comment on lines 24 to 34
useEffect(() => {
const init = async () => {
videoRef.current.srcObject = stream
videoRef.current.muted = true
videoRef.current.play()
}

if (!videoRef?.current) return

init()
}, [stream, videoRef])
Copy link

Choose a reason for hiding this comment

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

Ensure to handle the promise returned by videoRef.current.play(). This method returns a promise that could reject if the play request is interrupted by a new load request or if the user didn't interact with the document before.

- videoRef.current.play()
+ videoRef.current.play().catch(error => console.error("Failed to play video:", error));

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
useEffect(() => {
const init = async () => {
videoRef.current.srcObject = stream
videoRef.current.muted = true
videoRef.current.play()
}
if (!videoRef?.current) return
init()
}, [stream, videoRef])
useEffect(() => {
const init = async () => {
videoRef.current.srcObject = stream
videoRef.current.muted = true
videoRef.current.play().catch(error => console.error("Failed to play video:", error))
}
if (!videoRef?.current) return
init()
}, [stream, videoRef])

Copy link

@coderabbitai coderabbitai bot left a 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d1cab0f and 3446639.
Files selected for processing (1)
  • providers/PageLoadProvider.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • providers/PageLoadProvider.tsx

Copy link

@coderabbitai coderabbitai bot left a 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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3446639 and 31d8ff0.
Files selected for processing (2)
  • components/WebCam/WebCam.tsx (1 hunks)
  • providers/PageLoadProvider.tsx (2 hunks)
Files skipped from review as they are similar to previous changes (2)
  • components/WebCam/WebCam.tsx
  • providers/PageLoadProvider.tsx

@techeng322 techeng322 merged commit 10ee312 into test May 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants