-
Notifications
You must be signed in to change notification settings - Fork 293
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
fix(liveness): Fix oval render when switching cameras #5954
Conversation
|
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.
This makes sense to me
if (isMetadataLoaded) { | ||
send({ | ||
type: 'UPDATE_DEVICE_AND_STREAM', | ||
data: { newDeviceId, newStream }, | ||
}); | ||
} |
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.
How does this function run if setIsMetaDataLoaded
is set to false
in the same closure on line 275?
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.
This is updated now so it just sets IsMetaDataLoaded
to false. I took out the step where it draws the oval from the state machine since we're already drawing it in the camera component.
canvasRef?.current && | ||
videoRef?.current && | ||
videoStream && | ||
isStartView && | ||
isMetadataLoaded |
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.
Concerned abt fragility/maintainability with so many boolean values used for a condition
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.
Yeah fair, maybe we can extract them into one variable for readability?
|
||
React.useLayoutEffect(() => { | ||
if (isCameraReady) { | ||
if (isCameraReady && isMetadataLoaded) { |
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.
Using isMetadataLoaded
to gate behavior in three different side effects creates complexity in readability and refactoring, can we isolate some of this behavior?
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.
I think that would be hard to do without a lot of refactoring. But I was actually able to remove this particular gate
@@ -258,7 +269,9 @@ describe('LivenessCameraModule', () => { | |||
/> | |||
); | |||
const videoEl = screen.getByTestId('video'); | |||
videoEl.dispatchEvent(new Event('canplay')); | |||
await waitFor(() => { |
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.
thanks for fixing these!
if ( | ||
e.matches && | ||
canvasRef?.current && | ||
videoRef?.current && | ||
videoStream && | ||
isStartView | ||
) { | ||
drawStaticOval(canvasRef.current, videoRef.current, videoStream); | ||
if (e.matches && shouldDrawOval) { | ||
drawStaticOval(canvasRef.current, videoRef.current!, videoStream); | ||
} |
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.
Nice cleanup!
canvasRef, | ||
videoRef, |
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.
We don't need to track the refs in the dependency array, their references maintain stability since we access .current
inside the body of the hook
canvasRef, | |
videoRef, |
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.
removed canvasRef
but react gets mad if we take out videoRef, I think because the ref itself might change since it comes from the useMediaStreamInVideo
hook
Line 131 in 4393c78
const { videoRef, videoWidth, videoHeight } = useMediaStreamInVideo( |
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.
Ahh got it. For sure out of scope for this PR (and tbh think it will be a non-trivial change) but we should refactor to keep videoRef
scoped to wherever it's used directly. Passing refs around leads to unexpected behaviors
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.
Yeah makes sense I'll add that to our backlog. It definitely made this like 10x harder to fix
…fy-ui into fix-oval-render
* chore(liveness): allow selecting all cameras, allow camera selection … (#5833) * chore(liveness): allow selecting all cameras, allow camera selection on mobile * fix(liveness): fix camera select showing up with one camera, fix camera changing weirdness with hair check screen (#5845) * fix(liveness): Only apply transform style on user-facing video (#5953) * fix(liveness): Fix oval render when switching cameras (#5954) --------- Co-authored-by: thaddmt <68032955+thaddmt@users.noreply.github.com> Co-authored-by: Caleb Pollman <cpollman@amazon.com> Co-authored-by: Emma Sauerborn <70536670+esauerbo@users.noreply.github.com> Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
* chore(liveness): allow selecting all cameras, allow camera selection … (#5833) * chore(liveness): allow selecting all cameras, allow camera selection on mobile * only show on mobile with facemovement challenge only * relax e2e tests on alpha * make more reaadable * fix * update names * refactor, add tests * Update packages/react-liveness/src/components/FaceLivenessDetector/LivenessCheck/LivenessCameraModule.tsx Co-authored-by: Caleb Pollman <cpollman@amazon.com> * refactor --------- Co-authored-by: Caleb Pollman <cpollman@amazon.com> * fix(liveness): fix camera select showing up with one camera, fix camera changing weirdness with hair check screen (#5845) * fix(liveness): Only apply transform style on user-facing video (#5953) Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com> * fix(liveness): Fix oval render when switching cameras (#5954) * chore(liveness): update video constraints for selected camera (#6009) --------- Co-authored-by: thaddmt <68032955+thaddmt@users.noreply.github.com> Co-authored-by: Caleb Pollman <cpollman@amazon.com> Co-authored-by: Emma Sauerborn <70536670+esauerbo@users.noreply.github.com> Co-authored-by: Scott Rees <6165315+reesscot@users.noreply.github.com>
Description of changes
video.videoHeight
andvideo.videoWidth
) is loaded before attempting to draw the ovaldrawStaticOval
from state machine because we already call it in the LivenessCameraModule. Calling from multiple places caused weird/unpredictable behaviorIssue #, if available
Description of how you validated changes
Checklist
yarn test
passes and tests are updated/addeddocs
,e2e
,examples
, or other private packages.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.