Skip to main content

Methods

The <glamar-captureiq> element exposes async methods for imperative control. All return Promises—use try/catch or .catch() in your host app.

interface GlamarCaptureIQElement extends HTMLElement {
init(): Promise<void>;
start(): Promise<MediaStream | null>;
pause(): Promise<void>;
resume(): Promise<void>;
capture(): Promise<CaptureResult>;
cancel(): Promise<void>;
destroy(): Promise<void>;
}

init()

Validates license and configuration, then emits ready on success.

  • Call after the element is in the DOM (typically once).
  • Safe to call more than once; later calls reuse state when appropriate.

start()

Starts or resumes a session: may prompt for camera permission, opens the stream, and emits events such as sessionStart, permission, and cameraStarted.

  • Returns the active MediaStream or null if the camera cannot start.
  • Failures may reject the promise and emit licenseError, permission, or cameraError.

pause()

Stops the camera but keeps session context—use when hiding the widget temporarily without tearing down.

resume()

Restarts the camera after pause(), preserving session context.

capture()

Triggers a manual capture when the camera is running. Produces a CaptureResult with artifact (blob / dimensions / MIME) and metadata.

  • captureSuccess is not emitted here; it fires after the user confirms on the review step and final quality checks pass (average score ≥ 70). See Events.
  • Auto-capture uses the same result shape but is driven internally by quality and config.capture.

cancel()

Stops the camera, ends the session with reason cancelled, emits sessionEnd, and returns the runtime toward an idle state.

destroy()

Stops the camera, ends any session, cleans up internal state and UI. Call when removing the widget from the page (for example on route change).

CaptureResult shape

{
artifact: {
blob: Blob;
dataUrl?: string;
width: number;
height: number;
mimeType: string;
};
metadata: {
captureId: string;
sessionId: string;
preset: string;
deviceInfo: { deviceId?: string | null; label?: string | null };
qualitySnapshot: FrameQualityMetrics | null;
timestamps: { startedAt: number; completedAt: number };
};
}

Error handling

SituationBehavior
Licenseinit / start may reject; licenseError fires
Camera / permissionstart may reject; permission, cameraError
captureRejects if destroyed, camera not running, or canvas errors

Listen for DOM events alongside promise handling so users see clear messaging