-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Detect if the face is looking straight - Refactor to components in videoCall - Move components to components custom
- Loading branch information
Showing
10 changed files
with
169 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions
26
src/components/custom/interview/video-call/avatarVideo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { forwardRef } from 'react' | ||
|
||
type AvatarVideoProps = { | ||
avatarStream: MediaStream | null; | ||
} | ||
|
||
const AvatarVideo = forwardRef<HTMLVideoElement, AvatarVideoProps>((props, ref) => { | ||
return <div className="w-full h-full flex items-center justify-center"> | ||
{props.avatarStream ? ( | ||
<video | ||
ref={ref} | ||
className="w-full h-full object-cover" | ||
autoPlay | ||
playsInline | ||
> | ||
Your browser does not support the video tag. | ||
</video> | ||
) : ( | ||
<p>Waiting for avatar stream...</p> | ||
)} | ||
</div> | ||
}) | ||
|
||
AvatarVideo.displayName = 'AvatarVideo' | ||
|
||
export default AvatarVideo |
18 changes: 18 additions & 0 deletions
18
src/components/custom/interview/video-call/endInterviewButtonProps.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Button } from '@/components/ui/button' | ||
import { SquareIcon } from 'lucide-react' | ||
|
||
type EndInterviewButtonProps = { | ||
onClick: () => Promise<void>; | ||
} | ||
|
||
export const EndInterviewButton = (props: EndInterviewButtonProps) => { | ||
return <div className="absolute bottom-4 right-4 space-x-2"> | ||
<Button | ||
className="bg-black text-white hover:bg-gray-800" | ||
onClick={props.onClick} | ||
> | ||
<SquareIcon className="size-4 mr-2" /> | ||
End Interview | ||
</Button> | ||
</div> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { forwardRef } from 'react' | ||
import { RefreshCcw } from 'lucide-react' | ||
|
||
type UserCameraProps = { | ||
cameraError: string | null; | ||
onClick: () => void; | ||
isLookingToCamera: boolean; | ||
} | ||
|
||
const UserCamera = forwardRef<HTMLVideoElement, UserCameraProps>((props, ref) => { | ||
return <div className="absolute top-4 left-4 z-10 md:w-1/4 w-1/3"> | ||
{props.cameraError ? ( | ||
<div className="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded relative" role="alert"> | ||
<strong className="font-bold">Camera Error:</strong> | ||
<span className="block sm:inline"> {props.cameraError}</span> | ||
<button | ||
className="absolute top-0 right-0 px-4 py-3" | ||
onClick={props.onClick} | ||
> | ||
<RefreshCcw className="h-5 w-5 text-red-500" /> | ||
</button> | ||
</div> | ||
) : ( | ||
<div className={props.isLookingToCamera ? '' : 'border-2 border-red-500'}> | ||
<video | ||
ref={ref} | ||
className="w-full rounded-lg" | ||
autoPlay | ||
playsInline | ||
muted | ||
/> | ||
</div> | ||
)} | ||
</div> | ||
}); | ||
|
||
UserCamera.displayName = 'UserCamera' | ||
|
||
export default UserCamera; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import * as faceapi from 'face-api.js' | ||
|
||
export const isLookingStraight = (landmarks: faceapi.FaceLandmarks68) => { | ||
const leftEye = landmarks.getLeftEye() | ||
const rightEye = landmarks.getRightEye() | ||
const nose = landmarks.getNose() | ||
|
||
const eyeYDifference = Math.abs(leftEye[0].y - rightEye[0].y) | ||
|
||
const averageEyeX = (leftEye[0].x + rightEye[0].x) / 2 | ||
|
||
const noseXDeviation = Math.abs(nose[0].x - averageEyeX) | ||
|
||
const eyeYThreshold = 20 | ||
const noseXThreshold = 35 | ||
|
||
const eyesAligned = eyeYDifference < eyeYThreshold | ||
const noseCentered = noseXDeviation < noseXThreshold | ||
|
||
console.log(eyesAligned); | ||
console.log(noseCentered); | ||
|
||
return eyesAligned && noseCentered | ||
} |