@credenza3/scanner-lib
v0.0.1
Published
Credenza Scanner Library
Downloads
153
Readme
Credenza3 Scanner Library
Installation
with npm
npm install @credenza3/scanner-lib
with yarn
yarn add @credenza3/scanner-lib
with pnpm
pnpm install @credenza3/scanner-lib
or include a script tag
<script src="https://unpkg.com/@credenza3/scanner-lib/dist/scanner.umd.js"></script>
Usage
import {Scanner} from '@credenza3/scanner-lib'
or
const Scanner = window.CredenzaScanner
Create an instance of Credenza scanner
const scanner = new Scanner({target: '.scanner-placeholder'}) // query selector to render the scanner into.
Static
Scanner.events
- list of events produced by scanner
Get a list of available video input devices
await scanner.listVideoInputDevices()
Scan
scanner.scan({
deviceId?: string,
isCloseButton?: boolean
maxScansPerSecond? number // 25
}) // (await scanner.listVideoInputDevices())[0].id by default
Cancel
scanner.close()
Events
On capture
// 'capture'
scanner.on(Scanner.events.CAPTURE, ({ rawString, message, scanType, aud }) => {
console.log('Scan completed', { rawString, message, aud })
})
On error
// 'error'
scanner.on(Scanner.events.ERROR, (err) => {
console.log('Scan error:', err)
})
On cancel
// 'cancel'
scanner.on(Scanner.events.CAPTURE, () => {
console.log('Scan canceled')
})