JavaScript frontend SDK
The JavaScript SDK enables you to use IntelliProves features with ease from within your front end.
- JavaScript front-end project
This SDK only provides tools for front-end applications. Refer to our NodeJS SDK for JavaScript back-ends.
- Vue.JS 2
- Vue.JS 3
- React
Since our SDK does not use any framework-specific code, it should be compatible with most common JS web frameworks.
We recommend the use of TypeScript as it provides type hints and a better developer experience. However, our SDK works with CommonJS as well.
You can find our SDK on the node package manager repository for easy installation:
If you are not using an NPM-compatible package manager or just prefer using a CDN, you have multiple options. The most popular ones are:
- jsDelivr
- unpkg
If preferred you can also self-host our SDK by downloading our intelliprove-sdk.js file from a CDN or NPM. However, this is not recommended as updates will require you to manually re-download the latest file and update it on your own server(s).
More info on our API authentication can be found in our API docs. The action token, which you will use in your frontend to perform authentication as shown below, should be requested from your backend using your API key.
Attach the SDK to your current application. The attach method finds the user's available cameras, opens a camera stream, and previews the stream in the provided video object.
Parameters:
- videoElementId: string - HTML Element ID of the video element you want to attach to
- cameraId: string | null - OPTIONAL: A camera id if a specific camera is preferred
- streamWidth: MediaResolution | null - OPTIONAL: Custom width for video stream
- streamHeight: MediaResolution | null - OPTIONAL: Custom height for video stream
This method starts the measurement, i.e. performs the quality check and records a video. This corresponds to steps 2 and 3 found in our Integration guidelines.
Keep in mind, the attach method needs to be successful before calling start.
When calling start, first, an image from the camera stream will be captured and the quality check will be performed on the frame.
- If the quality check fails, a QualityError will be thrown with details on why the measurement cannot be started. More info on the quality check score and error type can be found here.
- If the quality check succeeds, the SDK will create a new measurement and start recording a video of the subject.
Parameters:
- length: number - The length of the recording
- chunkSize: number - The size of each video chunk when recording, default 500 ms.
- streamingMetadata: StreamingMetadata - An optional object with information about the subject and performer. See the models section below for more info
Exceptions: (doc)
- QualityError
- IntelliProveAPIError
- IntelliProveSDKError
When a measurement is started with the start method, the stopCallback method will automatically be called when the video is uploaded and processing has started. More info on the stopCallback here.
Finishing a measurement means stopping the recording and waiting for the results. Once available, the results of the processed video are returned as a BiomarkersResponse object.
In case we detect the video input requirements are not met, an EngineValidationError is returned. This could be related, for example, with the subject moving too much or looking away during from the camera the measurement.
Exceptions:
Cancel the current recording before it has been finished and reset the SDK.
Exceptions:
In case there is a need to manually retrieve the results for an existing measurement (referenced by UUID), the getResults method can be used. The results of the processed video are returned as a BiomarkersResponse object.
In case we detected something wrong with the recorded video, an EngineValidationError is returned. This could be related, for example, with the subject moving too much or looking away during the measurement.
Parameters:
- uuid: string - The UUID of the finished measurement
Exceptions:
If the user has multiple cameras, you can cycle through them using the nextCamera method. When the final camera has been reached and nextCamera is called again, the first camera will be selected again.
Those are simple representations of the models accessible through the SDK and their helper functions. All models have a .json() method to convert it to a normal JS object in case this is preferred.
Describes the quality of an image.
Helpers
- success(): boolean - Has the quality check succeeded
Holds the results of a processed video after a measurement.
Holds metadata info about a stream's subject and performer.
Holds information about the current measurement stream. StreamInfo objects are used as the parameter for the stopCallback and dataCallback
remaining is the amount of time the recording has left. It can be null if the recording is finished or has not begun yet.
Helpers
- isExpired(): boolean - Has the current stream expired
This model is used for retrieving a user's camera. If preferred you can provide custom instances of MediaResolution as arguments to our SDKs attach method.
This is a class containing information about a problem with the video or stream. Refer to the Result outcomes for more information about the different types of errors.
Contains information on why a recording or video has failed to process.
We provide the option to set callbacks that get called after certain actions are completed by the SDK.
Gets called when the recording stops and processing is started. It provides the stream status as a StreamStatus object as a parameter.
Gets called each time a new chunk of video is recorded. This will happen multiple times during a measurement. As parameters, it provides the stream's status as a StreamInfo object and a data Blob object. This could be handy when you want to do some custom actions with the recording or save the video yourself.
Our SDK throws 3 types of exceptions. All of our exceptions inherit from the base JavaScript Error class.
- Thrown when the quality check failed
- It contains information about why the quality check failed
- Thrown when a request to our API has failed or is invalid
- Includes a message about what failed
- Includes the HTTP status code
- Eg. Invalid Authentication (401)
- Thrown when there is an issue within the SDK
- Includes a message about what went wrong
- Includes ErrorType
- Eg. Your internet connection dropped while streaming