@digitalpersona/devices
Version:
DigitalPersona Security Devices support library
62 lines (44 loc) • 2.09 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[](./index.md) > [@digitalpersona/devices](./devices.md) > [FingerprintReader](./devices.fingerprintreader.md) > [on](./devices.fingerprintreader.on.md)
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>;
```
| Parameter | Type | Description |
| --- | --- | --- |
| event | <code>string</code> | a name of the event to subscribe, e.g. "SampleAcquired" |
| handler | <code>Handler<E></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.
```
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;
}
}
```