Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Scanner

A low-level scanner interacting with the external Scandit Engine library. Used to set up scan / image settings and to process single image frames.

The loading of the external Scandit Engine library can take some time, the on method targeting the ready event can be used to set up a listener function to be called when the library is loaded and the isReady method can return the current status. The scanner will be ready to start scanning when the library is fully loaded.

By default the external Scandit Engine library is preloaded in order to reduce the initialization time as much as possible.

In the special case where a single Scanner instance is shared between multiple active BarcodePicker instances, the fairness in resource allocation for processing images between the different pickers is not guaranteed.

Hierarchy

  • Scanner

Index

Constructors

constructor

  • Create a Scanner instance.

    It is required to having configured the library via configure before this object can be created.

    Before processing an image the relative settings must also have been set.

    If the library has not been correctly configured yet a LibraryNotConfiguredError error is thrown.

    If a browser is incompatible a UnsupportedBrowserError error is thrown.

    Parameters

    • Default value parameters: { imageSettings: undefined | ImageSettings; scanSettings: ScanSettings } = {}
      • imageSettings: undefined | ImageSettings
        Default = undefined
        The configuration object to define the properties of an image to be scanned.
      • scanSettings: ScanSettings
        Default = new ScanSettings()
        The configuration object for scanning options.

    Returns Scanner

Events

Static ready

  • ready(): void
  • Fired when the external Scandit Engine library has been loaded and the scanner can thus start to scan barcodes.

    asmemberof

    Scanner

    Returns void

Methods

addListener

  • addListener(eventName: EventName, listener: ListenerFn): Scanner
  • See the on method.

    Parameters

    • eventName: EventName

      The name of the event to listen to.

    • listener: ListenerFn

      The listener function.

    Returns Scanner

    The updated Scanner object.

applyImageSettings

  • Apply a new set of image settings to the scanner (replacing old settings).

    Parameters

    • imageSettings: ImageSettings

      The image configuration object to be applied to the scanner.

    Returns Scanner

    The updated Scanner object.

applyScanSettings

  • Apply a new set of scan settings to the scanner (replacing old settings).

    Parameters

    • scanSettings: ScanSettings

      The scan configuration object to be applied to the scanner.

    Returns Scanner

    The updated Scanner object.

clearSession

  • Clear the scanner session.

    This removes all recognized barcodes from the scanner session and allows them to be scanned again in case a custom codeDuplicateFilter was set in the ScanSettings.

    Returns Scanner

    The updated Scanner object.

createParserForFormat

  • Create a new parser object.

    Parameters

    • dataFormat: DataFormat

      The format of the input data for the parser.

    Returns Parser

    The newly created parser.

destroy

  • destroy(): void
  • Stop/reset the internal WebWorker and destroy the scanner itself; ensuring complete cleanup.

    This method should be called after you don't plan to use the scanner anymore, before the object is automatically cleaned up by JavaScript. The scanner must not be used in any way after this call.

    Returns void

getImageSettings

  • Return the current image settings.

    Note that modifying this object won't directly apply these settings: the applyImageSettings method must be called with the updated object.

    Returns ImageSettings | undefined

    The current image settings.

getScanSettings

  • Return the current scan settings.

    Note that modifying this object won't directly apply these settings: the applyScanSettings method must be called with the updated object.

    Returns ScanSettings

    The current scan settings.

isBusyProcessing

  • isBusyProcessing(): boolean
  • Returns boolean

    Whether the scanner is currently busy processing an image.

isReady

  • isReady(): boolean
  • Returns boolean

    Whether the scanner has loaded the external Scandit Engine library and is ready to scan.

on

  • on(eventName: EventName, listener: ListenerFn): Scanner
  • on(eventName: "ready", listener: () => void): Scanner
  • Add the listener function to the listeners array for an event.

    No checks are made to see if the listener has already been added. Multiple calls passing the same listener will result in the listener being added, and called, multiple times.

    Parameters

    • eventName: EventName

      The name of the event to listen to.

    • listener: ListenerFn

      The listener function.

    Returns Scanner

    The updated Scanner object.

  • Add the listener function to the listeners array for the ready event, fired only once when the external Scandit Engine library has been loaded and the scanner can thus start to scan barcodes. If the external Scandit Engine library has already been loaded the listener is called immediately.

    No checks are made to see if the listener has already been added. Multiple calls passing the same listener will result in the listener being added, and called, multiple times.

    Parameters

    • eventName: "ready"

      The name of the event to listen to.

    • listener: () => void

      The listener function.

        • (): void
        • Returns void

    Returns Scanner

    The updated Scanner object.

processImage

  • processImage(imageData: Uint8Array | HTMLImageElement, highQualitySingleFrameMode?: boolean): Promise<ScanResult>
  • Process a given image using the previously set scanner and image settings, recognizing codes and retrieving the result as a list of barcodes (if any).

    Multiple requests done without waiting for previous results will be queued and handled in order.

    If highQualitySingleFrameMode is enabled the image will be processed with really accurate internal settings, resulting in much slower but more precise scanning results. This should be used only for single images not part of a continuous video stream.

    Passing image data as a Uint8Array is the fastest option, passing a HTMLImageElement will incur in additional operations.

    Data passed to this function is "detached"/"neutered" becoming unusable as it's being passed to the external Scandit Engine library. You can access the same data once it's returned in the ScanResult.imageData property.

    Depending on the current image settings, given imageData and scanning execution, any of the following errors could be the rejected result of the returned promise:

    • NoImageSettings
    • ImageSettingsDataMismatch
    • ScanditEngineError

    Parameters

    • imageData: Uint8Array | HTMLImageElement

      The image data given as byte array or image element, complying with the previously set image settings.

    • Default value highQualitySingleFrameMode: boolean = false

      Whether to process the image as a high quality single frame.

    Returns Promise<ScanResult>

    A promise resolving to the ScanResult object.

removeAllListeners

  • removeAllListeners(eventName: EventName): Scanner
  • Remove all listeners from the given event's listener array.

    Parameters

    • eventName: EventName

      The name of the event from which to remove all listeners.

    Returns Scanner

    The updated Scanner object.

removeListener

  • removeListener(eventName: string, listener: ListenerFn): Scanner
  • Remove the specified listener from the given event's listener array.

    Parameters

    • eventName: string

      The name of the event from which to remove the listener.

    • listener: ListenerFn

      The listener function to be removed.

    Returns Scanner

    The updated Scanner object.

Generated using TypeDoc