/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import React from "react"; import "./NoseChallenge.css"; // @ts-ignore import Lottie from "react-lottie"; import SpinnerMessage from "../components/SpinnerMessage"; import { NoseChallengeProcessor } from "./NoseChallengeProcessor"; import { ChallengeMetadata } from "../utils/APIUtils"; import { ConfigUtils } from "../utils/ConfigUtils"; import { MediaUtils } from "../utils/MediaUtils"; import * as help1 from "./lottie/help1.json"; import * as help2 from "./lottie/help2.json"; type Props = { challengeMetadata: ChallengeMetadata; onLocalEnd: (localSuccess: boolean) => void; onError: (error: Error) => void; }; type State = { message: string; animation: number; localSuccess: boolean; uploading: boolean; }; export default class NoseChallenge extends React.Component { constructor(props: Props | Readonly) { super(props); this.state = { message: "Loading...", animation: -1, localSuccess: false, uploading: false }; this.onHelpMessage = this.onHelpMessage.bind(this); this.onHelpAnimation = this.onHelpAnimation.bind(this); this.onLocalEnd = this.onLocalEnd.bind(this); this.onUploadEnd = this.onUploadEnd.bind(this); } componentDidMount() { // Make sure all models are loaded before starting frame processing NoseChallengeProcessor.loadModels().then(() => { new NoseChallengeProcessor( this.props.challengeMetadata, "cameraVideo", "overlayCanvas", this.onLocalEnd, this.onUploadEnd, this.onHelpMessage, this.onHelpAnimation ).start(); }); } onLocalEnd(localSuccess: boolean) { this.setState({ uploading: true }); this.setState({ localSuccess: localSuccess }); } onUploadEnd() { this.props.onLocalEnd(this.state.localSuccess); } onHelpMessage(message: string | undefined): void { this.setState({ message: message || "" }); } onHelpAnimation(animationNumber: number | undefined): void { this.setState({ animation: animationNumber || -1 }); } render() { const videoWidth = MediaUtils.getMediaStreamInfo().actualWidth; const videoHeight = MediaUtils.getMediaStreamInfo().actualHeight; const shouldRotate = ConfigUtils.getConfigBooleanValue("FLIP_VIDEO"); // @ts-ignore const lottieOptions1 = { animationData: help1.default }; // @ts-ignore const lottieOptions2 = { animationData: help2.default }; return (
{!this.state.uploading && (
)} {this.state.uploading && }
); } }