Skip to content

Commit

Permalink
fix(liveness): fix styling when no face on screen by not showing oval…
Browse files Browse the repository at this point in the history
… canvas and ensuring full screen camera
  • Loading branch information
thaddmt committed Jan 5, 2024
1 parent 936243f commit 4fabf1e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,9 @@ export const LivenessCameraModule = (
);
}

const isRecordingOnMobile =
isMobileScreen && !isStartView && !isWaitingForCamera && isRecording;
// We don't show full screen camera on the pre check screen (isStartView/isWaitingForCamera)
const shouldShowFullScreenCamera =
isMobileScreen && !isStartView && !isWaitingForCamera;

return (
<>
Expand All @@ -301,7 +302,8 @@ export const LivenessCameraModule = (
<Flex
className={classNames(
LivenessClassNames.CameraModule,
isRecordingOnMobile && `${LivenessClassNames.CameraModule}--mobile`
shouldShowFullScreenCamera &&
`${LivenessClassNames.CameraModule}--mobile`
)}
data-testid={testId}
gap="zero"
Expand Down Expand Up @@ -335,7 +337,8 @@ export const LivenessCameraModule = (
<Flex
className={classNames(
LivenessClassNames.OvalCanvas,
isRecordingOnMobile && `${LivenessClassNames.OvalCanvas}--mobile`,
shouldShowFullScreenCamera &&
`${LivenessClassNames.OvalCanvas}--mobile`,
isRecordingStopped && LivenessClassNames.FadeOut
)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isCameraDeviceVirtual,
FreshnessColorDisplay,
drawStaticOval,
clearOvalCanvas,
} from '../utils';
import { nanoid } from 'nanoid';
import { getStaticLivenessOvalDetails } from '../utils/liveness';
Expand Down Expand Up @@ -183,6 +184,7 @@ export const livenessMachine = createMachine<LivenessContext, LivenessEvent>(
},
},
detectFaceBeforeStart: {
entry: ['hideOvalCanvas'],
invoke: {
src: 'detectFace',
onDone: {
Expand Down Expand Up @@ -249,7 +251,7 @@ export const livenessMachine = createMachine<LivenessContext, LivenessEvent>(
initial: 'ovalDrawing',
states: {
ovalDrawing: {
entry: ['sendTimeoutAfterOvalDrawingDelay'],
entry: ['showOvalCanvas', 'sendTimeoutAfterOvalDrawingDelay'],
invoke: {
src: 'detectInitialFaceAndDrawOval',
onDone: {
Expand Down Expand Up @@ -483,6 +485,17 @@ export const livenessMachine = createMachine<LivenessContext, LivenessEvent>(

drawStaticOval(canvasEl!, videoEl!, videoMediaStream!);
},
hideOvalCanvas: (context) => {
const { canvasEl } = context.videoAssociatedParams!;

clearOvalCanvas({ canvas: canvasEl! });
canvasEl!.style.display = 'none';
},
showOvalCanvas: (context) => {
const { canvasEl } = context.videoAssociatedParams!;

canvasEl!.style.display = 'unset';
},
updateRecordingStartTimestampMs: assign({
videoAssociatedParams: (context) => {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,21 @@ export function drawLivenessOvalInCanvas({
}
}

export function clearOvalCanvas({
canvas,
}: {
canvas: HTMLCanvasElement;
}): void {
const ctx = canvas.getContext('2d');

if (ctx) {
ctx.restore();
ctx.clearRect(0, 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
} else {
throw new Error('Cannot find Canvas.');
}
}

interface FaceMatchStateInLivenessOval {
faceMatchState: FaceMatchState;
faceMatchPercentage: number;
Expand Down

0 comments on commit 4fabf1e

Please sign in to comment.