NeccessoryNeccessory
Web SDK

Callbacks & errors

Every method and callback of a measurement, what each callback receives, and every error code with a fix.

A measurement reports progress, live values, the result and errors through callbacks. Each on* method returns the measurement, so calls chain:

m.onStage(showStage)
  .onRealtime(showHeartRate)
  .onCoach(showHint)
  .onResult(saveResult)
  .onError(showError);
  • Each event holds one callback. Registering again replaces the previous one.
  • Register callbacks before or after start().
  • There is no unsubscribe or destroy. stop() ends the measurement and releases the camera.

Methods

MethodReturnsDescription
init({ keyId, secret })measurementOn-device only. Sets the key ID added to the result; secret is optional and needed only for submit(). Synchronous.
start()Promise<void>Opens the camera, loads the SDK and starts capturing. Resolves once capture has started. Never rejects — failures go to onError. Does nothing if the measurement is already running.
stop()Promise<void>Never rejects. On-device: ends the measurement, computes the result and fires onResult; a stop during startup cancels without a result. Cloud: ends early and resolves after the result arrives.
submit(result, { includeAdvanced })Promise<MeasurementResult>On-device only. Stores the result with POST /sdk/v1/measurements and returns the stored measurement. Requires secret.
onRealtime(cb)measurementLive heart rate and signal quality.
onStage(cb)measurementProgress stage.
onCoach(cb)measurementCloud only. Hint for the user.
onDeliveryFallback(cb)measurementCloud with delivery: 'auto'. The SDK switched to upload.
onResult(cb)measurementFinal result.
onError(cb)measurementError.

A cloud measurement ends by itself at the session's duration. An on-device measurement runs until you call stop().

onRealtime

m.onRealtime((update: {
  heartRate: number | null;
  quality: { level: 'good' | 'fair' | 'poor'; score: number | null };
}) => {});
ModeWhen it fires
CloudUp to twice per second, only while the signal is good enough. When the signal is poor, updates pause — show the onCoach hint instead.
On-deviceOn every update during capture. heartRate is null while the signal is poor.

Live values are provisional. Show the values from onResult as the outcome. quality.score is between 0 and 1 — see Signal quality.

onStage

onStage receives a stage name from start() until the result arrives.

StageModeMeaningSuggested text
requestingCamerabothWaiting for camera permission and the camera to open.Allow camera access
loadingModelsbothLoading the SDK runtime.Loading…
preparingWorkerson-devicePreparing the measurement.Preparing…
initializingSdkon-deviceStarting the measurement.Starting…
connectingcloudConnecting to Neccessory cloud. Skipped with delivery: 'batch'.Connecting…
readybothCapture has started.Hold still and look at the camera
uploadingcloudUploading the measurement data — with delivery: 'batch', or after a switch to upload with 'auto'.Uploading…
processingcloudCapture has ended; the result is being computed.Calculating results…
  • On-device: requestingCamera → loadingModels → preparingWorkers → initializingSdk → ready.
  • Cloud: requestingCamera → loadingModels → connecting → ready → processing. With 'batch', or after a switch to upload, the end is uploading → processing.

Treat an unknown stage as "still working".

onCoach

Cloud only. onCoach receives a hint for the user, or null when the problem is gone and the hint should be cleared. Hints are already debounced — show them as they arrive.

ReasonMeaningSuggested message (EN)Suggested message (RU)
faceTooSmallThe face is too far from the camera or out of view.Move closer to the cameraПридвиньтесь ближе к камере
tooDarkThe picture is too dark.Find more lightДобавьте света
tooBrightThe picture is overexposed.Move out of direct lightУйдите от прямого света
unstableThe user is moving too much.Hold stillНе двигайтесь
lowSignalThe signal is weak for another reason.Keep your face in view and hold stillДержите лицо в кадре и не двигайтесь

In on-device mode, prompt the user from quality.level in onRealtime.

onDeliveryFallback

Cloud with delivery: 'auto' only. Fires at most once per measurement, when the live connection is lost and the SDK finishes the measurement by upload. Live updates stop, onStage continues with uploading and processing, and onResult still fires.

FieldTypeDescription
reasonstringShort code for your logs, such as socket_closed, connect_timeout or visibility_hidden.
source'node' | 'local''node': Neccessory cloud ended the live connection. 'local': the SDK ended it — the connection was lost, timed out or the tab was hidden.

onResult

Fires once with the final measurement result.

CloudOn-device
StoredAlready storedNot stored — send it to your backend and store it with POST /sdk/v1/measurements
idMeasurement IDAbsent until stored
origin'cloud'Stored as 'on_device'
attestedtrue when the measurement is complete and its quality is usableStored as false

When quality.level is 'poor', every metric is null. Check quality.usable before you show values — see Signal quality.

onError

onError receives { code, message }. Map code to your own text; message is for logs. In cloud mode, errors can arrive after start() has resolved — during capture or during stop(). After an error the measurement is over: create a new one, in cloud mode with a new session.

Error codes

CodeModeCauseWhat to do
no_videobothNo video element. With the React hook, videoRef was not attached when start() was called.Pass videoEl, or render the <video> before calling start().
load_failedbothThe camera could not be opened — permission denied, camera in use or absent — or the SDK runtime failed to load.Ask the user to allow camera access and close other apps that use the camera. Check that your network and CSP allow neccessory.com and cdn.jsdelivr.net.
start_failedbothStartup failed or timed out — for example, in on-device mode the camera delivered no video within 8 seconds.Retry. If it repeats, check the camera.
core_unavailableon-deviceThe browser cannot run the SDK.Ask the user to update the browser or use a supported one, or use cloud mode.
sdk_*, e.g. sdk_inferenceon-deviceProcessing error during the measurement.Start a new measurement.
no_session_tokencloudNo session token.Pass the whole session object from your backend.
no_ws_urlcloudThe session has no wsUrl and delivery is not 'batch'.Pass the whole session object. With a test key, use delivery: 'batch'.
no_session_idcloudNo session ID for the upload.Pass the whole session object.
no_framescloudThe camera delivered no video within 8 seconds.Retry. Ask the user to close other apps that use the camera.
cloud_unreachablecloud, 'stream'The live connection could not open within 8 seconds. A firewall, proxy or CSP blocks WebSockets.Use delivery: 'auto' or 'batch'. Allow the session's wsUrl host in connect-src.
stream_interruptedcloud, 'stream'The connection dropped, the tab was hidden, or the result did not arrive in time.Start again with a new session. Use delivery: 'auto' to finish by upload instead.
insufficient_signalcloudNo usable data was captured — for example, the face was never in view.Guide the user and start again with a new session.
upload_failedcloud, 'batch' or 'auto'The upload or processing failed, or no result arrived within 180 seconds.Start again with a new session.
token_invalid, token_expiredcloudThe session token was rejected or is older than 5 minutes.Create the session right before start().
session_already_usedcloudThe session was already used for a measurement.Create a new session for every measurement.
frame_rate_exceeded, duration_exceeded, idle_timeout, protocol_error, internal_error, cloud_errorcloud, 'stream'Neccessory cloud ended the session. With 'auto', the SDK finishes most of these by upload instead.Start again with a new session.

submit() errors

submit() rejects with { code, message }. signAndSubmit() and signAndFetchMeasurement() reject the same way.

CodeCause
no_secretinit() was called without secret.
API error code, e.g. validation_error, unauthorized, rate_limitedThe API rejected the request — see Errors.
HTTP status, e.g. "502"The response was not an API response.