UNPKG

@digitalpersona/devices

Version:
62 lines (44 loc) 2.09 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [@digitalpersona/devices](./devices.md) &gt; [FingerprintReader](./devices.fingerprintreader.md) &gt; [on](./devices.fingerprintreader.on.md) ## FingerprintReader.on() method Adds an event handler for the event. This is a multicast subscription, i.e. many handlers can be registered at once. <b>Signature:</b> ```typescript on<E extends Event>(event: string, handler: Handler<E>): Handler<E>; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | | event | <code>string</code> | a name of the event to subscribe, e.g. "SampleAcquired" | | handler | <code>Handler&lt;E&gt;</code> | an event handler. | <b>Returns:</b> `Handler<E>` an event handler reference. Store the reference and pass it to the [FingerprintReader.off()](./devices.fingerprintreader.off.md) to unsubscribe from the event. ## Example ``` class FingerprintComponent { private reader: FingerprintReader; private onDeviceConnected = (event: DeviceConnected) => { ... }; private onDeviceDisconnected = (event: DeviceDisconnected) => { ... }; private onSamplesAcquired = (event: SampleAquired) => { ... }; ... public async $onInit() { this.reader = new FingerprintReader(); this.reader.on("DeviceConnected", onDeviceConnected); this.reader.on("DeviceDisconnected", onDeviceDisconnected); this.reader.on("SamplesAcquired", onSamplesAcquired); ... await this.fingerprintReader.startAcquisition(SampleFormat.Intermediate); } public async $onDestroy() { await this.fingerprintReader.stopAcquisition(); this.reader.off("DeviceConnected", onDeviceConnected); this.reader.off("DeviceDisconnected", onDeviceDisconnected); this.reader.off("SamplesAcquired", onSamplesAcquired); ... // alternatively, call this.reader.off() to unsubscribe from all events at once. delete this.reader; } } ```