Skip to content

Control Camera On / Off

Vitals™ SDK offers easy to use API for controlling the on and off state of the Vital Sign Camera.

Target SDK

JavaScript
React
Vue
Flutter
ReactNative
Android
iOS

TIP

You can refer to the sample code and the API Reference for more details. Most related API(s) include: VitalSignCameraCreationProps and VitalSignCameraInterface.

You can control the camera on and off state through the isActive property of the VitalSignCameraInterface, which should have been prepared in the Create Vital Sign Camera Guide, for example:

typescript
window.onload = () => {
    /* A reference of the camera, set isActive to true to turn on the camera by default, else false. */
    const cam = createVitalSignCamera({ isActive: true, config, userInfo })

    // ...
}
js
window.onload = () => {
    /* A reference of the camera, set isActive to true to turn on the camera by default, else false. */
    const cam = createVitalSignCamera({ isActive: true, config, userInfo })

    // ...
}

After the first initialization, you can turn off the Vital Sign Camera by:

typescript
cam.isActive = false;
js
cam.isActive = false;

To turn on the Vital Sign Camera, set isActive to true instead:

typescript
cam.isActive = true;
js
cam.isActive = true;

Example with Checkbox

In this example, we create a checkbox to toggle the on and off state of the Vital Sign Camera.

First, add a checkbox in the HTML file:

html
<!-- Camera IsActive Control -->
<label>
    <input type="checkbox" id="isActive"> isActive
</label>

After that, setup the initial state of the checkbox by reading cam.isActive, and set isActive to be the checkbox value on checkbox value changed:

typescript
/* Update the onload event handler function */
window.onload = () => {
    /* A reference of the camera that should have been created. */
    const cam = createVitalSignCamera({ isActive: true, config, userInfo })

    /* Setup the isActive checkbox event handler, to turn on / off the camera */
    const isActiveCheckbox = document.querySelector("#isActive") as HTMLInputElement;
    isActiveCheckbox.checked = cam.isActive;
    isActiveCheckbox.addEventListener('change', function() {
        cam.isActive = isActiveCheckbox.checked;
    })
}
js
/* Update the onload event handler function */
window.onload = () => {
    /* A reference of the camera that should have been created. */
    const cam = createVitalSignCamera({ isActive: true, config, userInfo })

    /* Setup the isActive checkbox event handler, to turn on / off the camera */
    const isActiveCheckbox = document.querySelector("#isActive");
    isActiveCheckbox.checked = cam.isActive;
    isActiveCheckbox.addEventListener('change', function() {
        cam.isActive = isActiveCheckbox.checked;
    })
}