-
Notifications
You must be signed in to change notification settings - Fork 346
React liveness/provide default device info #6633
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
base: main
Are you sure you want to change the base?
React liveness/provide default device info #6633
Conversation
…ice automatically
🦋 Changeset detectedLatest commit: 3aa0cc7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Hello @riasatali42 , thanks for creating the PR! There's conflicts in the branch. Could you resolve the conflict and resubmit the PR? |
…aNotFoundCallback and device change callback methods after resolving merge conflicts
Hello @Simone319 , I have updated the branch with the current main branch and resolved all the conflicts. I've updated this PR instead of creating a new branch. Please let me know if I should do otherwise. |
@Simone319, I saw after running the tests that there were some ESLint issues. I've fixed those and updated the branch. |
data: { newDeviceId: selectedDeviceId, newStream }, | ||
}); | ||
} catch (error: any) { | ||
throw new Error('Error updating device:'); |
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.
Let's include the original error message. ex:
throw new Error(`Error updating device: ${error.message}`);
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.
Resolved.
onCameraChange(deviceInfo); | ||
} | ||
} catch (callbackError) { | ||
// console.error('Error in onCameraChange callback:', callbackError); |
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.
Here, we call still log the error, so that the error is not silently swallowed. However, we need to disable the eslint rule, such as:
// eslint-disable-next-line no-console
console.error('Error in onCameraChange callback:', callbackError);
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.
Resolved.
// console.error('Error in onCameraNotFound callback:', callbackError); | ||
// Don't rethrow to prevent state machine from getting stuck |
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.
Same as above.
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.
Resolved.
|
||
try { | ||
const deviceInfo = getSelectedDeviceInfo(context); | ||
onUserCancel(deviceInfo); |
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.
What's the use case of deviceInfo
in onUserCancel
callback?
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.
The main goal was to make all the callbacks more consistent. I've discarded it as we won't need this.
}); | ||
|
||
// Update the device if the selectedDeviceId changes | ||
React.useEffect(() => { |
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.
Why do we need to create a new effect here instead of reusing the existing onCameraChange callback?
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 we can discard that as the onCameraChange is already handling everything. So, I discarded.
const deviceInfo = getSelectedDeviceInfo(context); | ||
onUserCancel(deviceInfo); | ||
} catch (callbackError) { | ||
// console.error('Error in onUserCancel callback:', callbackError); |
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.
Same as above
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.
Resolved.
…rom the onUserCancel callback
Hello @Simone319 , I've updated the PR as per the feedback. |
Hi @riasatali42, thank you for addressing our concerns. Could you add end-to-end tests to verify the behavior of your changes? This guide should help you getting started: https://github.com/aws-amplify/amplify-ui/tree/main/packages/e2e If you got any questions, feel free to reach out. Thank you! |
Hello @adrianjoshua-strutt , Could you please guide me here to resolve this issue? |
Hi @riasatali42, |
Hi @riasatali42, |
…ide-default-device-info
Hello @soberm , |
Hi @riasatali42, |
…ss default device pass in
Hello @soberm , I've updated the PR. Please let me know if we need anything else. |
Hey @riasatali42, I can't execute the E2E tests due to a missing step implementation.
|
…ide-default-device-info
… case for device info pass out
Hello @soberm , I've added the step. Please take a look now. |
Hello @soberm - circling back on this. We are eager to get this merged. Could the team please review and return any issues to us so we can bring this to a close? |
…ide-default-device-info
We're currently reviewing this internally with our team and update you here once we have more information. |
Hi @riasatali42, @jasonfill, thank you for your work on implementing this feature for the Requested Changes
Your PR includes both We suggest removing the export interface FaceLivenessDetectorCoreConfig {
deviceId?: string; // Only this parameter should be supported
// ... other existing config options
}
We suggest removing the callbacks that were added:
The existing
We suggest using the existing callbacks to include optional DeviceInfo parameter to pass this information: export interface DeviceInfo {
deviceId: string;
groupId: string;
label: string;
}
export interface FaceLivenessDetectorCoreProps {
onAnalysisComplete: (deviceInfo?: DeviceInfo) => Promise<void>;
onError?: (livenessError: LivenessError, deviceInfo?: DeviceInfo) => void;
}
Ensure Thank you again for taking the initiative to implement this feature and for your patience as we work through the design. |
@soberm I have a few items on these
Numbers 3 and 4 make sense, and we can incorporate them. Please provide the final direction on 1 & 2, and we will look to wrap this up. cc @riasatali42 |
@jasonfill thank you for the feedback. Here are our thoughts on this: 1. Device Input Parameters 2. Callback Methods What are your thoughts on this approach? |
@soberm since the deviceId is not reliable, it makes no sense for us to use that. Our goal is to preload the camera that was used last. The only level of reliability is to do that via label. If label is. Or permitted, this feature is rendered useless for us. Unless I am missing the concept of what you are outlining. On point 2, that makes total sense. We can adjust to use the onError. |
@jasonfill Yes, the deviceId might change but if you already store the deviceLabel of the last used device it should be possible to get the DeviceInfo for the device with this label and then pass the deviceId to the liveness component. Maybe like this: // Get device by label and extract deviceId
async function getDeviceIdByLabel(targetLabel) {
const devices = await navigator.mediaDevices.enumerateDevices();
const camera = devices.find(device =>
device.kind === 'videoinput' && device.label === targetLabel
);
return camera?.deviceId;
}
const lastUsedLabel = getStoredCameraLabel(); // your stored device
const deviceId = await getDeviceIdByLabel(lastUsedLabel);
if (deviceId) {
// Pass to liveness component
<LivenessComponent deviceId={deviceId} />
} Would this approach work for your use case ? |
@soberm We can make that work. The team will roll these changes in ASAP. Thanks for your time and collaboration. |
Description of changes
This PR introduces features to pass in and out the device information (device Id, device label, kind, group Id) for the camera of the liveness check. Also, provides support to add callback methods for camera changes or default device not found.
Key additions:
Issue ##6587, Pass deviceId in and out of liveness check
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.