UNPKG

@nuralogix.ai/anura-web-core-sdk

Version:

Anura Web Core SDK

514 lines (498 loc) 15.2 kB
/** * The objectFit sets how the content of an element should be resized to fit its container. * * `contain`: * * The content is scaled to maintain its aspect ratio while fitting within the element's * content box. The entire object is made to fill the box, while preserving its aspect ratio, * so the object will be "letterboxed" or "pillarboxed" if its aspect ratio does not match the * aspect ratio of the box. * * `cover`: * * The content is sized to maintain its aspect ratio while filling the element's entire * content box. If the object's aspect ratio does not match the aspect ratio of its box, then * the object will be clipped to fit. * * `none`: * * The content is not resized. * @enum */ declare const objectFit: { readonly CONTAIN: "contain"; readonly COVER: "cover"; readonly NONE: "none"; }; type ObjectFit = typeof objectFit[keyof typeof objectFit]; interface VideoElementSize { width: number; height: number; offsetX: number; offsetY: number; } interface Centroids { [id: string]: {x: number, y: number }; } interface MeshAnnotation { x: number; y: number; z: number | undefined; } interface Annotations { silhouette: MeshAnnotation[], centroids: Centroids; } interface PosePoints { [x: string]: { point: number[], valid: boolean; estimated: boolean; quality: number; } } interface DfxRect { x: number; y: number; width: number; height: number; } interface DfxFace { detected: boolean; id: string; poseValid: boolean; posePoints: PosePoints, faceRect: DfxRect; } type ChunkAction = 'CHUNK::PROCESS' | 'FIRST::PROCESS' | 'LAST::PROCESS'; interface ConstraintsConfig { backLightMaxPixels_pct: number; backLightSearchMult: number; backLightThresh: number; boxCenterX_pct: number; boxCenterY_pct: number; boxHeight_pct: number; boxWidth_pct: number; cameraRot_chunkThresh: number; cameraRot_windowThresh: number; checkBackLight: boolean; checkCameraMovement: boolean; checkCentered: boolean; checkDistance: boolean; checkEyebrowMovement: boolean; checkFaceDirection: boolean; checkLighting: boolean; checkMaxDistance: boolean; checkMinFps: boolean; checkMovement: boolean; chunkMovementThresh_pct: number; enableDebugLog: boolean; enableFigures: boolean; faceRotLR_thresh: number; faceRotUD_lowerthresh: number; faceRotUD_upperThresh: number; hy_faceRotLR_thresh: number; hy_maxFaceRotLR_deg: number; hy_maxFaceRotUD_deg: number; hy_minInterPupilDist_px: number; hy_minimumFps: number; maxEyebrowMovement_mm: number; maxFaceRotLR_deg: number; maxFaceRotUD_deg: number; maxMovement_mm: number; minInterPupilDist_px: number; minimumFps: number; movementWindow_ms: number; threshBright: number; threshDark: number; } interface ChunkSent { data: { Params: { ID: string; }; Action: ChunkAction; Payload: string; }; chunkNumber: number; numberChunks: number; startTime_s: number; endTime_s: number; duration_s: number; metadata: Uint8Array; } declare const pointGroup: { readonly METADATA: "metadata"; readonly PHYSICAL: "physical"; readonly GENERAL_RISKS: "generalRisks"; readonly VITALS: "vitals"; readonly PHYSIOLOGICAL: "physiological"; readonly METABOLIC_RISKS: "metabolicRisks"; readonly BLOOD_BIOMARKERS: "bloodBiomarkers"; readonly OVERALL: "overall"; readonly MENTAL: "mental"; readonly SURVEYS: "surveys"; }; interface MeasurementOptions { userProfileId?: string; partnerId?: string; } interface LoggerSettings { mediaPipe?: boolean; beforeRESTCall?: boolean; afterRESTCall?: boolean; extractionLibWasm?: boolean; apiClient?: boolean; webSocket?: boolean; extractionWorker?: boolean; faceTrackerWorkers?: boolean; sdk?: boolean; } interface Settings { mediaElement: HTMLDivElement; assetFolder: string; apiUrl?: string; logger?: LoggerSettings; metrics?: boolean; mirrorVideo?: boolean; displayMediaStream?: boolean; constraintOverrides?: Partial<ConstraintsConfig>; } interface Demographics { age: number; height: number; weight: number; sex: number; smoking: number; bloodPressureMedication: number; diabetes: number; unit: 'Metric' | 'Imperial'; } interface ResultsError { code: string; errors: { [x: string]: { messages: string[]; }; }; } type PointGroupType = typeof pointGroup[keyof typeof pointGroup]; type BandColors = ('YELLOW' | 'LIGHT_GREEN' | 'GREEN' | 'LIGHT_RED' | 'RED')[]; interface IMeta { availableAfterSec: number; range: { min: number; max: number; }; requirements: { profileInfo: boolean; medicalHistory: boolean; }; group: PointGroupType; ranges: { [x: string]: number[][][]; }; dialBandColors: { [x: string]: BandColors; }; } interface DialSection { groupSize: number; bandColor: 'YELLOW' | 'LIGHT_GREEN' | 'GREEN' | 'LIGHT_RED' | 'RED'; range: number[]; } interface Point { channel: string; notes: string[]; value: string; dial: { sections: DialSection[]; group: number; subGroup: number; }; meta: IMeta; info: { name: string; unit: string; }; } interface Points { [x: string]: Point; } interface Results { measurementId: string; measurementResultId: string; resultsOrder: number; finalChunkNumber: number; points: Points; errors: ResultsError; statusId: string; } type IsoDate = `${number}-${number}-${number}T${number}:${number}:${number}.${number}Z`; interface SDKVersion { webSDK: string; extractionLib: { version: string; sdkId: string; }; faceTracker: string; } interface Drawables { face: DfxFace; annotations: Annotations; starRating: number; percentCompleted: number; } interface IMediaElementSize { width: number; height: number; x: number; y: number; } interface IFrameInfo { mediaStreamWidth: number; mediaStreamHeight: number; faceTrackerWidth: number; faceTrackerHeight: number; } interface IMaskResize { mediaElementSize: IMediaElementSize; videoElementSize: VideoElementSize; frameInfo: IFrameInfo; isPortrait: boolean; aspectRatio: number; } interface MediaElementResizeEvent extends CustomEvent { detail: IMaskResize; } /** * Face attribute values used to define demographic information * @enum */ declare const faceAttributeValue: { readonly SEX_NOT_PROVIDED: 1; readonly SEX_ASSIGNED_MALE_AT_BIRTH: 2; readonly SEX_ASSIGNED_FEMALE_AT_BIRTH: 3; readonly DIABETES_NONE: 4; readonly DIABETES_TYPE1: 5; readonly DIABETES_TYPE2: 6; readonly SMOKER_TRUE: 0; readonly SMOKER_FALSE: 1; readonly BLOOD_PRESSURE_MEDICATION_TRUE: 1; readonly BLOOD_PRESSURE_MEDICATION_FALSE: 0; }; /** * Face tracker states * @enum */ declare const faceTrackerState: { readonly ASSETS_NOT_DOWNLOADED: "ASSETS_NOT_DOWNLOADED"; readonly NOT_LOADED: "NOT_LOADED"; readonly LOADING: "LOADING"; readonly LOADED: "LOADED"; readonly READY: "READY"; }; /** * Face Tracker State * * `ASSETS_NOT_DOWNLOADED`: Assets required for face tracking have not been downloaded. * * `NOT_LOADED`: Face tracker is not loaded. * * `LOADING`: Face tracker is currently loading. * * `LOADED`: Face tracker has been loaded but is not yet ready. * * `READY`: Face tracker is ready to use. */ type FaceTrackerState = typeof faceTrackerState[keyof typeof faceTrackerState]; /** * Error categories enum * @enum */ declare const errorCategories: { readonly COLLECTOR: "COLLECTOR"; readonly ASSET_DOWNLOAD: "ASSET_DOWNLOAD"; }; /** * Error Categories * * `COLLECTOR`: Errors related to the collector, such as issues with data collection or processing. * * `ASSET_DOWNLOAD`: Errors related to downloading assets, such as face tracking models or other required files. */ type ErrorCategories = typeof errorCategories[keyof typeof errorCategories]; /** * Constraint Feedback enum * @enum */ declare const constraintFeedback: { readonly FACE_NONE: "FaceNone"; readonly FACE_OFF_TARGET: "FaceOffTarget"; readonly FACE_DIRECTION: "FaceDirection"; readonly FACE_FAR: "FaceFar"; readonly FACE_MOVEMENT: "FaceMovement"; readonly IMAGE_BRIGHT: "ImageBright"; readonly IMAGE_DARK: "ImageDark"; readonly IMAGE_QUALITY: "ImageQuality"; readonly IMAGE_BACKLIT: "ImageBackLit"; readonly LOW_FPS: "LowFps"; }; /** * Constraint Feedback * * `FaceNone`: No face detected, move face into target region. * * `FaceOffTarget`: Face not in target region, move face into target region. * * `FaceDirection`: Not looking at camera, look straight at the camera. * * `FaceFar`: Too far from camera, move closer to the camera. * * `FaceMovement`: Moving too much, hold still. * * `ImageBright`: Image too bright, try a darker room. * * `ImageDark`: Image too dark, try a brighter room. * * `ImageQuality`: Bad image quality, improve image quality - try alternate webcam. * * `ImageBackLit`: Backlit face, remove backlight behind face. * * `LowFps`: Framerate too low, try alternate webcam or a brighter room. * */ type ConstraintFeedback = typeof constraintFeedback[keyof typeof constraintFeedback]; /** * Constraint Status enum * @enum */ declare const constraintStatus: { readonly GOOD: "Good"; readonly WARN: "Warn"; readonly ERROR: "Error"; }; /** * Constraint Feedback * * `Good`: indicates there is nothing presently detected in constraints * * `Warn`: indicates a problem that needs to be corrected * * `Error`: indicates a problem that has failed the measurement */ type ConstraintStatus = typeof constraintStatus[keyof typeof constraintStatus]; declare class Measurement { #private; readonly on: { /** * before REST call * @param {IsoDate} timestamp - timestamp of the event */ beforeRESTCall: ((timestamp: IsoDate, actionId: number) => void) | null; /** * after REST call * @param {IsoDate} timestamp - timestamp of the event * @param {string} status - HTTP status code * @param {unknown} error - error object */ afterRESTCall: ((timestamp: IsoDate, actionId: number, status: string, error: unknown) => void) | null; /** * bytes downloaded * @param {number} bytes - number of bytes downloaded * @param {number} uncompressedSize - uncompressed size of the file * @param {string} url - download URL * @param {boolean} done - true if download is complete * * Note: If server-side compression is enabled, then you're comparing the downloaded byte count * (from the network stream) to the uncompressed file size which is not reliable. */ bytesDownloaded: ((bytes: number, uncompressedSize: number, url: string, done: boolean) => void) | null; /** * when face tracker state Changes * @param {faceTrackerState} state - face tracker state */ faceTrackerStateChanged: ((state: FaceTrackerState) => void) | null; /** * when measurement results are received * @param {any} results - measurement results */ resultsReceived: ((results: Results) => void) | null; /** * when measurement results are received * @param {any} results - measurement results */ constraintsUpdated: ((feedback: ConstraintFeedback, status: ConstraintStatus) => void) | null; /** * When media element size changes * @param {event} MediaElementResizeEvent */ mediaElementResize: ((event: MediaElementResizeEvent) => void) | null; /** * When facial landmarks are updated * @param {drawables} Drawables */ facialLandmarksUpdated: ((drawables: Drawables) => void) | null; /** * When a chunk is sent to DeepAffex * @param {chunkSent} ChunkSent */ chunkSent: ((chunkSent: ChunkSent) => void) | null; /** * When an error occurs * @param {ErrorCategories} category - error category * @param {unknown} data - error data */ error: ((category: ErrorCategories, data: unknown) => void) | null; }; /** * Initialize the Measurement SDK * @param {object} settings - Initialization settings * @returns Promise<Measurement> */ static init(settings: Settings): Promise<Measurement>; private constructor(); loadMask(element: SVGSVGElement): void; /** * Set settings * @param {Settings} newSettings * @returns {boolean} true if success */ setSettings(newSettings: Partial<Settings>): boolean; /** * Returns version number * @returns {SDKVersion} version - [Web SDK, DFX Extraction Lib, Face Tracker] */ getVersion(): SDKVersion; /** * Check if SIMD is supported and then download the supported MediaPipe * face traker assets for the runtime environment * It also downloads the extraction lib assets * @returns true if successfully download all files */ downloadAssets(): Promise<boolean | undefined>; /** * Set extraction library settings * @param {number} numberofChunks Number of chunks for extraction library collector * @param {number} targetFPS Target FPS for extraction library collector * @param {number} chunkDurationSeconds Chunk duration in seconds for extraction library collector */ setExtractionLibSettings(numberofChunks?: number, targetFPS?: number, chunkDurationSeconds?: number): void; /** * Set the action for the next chunk to LAST::PROCESS */ setNextChunkAsFinal(): Promise<void>; startTracking(): Promise<void>; /** * Stop Face Tracker tracking frames and DFX extraction library collection * If the measurement is started, it will disconnect from the Web Socket as well. */ stopTracking(): Promise<void>; destroy(): Promise<void>; setMediaStream(mediaStream: MediaStream): Promise<void>; prepare(token: string, refreshToken: string, studyId: string, sdkId?: string): Promise<void>; startMeasurement(measurementOptions?: MeasurementOptions): Promise<void>; setDemographics(demographics: Demographics): void; setObjectFit(fit: ObjectFit): boolean; } export { type ChunkSent, type ConstraintFeedback, type ConstraintStatus, type ConstraintsConfig, type Demographics, type Drawables, type ErrorCategories, type FaceTrackerState, type IsoDate, Measurement, type MeasurementOptions, type MediaElementResizeEvent, type Results, type Settings, constraintFeedback, constraintStatus, errorCategories, faceAttributeValue, faceTrackerState };