API Documentation

This page contains all LIQA API methods

Preparation stage

Create LIQA instance class

const liqa = new Liqa();

checkCameraAvailable: Promise<void>

The checkCameraAvailable method allows to validate if camera and browser are correctly setup and suitable for launching the LIQA.

liqa.checkCameraAvailable()
    .then(_ => {
        //this.liqa.load....
        //this.liqa.init....
      })
      .catch(e => {
        //Show pop up about camera issue
        //Leave only native camera/file upload. 
        //Example - <input type="file" capture="camera" accept="image/*">
});

This method requires access to the device camera and will launch (and then stop) the camera to check that all parameters are correctly setup and all API methods are available in current browser. We recommend calling this method for every start before liqa.init.

We highly recommend to setup a .catch operation on liqa.checkCameraAvailable method with some resulting warning for the end-user. The detected issues with LIQA start might be critical and it is better to recommend your user to try one of stable browsers (e.g. Chrome on Android, Safari on iOS) / check their permissions on camera access for different apps, etc.

Unfortunately, LIQA can not detect the exact reason why the system fails to provide the full necessary access to camera and its methods.

load: Promise<void>

The load method fetches model weights files and optionally compiles AI models for the device hardware. You may turn off a model compilation during the load method, and in this case, the compilation will take time during the first frame of a video stream.

  • The duration of fetching model weights depends on the Internet connection speed. For example, it requires only 0.3s at 30Mbps;

  • The model compilation is computationally intensive. It requires different times depending on device hardware: from ~1s on modern devices to more than 10s on laptops or old devices.

liqa.load({
    staticPath, 
    compileModels,
    useLocalModel
});

Parameter

Default value

Description

staticPath: string

N/A

Path to scriptsdirectory

compileModels?: boolean

True

Flag to turn on / off the compilation of models Learn more about it here

useLocalModels?: boolean

True

If set true, LIQA fetches some models

from local scripts/ directory.

If set false, LIQA fetches some models

from external servers (may require more time,

depending on the connection speed)

init: void

Create config object with inner settings (see Config description):

/* abstract code */
const config = json_read_from_file('./liqa/config.json')

The init method creates a canvas for video rendering in provided DOM container.

liqa.init({
    container, 
    config, 
    width, 
    height
});

Parameter

Default value

Description

container: HTMLDivElement

N/A

div container for creating a canvas for drawing stream and other overlays

config?: unknown

LIQA inner settings

width: number

N/A

Width size of div container

height: number

N/A

Height size of div container

Image collection session

play: Promise<void>

The play method starts live capture via the camera and the calculation of AI models.

liqa.play();

You can call methods

liqa.load();
liqa.init();
liqa.play();

one by one, without waiting (promise/then or await construction) for their completion. In this case, they will be executed sequentially.

It allows to put the load method in another component of your application.

captureSelfie: Promise<void>

The captureSelfie method sends a request to capture selfie.

liqa.captureSelfie();

Note: aftercaptureSelfie method, LIQA will stop the stream. You can continue stream by callingliqa.play() after receiving a selfie image.

Note: This method will be called automatically, if autoSelfieCapture parameter value in config.json was set to true

Note: Promise rejection if the play method has not been finished by now.

stop: void

The stop method stops the camera's live capture and the calculation of AI models.

liqa.stop();

You can call the stop method urgently without waiting for the play method to complete. The methods will be executed sequentially.

unmount: void

The unmount method destroys the canvas and all of the elements generated during the LIQA work inside of the DOM container provided in the init method.

liqa.unmount();

After unmounting of LIQA, play, stop, captureSelfie methods are not available. To start LIQA again call the init method.

exit: void

The exit method removes web-workers, clears variables, and frees memory buffers allocated for LIQA.

liqa.exit();

After exiting, all methods are not available. To start LIQA again call the load method.

Last updated