Skip to content
On this page

Session State

A measuring session is always in a "state". The session transitions between possible states either by following an API action called by the application, or via internal logic that is intended to prepare the session for performing measurements. The session state diagram appears in the figure below.

Session States

State Diagram

The table below provides a description of each session state:

State NameState Definition
INITIALIZINGThe session is in its initial state, performing initialization actions. Please wait until you receive the message indicating that the session is in the READY state before starting to measure vital signs or before calling any session APIs.
READYThe session is now ready to be started. The application can display the camera preview. Refer to the Creating a Preview page for detailed instructions.
STARTINGThe session is currently preparing to measure vital signs.
PROCESSINGThe session is processing the images and calculating vital signs. For information on the handling of instantaneous vital signs, please refer to the Vital Signs page.
STOPPINGThe session has been stopped, and the measurement results are being calculated. For information on the handling the final results, please see the Vital Signs page.
TERMINATINGThe session is currently being terminated. Please refrain from calling any session APIs.
TERMINATEDThe session has been gracefully terminated, and a new session can now be initiated.

Session State Transitions

The table below describes the actions that cause a transition between the states:

StateNext StateTrigger
INITIALIZINGREADYOnce all initialization actions are completed, the session transitions to the READY state.
READYSTARTINGCalling the start() method causes the session to transition to the STARTING state.
STARTINGPROCESSINGThe session's actions in the STARTING state were completed.
PROCESSINGSTOPPINGThe session will transition to the STOPPING state under the following circumstances:
*The measurement ends gracefully either because it reached the defined duration or due to a manual invocation of the stop() method.
*The measurement was stopped due to an error. Refer to the Alerts section for more information.
STOPPINGREADYThe SDK has finished performing the vital sign calculations.
READYTERMINATINGBy calling the terminate() method, the session transitions to the TERMINATING state.
TERMINATINGTERMINATEDThe termination actions have been completed.

Note

The STARTING, STOPPING and TERMINATING states are 'transition states' that end automatically after a short period. Do not call any session methods while the session is in transition.

Receiving Session State Updates

The application can receive session state updates by using useSessionState hook:

TypeScript
import { 
    SessionState, 
    useSessionState, 
} from 'binah-react-native-sdk';

const sessionState = useSessionState();

React.useEffect(() => {
    // Receive session state updates
}, [sessionState])

Handling State Transitions

The code below is a simple example for handling session transitions updates by using useSessionState hook:

TypeScript
import { 
    SessionState, 
    useSessionState, 
} from 'binah-react-native-sdk';

const sessionState = useSessionState();

React.useEffect(() => {
    switch (sessionState) {
        case SessionState.INITIALIZING:
            console.log("Session is initializing and NOT ready");
            break;
        case SessionState.READY:
            console.log("Session is ready to start measuring");
            break;
        case SessionState.STARTING:
            console.log("Session is preparing for the measurement of vital signs");
            break;
        case SessionState.PROCESSING:
            console.log("Session is measuring vital signs");
            break;
        case SessionState.STOPPING:
            console.log("Session is stopping the measuring of vital signs");
            break;
        case SessionState.TERMINATING:
            console.log("Session is preparing to terminate");
            break;
        case SessionState.TERMINATED:
            console.log("Session is terminated");
            break;
    }
}, [sessionState])