Skip to main content

Scanner Driver

The SDK communicates with fingerprint scanners through a local WebSocket driver. The DriverSocket class manages the connection, automatic reconnection, and event dispatching.

Architecture

The local driver runs as a local service on the user's machine and exposes a WebSocket endpoint at ws://127.0.0.1:2794/hk-reader. The SDK connects to this endpoint automatically when the client is created.

Connection lifecycle

On construction, DriverSocket attempts to connect. If the connection drops, it reconnects with exponential backoff. Calling destroy() terminates the connection permanently.

Exponential backoff

When the connection drops, the driver reconnects with exponential backoff:

AttemptDelay
12s
24s
38s
416s
5+32s (capped at 60s)

Events

The DriverSocket emits the following events via its internal EventEmitter:

EventPayloadDescription
connectedWebSocket connection established
disconnectedWebSocket connection lost
sensorConnectedDeviceDescription.dataScanner device detected and described
sensorDisconnecteddeviceId?: numberScanner device lost
fingerprintPreviewbase64Image: stringPreview frame from scanner (BMP)
fingerprintResultbase64Image: string, score?: number, deviceId?: numberFinal result with quality score