Skip to content

Commit

Permalink
chore: update api calls to match latest SDK changes (#803)
Browse files Browse the repository at this point in the history
* chore: update api calls to match latest SDK changes

* chore: update to new version published in CA, rename OvalScaleFactors to OvalParameters

---------

Co-authored-by: Heather Buchel <buchel@amazon.com>
  • Loading branch information
hbuchel and Heather Buchel authored Mar 24, 2023
1 parent ecdcf12 commit 64c4d1f
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 652 deletions.
2 changes: 1 addition & 1 deletion packages/react-liveness/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"dependencies": {
"@aws-amplify/ui": "5.5.7",
"@aws-amplify/ui-react": "4.3.10",
"@aws-sdk/client-rekognitionstreaming": "^3.266.3",
"@aws-sdk/client-rekognitionstreaming": "^3.298.1",
"@tensorflow/tfjs-backend-cpu": "3.11.0",
"@tensorflow/tfjs-backend-wasm": "3.11.0",
"@tensorflow/tfjs-converter": "3.11.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,11 +519,6 @@ export const livenessMachine = createMachine<LivenessContext, LivenessEvent>(
width - initialFace.left - initialFace.width;

context.livenessStreamProvider.sendClientInfo({
DeviceInformation: {
ClientSDKVersion: '1.0.0',
VideoHeight: height,
VideoWidth: width,
},
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeId: challengeId,
Expand Down Expand Up @@ -1212,11 +1207,6 @@ export const livenessMachine = createMachine<LivenessContext, LivenessEvent>(
await livenessStreamProvider.stopVideo();

const livenessActionDocument: ClientSessionInformationEvent = {
DeviceInformation: {
ClientSDKVersion: '1.0.0',
VideoHeight: height,
VideoWidth: width,
},
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeId: challengeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export enum ChallengeType {
FACE_MOVEMENT = 'FACE_MOVEMENT',
}

export interface OvalScaleFactors {
export interface OvalParameters {
width: number;
centerX: number;
centerY: number;
}

export interface ClientFaceMovementAndLightChallenge {
ovalScaleFactors: OvalScaleFactors;
ovalParameters: OvalParameters;
}

export interface ClientChallenge {
Expand Down Expand Up @@ -83,12 +83,6 @@ export interface ServerChallenge {
faceMovementAndLightChallenge: ServerFaceMovementAndLightChallenge;
}

export interface DeviceInformation {
videoHeight: number;
videoWidth: number;
}

export interface ClientSessionInformation {
deviceInformation: DeviceInformation;
challenge: ServerChallenge;
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ export const mockSessionInformation: SessionInformation = {
OvalIouThreshold: 0.699999988079071,
OvalIouWidthThreshold: 0.25,
},
OvalScaleFactors: {
Width: 1,
CenterX: 2,
CenterY: 3,
},
OvalParameters: {
Width: 1,
Height: 2,
Expand Down Expand Up @@ -300,10 +295,23 @@ export const MOCK_NO_FLAT_COLOR_SEQUENCES: ColorSequence[] = [
export const mockSessionInformationNoFlatColors: SessionInformation = {
Challenge: {
FaceMovementAndLightChallenge: {
OvalScaleFactors: {
ChallengeConfig: {
BlazeFaceDetectionThreshold: 0.75,
FaceDistanceThreshold: 0.4000000059604645,
FaceDistanceThresholdMax: 0,
FaceDistanceThresholdMin: 0.4000000059604645,
FaceIouHeightThreshold: 0.15000000596046448,
FaceIouWidthThreshold: 0.15000000596046448,
OvalHeightWidthRatio: 1.6180000305175781,
OvalIouHeightThreshold: 0.25,
OvalIouThreshold: 0.699999988079071,
OvalIouWidthThreshold: 0.25,
},
OvalParameters: {
Width: 1,
CenterX: 2,
CenterY: 3,
Height: 2,
CenterX: 3,
CenterY: 4,
},
LightChallengeType: 'SEQUENTIAL',
ColorSequences: MOCK_NO_FLAT_COLOR_SEQUENCES,
Expand All @@ -313,7 +321,6 @@ export const mockSessionInformationNoFlatColors: SessionInformation = {

export const mockClientSessionInformationEvent: ClientSessionInformationEvent =
{
DeviceInformation: undefined,
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeId: 'challengeId',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
FaceMovementAndLightServerChallenge,
LivenessResponseStream,
OvalScaleFactors,
OvalParameters,
ServerChallenge,
SessionInformation,
} from '@aws-sdk/client-rekognitionstreaming';
Expand All @@ -13,10 +13,8 @@ export const isServerSesssionInformationEvent = (
?.ServerSessionInformationEvent;
};

export const isOvalScaleFactors = (
value: unknown
): value is OvalScaleFactors => {
const { CenterX, CenterY, Width } = value as OvalScaleFactors;
export const isOvalParameters = (value: unknown): value is OvalParameters => {
const { CenterX, CenterY, Width } = value as OvalParameters;
return (
typeof Width === 'number' &&
typeof CenterX === 'number' &&
Expand All @@ -27,8 +25,8 @@ export const isOvalScaleFactors = (
export const isFaceMovementAndLightChallenge = (
value: unknown
): value is FaceMovementAndLightServerChallenge => {
return isOvalScaleFactors(
(value as FaceMovementAndLightServerChallenge)?.OvalScaleFactors
return isOvalParameters(
(value as FaceMovementAndLightServerChallenge)?.OvalParameters
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export class FreshnessColorDisplay {
}) {
const { livenessStreamProvider, challengeId } = this.context;
livenessStreamProvider.sendClientInfo({
DeviceInformation: undefined,
Challenge: {
FaceMovementAndLightChallenge: {
ChallengeId: challengeId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ function isBlob(obj: unknown): obj is Blob {
function isClientSessionInformationEvent(
obj: unknown
): obj is ClientSessionInformationEvent {
return (
(obj as ClientSessionInformationEvent).DeviceInformation !== undefined ||
(obj as ClientSessionInformationEvent).Challenge !== undefined
);
return (obj as ClientSessionInformationEvent).Challenge !== undefined;
}

export class LivenessStreamProvider extends AmazonAIInterpretPredictionsProvider {
Expand Down Expand Up @@ -165,7 +162,6 @@ export class LivenessStreamProvider extends AmazonAIInterpretPredictionsProvider
} else if (isClientSessionInformationEvent(value)) {
yield {
ClientSessionInformationEvent: {
DeviceInformation: value.DeviceInformation,
Challenge: value.Challenge,
},
};
Expand All @@ -183,7 +179,7 @@ export class LivenessStreamProvider extends AmazonAIInterpretPredictionsProvider

const response = await this._client.send(
new StartFaceLivenessSessionCommand({
ClientSDKVersion: '1.0.0',
ChallengeVersions: 'FaceMovementAndLightChallenge_1.0.0',
SessionId: this.sessionId,
LivenessRequestStream: livenessRequestGenerator,
VideoWidth: this.videoEl.videoWidth.toString(),
Expand Down
Loading

0 comments on commit 64c4d1f

Please sign in to comment.