### Configure Shenai in MAUI App Source: https://developer.shen.ai/getting-started/initialization Configure the Shenai SDK within a .NET MAUI application by using the `UseShenai` extension method. This setup is typically done in the `MauiProgram.cs` file. ```csharp using Shenai.Maui; var builder = MauiApp.CreateBuilder(); builder.UseMauiApp() .UseShenai(); ``` -------------------------------- ### Manage SDK Screens - Web Source: https://developer.shen.ai/getting-started/configuration This JavaScript example illustrates how to manage SDK screens in a web environment. It defines a constant object for screen states and uses the shenaiSDK object to get and set the current screen. ```javascript const Screen = { INITIALIZATION: 0, ONBOARDING: 1, MEASUREMENT: 2, INSTRUCTIONS: 3, RESULTS: 4, HEALTH_RISKS: 5, HEALTH_RISKS_EDIT: 6, CALIBRATION_ONBOARDING: 7, CALIBRATION_FINISH: 8, CALIBRATION_DATA_ENTRY: 9, DISCLAIMER: 10, DASHBOARD: 11, } as const; const screen = shenaiSDK.getScreen(); shenaiSDK.setScreen(Screen.RESULTS); ``` -------------------------------- ### Set and Get Measurement Presets (Capacitor) Source: https://developer.shen.ai/getting-started/configuration This example shows how to interact with measurement presets using the Capacitor Shenai SDK. It includes fetching the current preset with `getMeasurementPreset` and setting a new preset using `setMeasurementPreset`, passing the desired preset enum value, such as `MeasurementPreset.ONE_MINUTE_ALL_METRICS`. ```javascript import { ShenaiSdkCapacitor, MeasurementPreset } from 'capacitor-shenai-sdk'; const { value: preset } = await ShenaiSdkCapacitor.getMeasurementPreset(); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.ONE_MINUTE_ALL_METRICS }); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.FOURTY_FIVE_SECONDS_ALL_METRICS }); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.THIRTY_SECONDS_ALL_METRICS }); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.INFINITE_HR }); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.INFINITE_METRICS }); await ShenaiSdkCapacitor.setMeasurementPreset({ preset: MeasurementPreset.QUICK_HR_MODE }); ``` -------------------------------- ### Install Local Web SDK Package using npm Source: https://developer.shen.ai/platforms/web This snippet demonstrates how to reference a locally downloaded and unzipped Shen.ai SDK package in your project's package.json file when using a package manager like npm, yarn, or pnpm. Ensure the 'shenai-sdk' directory is placed in your project root. ```json { "dependencies": { "shenai-sdk": "file:shenai-sdk" } } ``` -------------------------------- ### Starting the Measurement Programmatically Source: https://developer.shen.ai/video-measurement/preparation This section explains how to initiate the video measurement process programmatically by setting the SDK's operating mode. ```APIDOC ## Set Operating Mode to Measure ### Description Allows you to programmatically start the video measurement by setting the SDK's operating mode to `Measure`. This mimics the action of a user clicking a 'START' button in the UI. ### Method - `setOperatingMode(OperatingMode.measure)` - `setOperatingMode(OperatingMode.MEASURE)` ### Endpoint N/A (This is a programmatic SDK call) ### Parameters #### Request Body - **operatingMode** (OperatingMode enum) - Required - Specifies the desired operating mode for the SDK. Use `Measure` or `MEASURE`. ### Request Example ```javascript // Example for React Native SDK import { setOperatingMode, OperatingMode } from 'react-native-shenai-sdk'; await setOperatingMode(OperatingMode.MEASURE); ``` ### Response #### Success Response (200) Indicates the operating mode has been successfully set. #### Response Example ```json { "status": "success", "message": "Operating mode set to MEASURE" } ``` ``` -------------------------------- ### Initialize SDK in Capacitor App Source: https://developer.shen.ai/getting-started/initialization Initialize the Shenai SDK in a Capacitor application using the `ShenaiSdkCapacitor` module. This requires an API key for initialization. ```typescript import { ShenaiSdkCapacitor } from 'capacitor-shenai-sdk'; const initShenai = async () => { await ShenaiSdkCapacitor.initialize({ apiKey: API_KEY }); }; ``` -------------------------------- ### Set SDK Operating Mode (Capacitor) Source: https://developer.shen.ai/getting-started/configuration Provides an example of setting the operating mode for the Shen.ai SDK using Capacitor. It includes functions to get and set the operating mode, with specific constants for MEASURE and POSITIONING. The SystemOverloaded mode is not settable. ```typescript import { ShenaiSdkCapacitor, OperatingMode } from 'capacitor-shenai-sdk'; const { value: mode } = await ShenaiSdkCapacitor.getOperatingMode(); await ShenaiSdkCapacitor.setOperatingMode({ operatingMode: OperatingMode.MEASURE }); await ShenaiSdkCapacitor.setOperatingMode({ operatingMode: OperatingMode.POSITIONING }); ``` -------------------------------- ### Deinitialize SDK (Capacitor) Source: https://developer.shen.ai/getting-started/initialization Use the ShenaiSdkCapacitor class from the capacitor-shenai-sdk package to asynchronously deinitialize the SDK, freeing resources and disconnecting from the camera. This method is asynchronous. ```typescript import { ShenaiSdkCapacitor } from 'capacitor-shenai-sdk'; await ShenaiSdkCapacitor.deinitialize(); ``` -------------------------------- ### Token Generation Example Source: https://developer.shen.ai/admin-api/authentication Example of using `curl` to generate a short-lived token using the Admin API. ```APIDOC ## Token Generation Example ### Description Example `curl` command to generate a short-lived token. ### Method POST ### Endpoint `https://api.shen.ai/v1/token` ### Parameters #### Request Headers - **Authorization** (string) - Required - The authentication token in the format `Bearer `. - **Content-Type** (string) - Required - Must be `application/json`. #### Request Body - **expires_in** (integer) - Required - The token's validity period in seconds. - **single_device** (boolean) - Optional - If true, the token is restricted to a single device. ### Request Example ```bash curl -X POST https://api.shen.ai/v1/token \ -H "Authorization: Bearer $SHENAI_ADMIN_KEY" \ -H "Content-Type: application/json" \ -d '{"expires_in":3600,"single_device":true}' ``` ### Response #### Success Response (200) - **token** (string) - The generated short-lived token. - **expires_at** (string) - The expiration timestamp of the token. #### Response Example ```json { "token": "tok_xxxxxxxxxxxxxxxxxxxxxxxxx", "expires_at": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### Deinitialize SDK (MAUI) Source: https://developer.shen.ai/getting-started/initialization Call the DeinitializeAsync method from the Shenai.Maui namespace to asynchronously deinitialize the SDK, releasing allocated resources and disconnecting from the camera. This is for .NET MAUI applications. ```csharp using Shenai.Maui; await ShenaiSdk.DeinitializeAsync(); ``` -------------------------------- ### Install Capacitor Plugin for Shen.AI Source: https://developer.shen.ai/platforms/capacitor This snippet shows how to add the `capacitor-shenai-sdk` as a dependency in your `package.json` file. This step is crucial for integrating Shen.AI into your hybrid application built with Capacitor. ```json { "dependencies": { ... "capacitor-shenai-sdk": "file:./capacitor-shenai-sdk" } } ``` -------------------------------- ### Embed SDK UI in Android App Source: https://developer.shen.ai/getting-started/initialization Embed the SDK's UI in an Android application using the `ShenAIView` class. The constructor requires the current `Activity` context. ```java import ai.mxlabs.shenai_sdk.ShenAIView; public class MainActivity extends ComponentActivity { ... ShenAIView shenaiView = new ShenAIView(this); setContentView(shenaiView); ... } ``` -------------------------------- ### Manage SDK Screens - iOS Source: https://developer.shen.ai/getting-started/configuration This example shows how to manage SDK screens in Swift for iOS development. It defines an enum for screen states and utilizes the ShenaiSDK object to retrieve and set the current screen. ```swift enum Screen { case initialization case onboarding case measurement case instructions case results case healthRisks case healthRisksEdit case calibrationOnboarding case calibrationFinish case calibrationDataEntry case disclaimer case dashboard } let screen = ShenaiSDK.getScreen() ShenaiSDK.setScreen(.results) ``` -------------------------------- ### Embed SDK UI in MAUI XAML Source: https://developer.shen.ai/getting-started/initialization Embed the SDK's UI in a MAUI application's XAML view using the `ShenaiSdkView` control. Ensure the necessary namespace is included. ```xml ``` -------------------------------- ### Set and Get Measurement Presets (iOS / Swift) Source: https://developer.shen.ai/getting-started/configuration This Swift code demonstrates how to set and get measurement presets in an iOS application using the Shenai SDK. It defines the `MeasurementPreset` enum locally and shows examples of calling `getMeasurementPreset` to retrieve the current setting and `setMeasurementPreset` to apply presets like `.oneMinuteAllMetrics`. ```swift enum MeasurementPreset { case oneMinuteAllMetrics case fourtyFiveSecondsAllMetrics case thirtySecondsAllMetrics case infiniteHr case infiniteMetrics case quickHrMode case custom } let preset = ShenaiSDK.getMeasurementPreset() ShenaiSDK.setMeasurementPreset(.oneMinuteAllMetrics) ShenaiSDK.setMeasurementPreset(.fourtyFiveSecondsAllMetrics) ShenaiSDK.setMeasurementPreset(.thirtySecondsAllMetrics) ShenaiSDK.setMeasurementPreset(.infiniteHr) ShenaiSDK.setMeasurementPreset(.infiniteMetrics) ShenaiSDK.setMeasurementPreset(.quickHrMode) ``` -------------------------------- ### Configure Initialization Settings for Shen AI Project Source: https://developer.shen.ai/getting-started/initialization Provides a comprehensive set of settings to configure the initialization and behavior of the Shen AI application. Includes options for modes, UI elements, and data saving. ```csharp public class InitializationSettings { public InitializationMode initializationMode; public PrecisionMode precisionMode; public OperatingMode operatingMode; public MeasurementPreset measurementPreset; public CameraMode cameraMode; public OnboardingMode onboardingMode; public boolean showUserInterface; public boolean showFacePositioningOverlay; public boolean showVisualWarnings; public boolean enableCameraSwap; public boolean showFaceMask; public boolean showBloodFlow; public boolean hideShenaiLogo; public boolean enableStartAfterSuccess; public boolean enableSummaryScreen; public boolean showResultsFinishButton; public boolean enableHealthRisks; public boolean showHealthIndicesFinishButton; public boolean saveHealthRisksFactors; public boolean showOutOfRangeResultIndicators; public boolean showTrialMetricLabels; public boolean showSignalQualityIndicator; public boolean showSignalTile; public boolean showStartStopButton; public boolean showInfoButton; public boolean showDisclaimer; public List uiFlowScreens; public EventCallback eventCallback; public RisksFactors risksFactors; } ``` ```swift class InitializationSettings { var initializationMode InitializationMode; var precisionMode: PrecisionMode var operatingMode: OperatingMode var measurementPreset: MeasurementPreset var cameraMode: CameraMode var onboardingMode: OnboardingMode var showUserInterface: Bool var showFacePositioningOverlay: Bool var showVisualWarnings: Bool var enableCameraSwap: Bool var showFaceMask: Bool var showBloodFlow: Bool var hideShenaiLogo: Bool var enableStartAfterSuccess: Bool var enableSummaryScreen: Bool var showResultsFinishButton: Bool var enableHealthRisks: Bool var showHealthIndicesFinishButton: Bool var saveHealthRisksFactors: Bool var showOutOfRangeResultIndicators: Bool var showTrialMetricLabels: Bool var showSignalQualityIndicator: Bool var showSignalTile: Bool var showStartStopButton: Bool var showInfoButton: Bool var showDisclaimer: Bool var uiFlowScreens: [NSNumber]? var eventCallback: ((Event) -> Void)? var risksFactors: RisksFactors? } ``` ```typescript interface InitializationSettings { initializationMode?: InitializationMode; precisionMode?: PrecisionMode; operatingMode?: OperatingMode; measurementPreset?: MeasurementPreset; cameraMode?: CameraMode; cameraAspectRatio?: number; onboardingMode?: OnboardingMode; showUserInterface?: boolean; showFacePositioningOverlay?: boolean; showVisualWarnings?: boolean; enableCameraSwap?: boolean; showFaceMask?: boolean; showBloodFlow?: boolean; hideShenaiLogo?: boolean; enableStartAfterSuccess?: boolean; enableSummaryScreen?: boolean; showResultsFinishButton?: boolean; enableHealthRisks?: boolean; showHealthIndicesFinishButton?: boolean; saveHealthRisksFactors?: boolean; showOutOfRangeResultIndicators?: boolean; showTrialMetricLabels?: boolean; showSignalQualityIndicator?: boolean; showSignalTile?: boolean; showStartStopButton?: boolean; showInfoButton?: boolean; showDisclaimer?: boolean; uiFlowScreens?: Screen[]; risksFactors?: RisksFactors; eventCallback?: (event: EventName) => void; onCameraError?: () => void; } ``` -------------------------------- ### Initialize Shen.ai SDK (MAUI) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK in a .NET MAUI application. Requires an API key and user ID. Camera permissions are a prerequisite. The initialization status is checked against an enum for successful completion or distinct error conditions. ```csharp using Shenai.Maui; const string API_KEY = ""; const string USER_ID = ""; var initResult = await ShenaiSdk.InitializeAsync(API_KEY, USER_ID); ``` ```csharp enum InitializationResult { OK = 0, INVALID_API_KEY, CONNECTION_ERROR, INTERNAL_ERROR, } if (initResult != InitializationResult.OK) { // handle error } ``` -------------------------------- ### Get Real-time Heart Rate (10s and 4s) Source: https://developer.shen.ai/video-measurement/measurement This section provides code examples for retrieving real-time heart rate data over 10-second and 4-second intervals using the Shen AI SDK. The 10-second average is more stable, while the 4-second average captures more immediate fluctuations. Examples are shown for Flutter, React Native, Capacitor, MAUI, iOS, Android, and Web. ```dart var hr = await ShenAiSdk.getHeartRate10s(); var hr = await ShenAiSdk.getHeartRate4s(); ``` ```javascript import { getHeartRate10s, getHeartRate4s } from 'react-native-shenai-sdk'; const hr10s = await getHeartRate10s(); const hr4s = await getHeartRate4s(); ``` ```javascript import { useRealtimeHeartRate, useRealtimeHeartRate4s } from 'react-native-shenai-sdk'; const hr10s = useRealtimeHeartRate(); const hr4s = useRealtimeHeartRate4s(); ``` ```javascript import { ShenaiSdkCapacitor } from 'capacitor-shenai-sdk'; const { value: hr10s } = await ShenaiSdkCapacitor.getHeartRate10s(); const { value: hr4s } = await ShenaiSdkCapacitor.getHeartRate4s(); ``` ```csharp using Shenai.Maui; var hr10s = await ShenaiSdk.GetHeartRate10sAsync(); var hr4s = await ShenaiSdk.GetHeartRate4sAsync(); ``` ```javascript let hr = ShenaiSDK.getHeartRate10s(); let hr = ShenaiSDK.getHeartRate4s(); ``` ```java int hr = ShenAiSdk.getHeartRate10s(); int hr = ShenAiSdk.getHeartRate4s(); ``` ```javascript const hr = shenaisdk.getHeartRate10s(); const hr = ShenAiSdk.getHeartRate4s(); ``` -------------------------------- ### Initialize Shen.ai SDK (Capacitor) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK within a Capacitor application. Requires an API key. Camera permissions are necessary before initialization. The outcome is verified against an enum to detect success or specific failure types. ```typescript import { ShenaiSdkCapacitor, InitializationResult } from 'capacitor-shenai-sdk'; const API_KEY = ""; const { value: initResult } = await ShenaiSdkCapacitor.initialize({ apiKey: API_KEY }); ``` ```typescript if (initResult != InitializationResult.OK) { // handle error } ``` -------------------------------- ### Initialize Shen.ai SDK (Web) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK on the web. This involves creating an SDK instance and then calling its initialize method with an API key and user ID. Error handling is done via a callback function. ```typescript import CreateShenaiSDK from "shenai-sdk"; const shenaiSDK = await CreateShenaiSDK(); const API_KEY = ""; // Use your API key here const USER_ID = ""; shenaiSDK.initialize( API_KEY, USER_ID, { /* settings */ }, (initResult) => { /* handle result */ } ); ``` ```typescript import { InitializationResult } from "shenai-sdk"; // Initialize the SDK and handle result in callback shenaiSDK.initialize(API_KEY, USER_ID, {}, (initResult) => { switch (initResult) { case InitializationResult.OK: // initialization succeeded break; case InitializationResult.INVALID_API_KEY: // handle invalid API key break; case InitializationResult.CONNECTION_ERROR: // handle connection error break; case InitializationResult.INTERNAL_ERROR: // handle internal error break; } }); ``` -------------------------------- ### Set and Get UI Element States (Flutter) Source: https://developer.shen.ai/getting-started/configuration This snippet demonstrates how to set and get the boolean states of various UI elements in the Shen AI SDK using Flutter. It covers elements like the user interface, face positioning overlay, visual warnings, camera swap, face mask, blood flow visualization, start after success, start/stop button, info button, and disclaimer. ```dart ShenaiSdk.setShowUserInterface(true); ShenaiSdk.getShowUserInterface(); ShenaiSdk.setShowFacePositioningOverlay(true); ShenaiSdk.getShowFacePositioningOverlay(); ShenaiSdk.setShowVisualWarnings(true); ShenaiSdk.getShowVisualWarnings(); ShenaiSdk.setEnableCameraSwap(true); ShenaiSdk.getEnableCameraSwap(); ShenaiSdk.setShowFaceMask(true); ShenaiSdk.getShowFaceMask(); ShenaiSdk.setShowBloodFlow(true); ShenaiSdk.getShowBloodFlow(); ShenaiSdk.setEnableStartAfterSuccess(true); ShenaiSdk.getEnableStartAfterSuccess(); ShenaiSdk.setShowStartStopButton(true); ShenaiSdk.getShowStartStopButton(); ShenaiSdk.setShowInfoButton(true); ShenaiSdk.getShowInfoButton(); ShenaiSdk.getShowDisclaimer(); ``` -------------------------------- ### Set SDK Operating Mode (Web) Source: https://developer.shen.ai/getting-started/configuration Illustrates setting the operating mode for the Shen.ai SDK in a web environment. This example shows how to initialize the SDK with a specific operating mode and how to dynamically change it. It also demonstrates checking the current mode. ```javascript import { OperatingMode } from "shenai-sdk"; shenaiSDK.initialize(..., { operatingMode: OperatingMode.MEASURE, ... }); const mode = shenaiSDK.getOperatingMode(); switch (mode) { case OperatingMode.POSITIONING: console.log("SDK is positioning"); break; case OperatingMode.MEASURE: console.log("SDK is measuring"); break; case OperatingMode.SYSTEM_OVERLOADED: console.log("SDK is paused due to system overload"); break; } shenaiSDK.setOperatingMode(OperatingMode.POSITIONING); shenaiSDK.setOperatingMode(OperatingMode.MEASURE); // shenaiSDK.setOperatingMode(OperatingMode.SYSTEM_OVERLOADED); // not allowed ``` -------------------------------- ### Initialize SDK with Partially Custom UI Source: https://developer.shen.ai/getting-started/choosing-mode Configure SDK to display only the camera feed and positioning hints by disabling built-in UI elements. This allows for custom UI management while leveraging SDK's camera handling. Set 'showUserInterface' to false and 'onboardingMode' to HIDDEN during initialization. ```Swift let settings = InitializationSettings() settings.showUserInterface = false settings.onboardingMode = .hidden // Initialize SDK with these settings ``` -------------------------------- ### Set and Get Measurement Presets (Flutter) Source: https://developer.shen.ai/getting-started/configuration This snippet demonstrates how to set and retrieve measurement presets in Flutter using the Shenai SDK. It includes the enum definition for `MeasurementPreset` and examples of calling `setMeasurementPreset` with various predefined options. The default preset is `oneMinuteAllMetrics`. ```dart enum MeasurementPreset { oneMinuteAllMetrics, fourtyFiveSecondsAllMetrics, thirtySecondsAllMetrics, infiniteHr, infiniteMetrics, quickHrMode, custom, } var preset = await ShenaiSdk.getMeasurementPreset(); ShenaiSdk.setMeasurementPreset(MeasurementPreset.oneMinuteAllMetrics); ShenaiSdk.setMeasurementPreset(MeasurementPreset.fourtyFiveSecondsAllMetrics); ShenaiSdk.setMeasurementPreset(MeasurementPreset.thirtySecondsAllMetrics); ShenaiSdk.setMeasurementPreset(MeasurementPreset.infiniteHr); ShenaiSdk.setMeasurementPreset(MeasurementPreset.infiniteMetrics); ShenaiSdk.setMeasurementPreset(MeasurementPreset.quickHrMode); ``` -------------------------------- ### Configure Shen.ai SDK Loader (Web) Source: https://developer.shen.ai/getting-started/initialization Allows configuration of the Shen.ai SDK's loader behavior before the engine boots on the web. Options include error reporting, preload display, hiding the logo, and WASM loading progress callbacks. ```typescript const shenaiSDK = await CreateShenaiSDK({ enablePreloadDisplay: true, hidePreloadDisplayLogo: false, wasmLoadingProgressCallback: (value) => console.log(`Loading ${(value * 100).toFixed(0)}%`), }); ``` -------------------------------- ### Set and Get Measurement Presets (Android / Java) Source: https://developer.shen.ai/getting-started/configuration This Java code snippet shows how to manage measurement presets within an Android application using the Shenai SDK. It includes the `MeasurementPreset` enum definition and provides examples of retrieving the current preset using `getMeasurementPreset` and setting new presets via `setMeasurementPreset`, referencing constants like `ShenAIAndroidSDK.MeasurementPreset.ONE_MINUTE_ALL_METRICS`. ```java enum MeasurementPreset { ONE_MINUTE_ALL_METRICS, FOURTY_FIVE_SECONDS_ALL_METRICS, THIRTY_SECONDS_ALL_METRICS, INFINITE_HR, INFINITE_METRICS, QUICK_HR_MODE, CUSTOM } MeasurementPreset preset = shenaiSDK.getMeasurementPreset(); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.ONE_MINUTE_ALL_METRICS); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.FOURTY_FIVE_SECONDS_ALL_METRICS); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.THIRTY_SECONDS_ALL_METRICS); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.INFINITE_HR); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.INFINITE_METRICS); shenaiSDK.setMeasurementPreset(ShenAIAndroidSDK.MeasurementPreset.QUICK_HR_MODE); ``` -------------------------------- ### C# Initialization Settings and Events for MAUI/Android/iOS Source: https://developer.shen.ai/getting-started/initialization Provides the C# definitions for InitializationSettings and EventName used in .NET MAUI, Android, and iOS applications. This includes an enum for event names and a sealed class for settings, allowing developers to configure the Shen.AI SDK with nullable properties for flexibility. Uses C#. ```csharp using Shenai.Maui; public enum EventName { START_BUTTON_CLICKED = 0, STOP_BUTTON_CLICKED, MEASUREMENT_FINISHED, USER_FLOW_FINISHED, SCREEN_CHANGED, } public sealed class InitializationSettings { public PrecisionMode? PrecisionMode { get; set; } public OperatingMode? OperatingMode { get; set; } public MeasurementPreset? MeasurementPreset { get; set; } public CameraMode? CameraMode { get; set; } public OnboardingMode? OnboardingMode { get; set; } public bool? ShowUserInterface { get; set; } public bool? ShowFacePositioningOverlay { get; set; } public bool? ShowVisualWarnings { get; set; } public bool? EnableCameraSwap { get; set; } public bool? ShowFaceMask { get; set; } public bool? ShowBloodFlow { get; set; } public bool? HideShenaiLogo { get; set; } public bool? EnableStartAfterSuccess { get; set; } public bool? EnableSummaryScreen { get; set; } public bool? EnableHealthRisks { get; set; } public bool? SaveHealthRisksFactors { get; set; } public bool? ShowOutOfRangeResultIndicators { get; set; } public bool? ShowTrialMetricLabels { get; set; } public bool? ShowSignalQualityIndicator { get; set; } public bool? ShowSignalTile { get; set; } public bool? ShowStartStopButton { get; set; } public bool? ShowInfoButton { get; set; } public IReadOnlyList? UiFlowScreens { get; set; } ``` -------------------------------- ### Get Real-time Metrics (HRV, Stress Index) Source: https://developer.shen.ai/video-measurement/measurement This section demonstrates how to query the SDK for real-time Heart Rate Variability (HRV) and Stress Index values over a specified period in seconds. Shorter periods may yield unstable values but can be useful for biofeedback. Examples are provided for Flutter, React Native, Capacitor, MAUI, iOS, Android, and Web. Note that Breathing Rate and Blood Pressure will be null. ```dart var metrics = await ShenaiSDK.getRealtimeMetrics(30.0); ``` ```typescript import { getRealtimeMetrics, MeasurementResults } from 'react-native-shenai-sdk'; const metrics: MeasurementResults = await getRealtimeMetrics(30.0); ``` ```typescript import { ShenaiSdkCapacitor, MeasurementResults } from 'capacitor-shenai-sdk'; const { value: metrics } = await ShenaiSdkCapacitor.getRealtimeMetrics({ periodSec: 30.0 }); ``` ```csharp using Shenai.Maui; var metrics = await ShenaiSdk.GetRealtimeMetricsAsync(30.0f); ``` ```javascript let metrics = ShenaiSDK.getRealtimeMetrics(30.0) ``` ```java MeasurementResults metrics = shenaiSDKHandler.getRealtimeMetrics(30.0); ``` ```javascript const metrics = await shenaiSDK.getRealtimeMetrics(30.0); ``` -------------------------------- ### Set and Get UI Element States (Capacitor) Source: https://developer.shen.ai/getting-started/configuration This snippet illustrates how to configure and query the state of UI elements in the Shen AI SDK using Capacitor. It demonstrates asynchronous calls to set and get boolean values for UI features, with values passed in an object format. ```typescript import { ShenaiSdkCapacitor } from 'capacitor-shenai-sdk'; await ShenaiSdkCapacitor.setShowUserInterface({ value: true }); const { value: showUserInterface } = await ShenaiSdkCapacitor.getShowUserInterface(); await ShenaiSdkCapacitor.setShowFacePositioningOverlay({ value: true }); const { value: showFacePositioningOverlay } = await ShenaiSdkCapacitor.getShowFacePositioningOverlay(); await ShenaiSdkCapacitor.setShowVisualWarnings({ value: true }); const { value: showVisualWarnings } = await ShenaiSdkCapacitor.getShowVisualWarnings(); await ShenaiSdkCapacitor.setEnableCameraSwap({ value: true }); const { value: enableCameraSwap } = await ShenaiSdkCapacitor.getEnableCameraSwap(); await ShenaiSdkCapacitor.setShowFaceMask({ value: true }); const { value: showFaceMask } = await ShenaiSdkCapacitor.getShowFaceMask(); await ShenaiSdkCapacitor.setShowBloodFlow({ value: true }); const { value: showBloodFlow } = await ShenaiSdkCapacitor.getShowBloodFlow(); await ShenaiSdkCapacitor.setEnableStartAfterSuccess({ value: true }); ``` -------------------------------- ### Set and Get Measurement Presets (React Native) Source: https://developer.shen.ai/getting-started/configuration This code demonstrates setting and getting measurement presets in React Native using the `react-native-shenai-sdk` library. It shows how to import the necessary functions and enum, then use `getMeasurementPreset` to retrieve the current setting and `setMeasurementPreset` to apply different presets like `ONE_MINUTE_ALL_METRICS`. ```javascript import {getMeasurementPreset, setMeasurementPreset, MeasurementPreset} from 'react-native-shenai-sdk'; const preset = await getMeasurementPreset(); setMeasurementPreset(MeasurementPreset.ONE_MINUTE_ALL_METRICS); setMeasurementPreset(MeasurementPreset.FOURTY_FIVE_SECONDS_ALL_METRICS); setMeasurementPreset(MeasurementPreset.THIRTY_SECONDS_ALL_METRICS); setMeasurementPreset(MeasurementPreset.INFINITE_HR); setMeasurementPreset(MeasurementPreset.INFINITE_METRICS); setMeasurementPreset(MeasurementPreset.QUICK_HR_MODE); ``` -------------------------------- ### Set and Get UI Element States (React Native) Source: https://developer.shen.ai/getting-started/configuration This snippet shows how to set and get the states of UI elements within the Shen AI SDK using React Native. It imports necessary functions and demonstrates setting boolean values for various UI controls and then retrieving their current states asynchronously. ```javascript import { setShowUserInterface, getShowUserInterface, setShowFacePositioningOverlay, getShowFacePositioningOverlay, setShowVisualWarnings, getShowVisualWarnings, setEnableCameraSwap, getEnableCameraSwap, setShowFaceMask, getShowFaceMask, setShowBloodFlow, getShowBloodFlow, setEnableStartAfterSuccess, getEnableStartAfterSuccess, setShowStartStopButton, getShowStartStopButton, setShowInfoButton, getShowInfoButton, getShowDisclaimer } from 'react-native-shenai-sdk'; setShowUserInterface(true); const showUserInterface = await getShowUserInterface(); setShowFacePositioningOverlay(true); const showFacePositioningOverlay = await getShowFacePositioningOverlay(); setShowVisualWarnings(true); const showVisualWarnings = await getShowVisualWarnings(); setEnableCameraSwap(true); const enableCameraSwap = await getEnableCameraSwap(); setShowFaceMask(true); const showFaceMask = await getShowFaceMask(); setShowBloodFlow(true); const showBloodFlow = await getShowBloodFlow(); setEnableStartAfterSuccess(true); const enableStartAfterSuccess = await getEnableStartAfterSuccess(); setShowStartStopButton(true); const showStartStopButton = await getShowStartStopButton(); setShowInfoButton(true); const showInfoButton = await getShowInfoButton(); const showDisclaimer = await getShowDisclaimer(); ``` -------------------------------- ### Initialize Shen.ai SDK (Android) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK on Android. Requires the application context, an API key, and a user ID. Camera permissions are mandatory. The initialization outcome is checked against an enum to identify success or particular error conditions. ```kotlin import ai.mxlabs.shenai_sdk.ShenAIAndroidSDK val API_KEY = "" val USER_ID = "" // Assuming shenaiSDKHandler is an instance of ShenAIAndroidSDK or a handler class val initResult = shenaiSDKHandler.initialize(this, API_KEY, USER_ID) ``` ```kotlin enum InitializationResult { OK, INVALID_API_KEY, CONNECTION_ERROR, INVALID } if (initResult != InitializationResult.OK) { // handle error } ``` -------------------------------- ### Web: Customize Preload Display Canvas Source: https://developer.shen.ai/getting-started/initialization When manually attaching the SDK to a custom canvas, it's recommended to specify the same canvas for the preload display. This ensures a consistent user experience before the SDK is fully loaded. ```javascript // In shenai-sdk/index.mjs createPreloadDisplay("not-mxcanvas"); ``` -------------------------------- ### Open PDF Report in Browser - Cross-Platform SDK Examples Source: https://developer.shen.ai/pdf-reports Provides examples for opening a generated PDF report directly in the end-user's web browser via a 'print' dialog using the `openMeasurementResultsPdfInBrowser` method across different platforms. Prerequisites include a stable internet connection and successful completion of the video measurement. ```flutter ShenaiSDK.openMeasurementResultsPdfInBrowser() ``` ```react-native import {openMeasurementResultsPdfInBrowser} from 'react-native-shenai-sdk'; openMeasurementResultsPdfInBrowser(); ``` ```capacitor import { ShenaiSdkCapacitor } from 'capacitor-shenai-sdk'; await ShenaiSdkCapacitor.openMeasurementResultsPdfInBrowser(); ``` ```maui using Shenai.Maui; await ShenaiSdk.OpenMeasurementResultsPdfInBrowserAsync(); ``` ```ios ShenaiSDK.openMeasurementResultsPdfInBrowser() ``` ```android shenaiSDKHandler.openMeasurementResultsPdfInBrowser(); ``` ```web shenaiSDK.openMeasurementResultsPdfInBrowser(); ``` -------------------------------- ### Initialize Shen.ai SDK (iOS) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK on iOS. Requires an API key and optionally a user ID and settings. Camera permissions must be granted. The initialization result is evaluated against an enum to determine success or specific error scenarios. ```swift import ShenaiSDK let API_KEY = ""; let init_result = ShenaiSDK.initialize(API_KEY, userID: nil, settings: nil) ``` ```swift enum InitializationResult { case success case failureInvalidApiKey case failureConnectionError case failureInternalError }; if (init_result != .success) { // handle error } ``` -------------------------------- ### GET /measurement/results Source: https://developer.shen.ai/video-measurement/results Retrieves the final metrics from the most recently completed measurement. Returns null if no measurement has finished successfully yet. ```APIDOC ## GET /measurement/results ### Description Call `getMeasurementResults()` to retrieve final metrics from the most recently completed measurement. If no measurement has finished successfully yet, a null value will be returned. ### Method GET ### Endpoint /measurement/results ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **heart_rate_bpm** (double) - Heart rate, rounded to 1 BPM - **hrv_sdnn_ms** (double?) - HRV, SDNN metric, rounded to 1 ms - **hrv_lnrmssd_ms** (double?) - HRV, lnRMSSD metric, rounded to 0.1 ms - **stress_index** (double?) - Stress Index, rounded to 0.1 - **parasympathetic_activity** (double?) - Parasympathetic activity, rounded to 1% - **breathing_rate_bpm** (double?) - Breathing rate, rounded to 1 BPM - **systolic_blood_pressure_mmhg** (double?) - Systolic blood pressure, rounded to 1 mmHg - **diastolic_blood_pressure_mmhg** (double?) - Diastolic blood pressure, rounded to 1 mmHg - **cardiac_workload_mmhg_per_sec** (double?) - Cardiac workload, rounded to 1 mmHg/s - **age_years** (double?) - Estimated age, rounded to 1 year - **bmi_kg_per_m2** (double?) - Estimated BMI, rounded to 0.01 - **bmiCategory** (BmiCategory?) - Estimated BMI category - **heartbeats** (List) - List of detected heartbeats - **average_signal_quality** (double) - Average signal quality metric #### Response Example ```json { "heart_rate_bpm": 75, "hrv_sdnn_ms": 50.5, "hrv_lnrmssd_ms": 25.2, "stress_index": 3.5, "parasympathetic_activity": 60, "breathing_rate_bpm": 16, "systolic_blood_pressure_mmhg": 120, "diastolic_blood_pressure_mmhg": 80, "cardiac_workload_mmhg_per_sec": 1.2, "age_years": 30, "bmi_kg_per_m2": 22.5, "bmiCategory": "normal", "heartbeats": [ { "start_location_sec": 0.5, "end_location_sec": 0.8, "duration_ms": 300 } ], "average_signal_quality": 0.95 } ``` #### Error Response (400) - **error** (string) - Description of the error ``` -------------------------------- ### Initialize Shen.ai SDK (React Native) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK in a React Native application. Requires an API key. The app must have camera permissions. The initialization result is compared against an enum to identify success or specific errors. ```typescript import { initialize, InitializationResult } from "react-native-shenai-sdk"; const API_KEY = ""; const initResult = await initialize(API_KEY); ``` ```typescript enum InitializationResult { OK, INVALID_API_KEY, CONNECTION_ERROR, INTERNAL_ERROR, } if (initResult != InitializationResult.OK) { // handle error } ``` -------------------------------- ### Real-time Heartbeat Intervals Source: https://developer.shen.ai/video-measurement/measurement Retrieves real-time heartbeat intervals. Optionally, a period can be specified to limit the heartbeats. Each interval includes start and end locations and the duration. ```APIDOC ## GET /realtime/heartbeats ### Description Retrieves real-time heartbeat intervals. Optionally, a period can be specified to limit the heartbeats. Each returned heartbeat interval includes the start and end locations (in seconds) and the duration between heartbeats (in milliseconds, rounded to the nearest integer). ### Method GET ### Endpoint /realtime/heartbeats ### Query Parameters - **period** (float) - Optional - The period in seconds to limit the heartbeats. ### Response #### Success Response (200) - **heartbeats** (array) - An array of heartbeat objects. Each object contains: - **start_location** (integer) - The start location of the heartbeat in seconds. - **end_location** (integer) - The end location of the heartbeat in seconds. - **duration** (integer) - The duration between heartbeats in milliseconds. ### Response Example ```json { "heartbeats": [ { "start_location": 0, "end_location": 5, "duration": 5000 }, { "start_location": 5, "end_location": 10, "duration": 5000 } ] } ``` ``` -------------------------------- ### Initialize ShenAI SDK with Measurement Preset Source: https://developer.shen.ai/getting-started/configuration Initializes the ShenAI SDK with a specified measurement preset. This configures the SDK for a particular data collection duration and metric set. Ensure the 'shenai-sdk' is imported. ```typescript import { MeasurementPreset } from "shenai-sdk"; shenaiSDK.initialize(..., { measurementPreset: MeasurementPreset.THIRTY_SECONDS_ALL_METRICS, }, ... ); ``` -------------------------------- ### Get Measurement Results (Java) Source: https://developer.shen.ai/video-measurement/results Retrieves measurement results using the shenaiSDKHandler in Java. This method is typically used in Android applications. It returns a MeasurementResults object containing various health metrics. ```java MeasurementResults results = shenaiSDKHandler.getMeasurementResults(); ``` -------------------------------- ### Initialize Shen.ai SDK (Flutter) Source: https://developer.shen.ai/getting-started/initialization Initializes the Shen.ai SDK in a Flutter application. Requires an API key and user ID. The app must have camera permissions. The result is checked against an enum for success or specific errors. ```dart import 'package:shenai_sdk/shenai_sdk.dart'; var API_KEY = "" var USER_ID = "" final _initResult = await ShenaiSdk.initialize(API_KEY, USER_ID); ``` ```dart enum InitializationResult { success, failInvalidApiKey, failConnectionError, failInternalError } if (_initResult != InitializationResult.success) { // handle error } ``` -------------------------------- ### Deinitialize SDK (React Native) Source: https://developer.shen.ai/getting-started/initialization Import and call the deinitialize function from the react-native-shenai-sdk package to free resources and disconnect from the camera. This is specific to React Native applications. ```javascript import { deinitialize } from "react-native-shenai-sdk"; deinitialize(); ``` -------------------------------- ### Get Measurement Results (Swift) Source: https://developer.shen.ai/video-measurement/results Retrieves measurement results using the ShenaiSDK in Swift. This method is typically used in iOS or macOS applications. It returns a MeasurementResults object containing various health metrics. ```swift let results = ShenaiSDK.getMeasurementResults() ```