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

chore(liveness): allow selecting all cameras, allow camera selection … #5833

Merged
merged 9 commits into from
Sep 26, 2024

Conversation

thaddmt
Copy link
Member

@thaddmt thaddmt commented Sep 24, 2024

…on mobile

Description of changes

Issue #, if available

Description of how you validated changes

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, 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.

@thaddmt thaddmt requested a review from a team as a code owner September 24, 2024 19:08
Copy link

changeset-bot bot commented Sep 24, 2024

⚠️ No Changeset found

Latest commit: c76bf05

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -115,6 +115,8 @@ export const LivenessCameraModule = (

const isFaceMovementChallenge =
useLivenessSelector(selectChallengeType) === FACE_MOVEMENT_CHALLENGE.type;
const isMobileFaceMovementAndLightChallenge =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we flip this logic to be more readable, something like
const allowSelectableDevices = !isMobile || (isMobile && isFaceMovementChallenge)
then add a comment why we only support desktop or mobile and facemovement?

@@ -24,6 +24,3 @@ Feature: Disable Start Screen
Then I click the "FaceMovementAndLightChallenge" selectfield and select the "FaceMovementChallenge" option
Then I see "FaceMovementChallenge"
Then I see "liveness-detector" element
Then I see the "Face didn't fit inside oval in time limit." timeout error
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do these need to be removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Rekognition updated the values for face distance which make it so these tests no longer work, only on the no light stuff, figure that's unrelated to this PR but just want to unblock this

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh gotcha, what updates would we need to get them passing? But make sense as a follow up

Copy link
Member Author

Choose a reason for hiding this comment

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

We would need to update the video we use in the e2e test haha

@@ -115,6 +115,8 @@

const isFaceMovementChallenge =
useLivenessSelector(selectChallengeType) === FACE_MOVEMENT_CHALLENGE.type;
const allowSelectableDevicesMobile =
!isMobileScreen || (isMobileScreen && isFaceMovementChallenge);

Check warning

Code scanning / CodeQL

Useless conditional Warning

This use of variable 'isMobileScreen' always evaluates to true.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this think isMobileScreen is always true?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe because if isMobileScreen === false then the left hand side will always short circuit the whole thing to be true. So you only evaluate the right side if isMobileScreen === true so it's redundant

Copy link
Member Author

Choose a reason for hiding this comment

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

boolean algebra 🙃

selectableDevices: MediaDeviceInfo[];
}

export const CameraSelector = (props: CameraSelectorProps): JSX.Element => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

@@ -8,5 +8,4 @@ export const STATIC_VIDEO_CONSTRAINTS: MediaTrackConstraints = {
ideal: 480,
},
frameRate: { min: 15, ideal: 30, max: 30 },
facingMode: 'user',
Copy link
Contributor

@reesscot reesscot Sep 25, 2024

Choose a reason for hiding this comment

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

Just to confirm, this is no longer needed because with the light challenge we only show the dropdown on desktop, and on desktop the facing mode is not relevant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly, desktop cameras do not have a facingMode value

reesscot
reesscot previously approved these changes Sep 25, 2024
Copy link
Member

@calebpollman calebpollman left a comment

Choose a reason for hiding this comment

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

Minor feedback, lmk your thoughts!

value={selectedDeviceId}
onChange={onCameraChange}
>
{selectableDevices?.map((device) => (
Copy link
Member

Choose a reason for hiding this comment

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

Since we are gating rendering of this component think we can remove the optional chaining here

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, removed

Comment on lines 423 to 429
{allowSelectableDevices && (
<CameraSelector
onCameraChange={onCameraChange}
selectableDevices={selectableDevices}
selectedDeviceId={selectedDeviceId}
/>
)}
Copy link
Member

Choose a reason for hiding this comment

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

Prefer ternary returning null as the second condition in place of returning false

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -160,6 +153,15 @@ export const LivenessCameraModule = (
videoWidth && videoHeight ? videoWidth / videoHeight : 0
);

// Only allow on mobile screen if it is no light challenge
const allowSelectableDevicesMobile =
!isMobileScreen || isFaceMovementChallenge;
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit hard to follow that allowSelectableDevicesMobile is true when isMobileScreen is false. Realize that it going to be hard for this not to be somewhat confusing but maybe we can update the approach to something like:

const hasMultipleDevices = !!selectableDevices?.length;
const allowDeviceSelection = (isStartView && hasMultipleDevices) && (!isMobileScreen || isFaceMovementChallenge)

Copy link
Member Author

Choose a reason for hiding this comment

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

Think that makes sense, think this is much cleaner

Comment on lines 6 to 8
selectedDeviceId?: string;
onCameraChange: (e: React.ChangeEvent<HTMLSelectElement>) => void;
selectableDevices: MediaDeviceInfo[];
Copy link
Member

Choose a reason for hiding this comment

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

IMO we can simplify the naming of the props a bit here since camera selection is implied by the component name, e.g.

  deviceId?: string;
  onSelect?: (e: React.ChangeEvent<HTMLSelectElement>) => void;
  devices: MediaDeviceInfo[];

Copy link
Member Author

Choose a reason for hiding this comment

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

on board with this

…venessCheck/LivenessCameraModule.tsx

Co-authored-by: Caleb Pollman <cpollman@amazon.com>
@thaddmt thaddmt merged commit 984fa99 into liveness/alpha Sep 26, 2024
32 checks passed
@thaddmt thaddmt deleted the liveness-camera-select-mobile branch September 26, 2024 18:10
ayush987goyal added a commit to ayush987goyal/amplify-ui that referenced this pull request Sep 27, 2024
commit 984fa99
Author: thaddmt <68032955+thaddmt@users.noreply.github.com>
Date:   Thu Sep 26 11:10:45 2024 -0700

    chore(liveness): allow selecting all cameras, allow camera selection … (aws-amplify#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>
calebpollman pushed a commit that referenced this pull request Sep 27, 2024
* Update publish workflow

* disable e2e tests in workflow

* Squashed commit of the following:

commit 984fa99
Author: thaddmt <68032955+thaddmt@users.noreply.github.com>
Date:   Thu Sep 26 11:10:45 2024 -0700

    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>
thaddmt added a commit that referenced this pull request Sep 30, 2024
* 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)

---------

Co-authored-by: thaddmt <68032955+thaddmt@users.noreply.github.com>
Co-authored-by: Caleb Pollman <cpollman@amazon.com>
esauerbo added a commit that referenced this pull request Nov 1, 2024
* 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>
@ayush987goyal ayush987goyal mentioned this pull request Nov 6, 2024
5 tasks
esauerbo added a commit that referenced this pull request Nov 6, 2024
* 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>
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.

4 participants