Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BarcodePicker

A barcode picker element used to get and show camera input and perform scanning operations.

The barcode picker will automatically fit and scale inside the given originElement.

Each barcode picker internally contains a Scanner object with its own WebWorker thread running a separate copy of the external Scandit Engine library. To optimize loading times and performance it's recommended to reuse the same picker and to already create the picker in advance (hidden) and just display it when needed whenever possible.

As the loading of the external Scandit Engine library can take some time the picker always starts inactive (but showing GUI and video) and then activates, if not paused, as soon as the library is ready to scan. The onReady method can be used to set up a listener function to be called when the library is loaded.

You are not allowed to hide the Scandit logo present in the corner of the GUI.

Hierarchy

  • BarcodePicker

Index

Methods

accessCamera

  • Access the currently set or default camera, requesting user permissions if needed. This method is meant to be used after the picker has been initialized with disabled camera access (cameraAccess=false). Calling this doesn't do anything if the camera has already been accessed.

    Depending on device features and user permissions for camera access, any of the following errors could be the rejected result of the returned promise:

    • PermissionDeniedError
    • NotAllowedError
    • NotFoundError
    • AbortError
    • NotReadableError
    • InternalError
    • NoCameraAvailableError

    Returns Promise<BarcodePicker>

    A promise resolving to the updated BarcodePicker object when the camera is accessed.

applyCameraSettings

  • Try to apply new settings to the currently used camera for video input, if no settings are passed the default ones are set.

    If camera access is enabled, the camera is updated and accessed with the new settings.

    Depending on device features and user permissions for camera access, any of the following errors could be the rejected result of the returned promise:

    • PermissionDeniedError
    • NotAllowedError
    • NotFoundError
    • AbortError
    • NotReadableError
    • InternalError
    • NoCameraAvailableError

    Parameters

    • Optional cameraSettings: CameraSettings

      The new camera options used when accessing the camera, by default HD resolution is used.

    Returns Promise<BarcodePicker>

    A promise resolving to the updated BarcodePicker object when the camera is updated (and accessed, if camera access is currently enabled).

applyScanSettings

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

    Parameters

    • scanSettings: ScanSettings

      The scan configuration object to be applied to the scanner.

    Returns BarcodePicker

    The updated BarcodePicker 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 scanning and displaying video output, remove HTML elements added to the page, destroy the internal Scanner and destroy the barcode picker itself; ensuring complete cleanup.

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

    Returns void

getActiveCamera

  • getActiveCamera(): Camera | undefined
  • Returns Camera | undefined

    The currently active camera.

isMirrorImageEnabled

  • isMirrorImageEnabled(): boolean
  • Returns boolean

    Whether the camera video is mirrored along the vertical axis.

isPlaySoundOnScanEnabled

  • isPlaySoundOnScanEnabled(): boolean
  • Returns boolean

    Whether a sound should be played on barcode recognition (iOS requires user input).

isReady

  • isReady(): boolean
  • Returns boolean

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

isScanningPaused

  • isScanningPaused(): boolean
  • Returns boolean

    Whether the scanning is currently paused.

isVibrateOnScanEnabled

  • isVibrateOnScanEnabled(): boolean
  • Returns boolean

    Whether the device should vibrate on barcode recognition (only Chrome & Firefox, requires user input).

isVisible

  • isVisible(): boolean
  • Returns boolean

    Whether the picker is in a visible state or not.

onProcessFrame

  • onProcessFrame(listener: function, once?: undefined | true | false): BarcodePicker
  • Add the listener function to the listeners array for the "processFrame" event, fired when a new frame is processed. This event is fired on every frame, independently from the number of recognized barcodes (can be none). The returned barcodes are affected by the ScanSettings.setCodeDuplicateFilter option.

    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

    • listener: function

      The listener function, which will be invoked with a ScanResult object.

    • Optional once: undefined | true | false

      Whether the listener should just be triggered only once and then discarded.

    Returns BarcodePicker

    The updated BarcodePicker object.

onReady

  • Add the listener function to the listeners array for the "ready" event, fired when the external Scandit Engine library has been loaded and the barcode picker can thus start to scan barcodes.

    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

    • listener: function

      The listener function.

        • (): void
        • Returns void

    Returns BarcodePicker

    The updated BarcodePicker object.

onScan

  • onScan(listener: function, once?: undefined | true | false): BarcodePicker
  • Add the listener function to the listeners array for the "scan" event, fired when new barcodes are recognized in the image frame. The returned barcodes are affected by the ScanSettings.setCodeDuplicateFilter option.

    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

    • listener: function

      The listener function, which will be invoked with a ScanResult object.

    • Optional once: undefined | true | false

      Whether the listener should just be triggered only once and then discarded.

    Returns BarcodePicker

    The updated BarcodePicker object.

onScanError

  • onScanError(listener: function, once?: undefined | true | false): BarcodePicker
  • Add the listener function to the listeners array for the "scan error" event, fired when an error occurs during scanning initialization and execution. The barcode picker will be automatically paused when this happens.

    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

    • listener: function

      The listener function, which will be invoked with an ScanditEngineError object.

        • (error: Error): void
        • Parameters

          • error: Error

          Returns void

    • Optional once: undefined | true | false

      Whether the listener should just be triggered only once and then discarded.

    Returns BarcodePicker

    The updated BarcodePicker object.

pauseScanning

  • Pause the recognition of codes in the input image.

    By default video from the camera is still shown, if the pauseCamera option is enabled the camera stream is paused (camera access is fully interrupted) and will be resumed when calling resumeScanning, possibly requesting user permissions if needed.

    Parameters

    • Default value pauseCamera: boolean = false

      Whether to also pause the camera stream.

    Returns BarcodePicker

    The updated BarcodePicker object.

reassignOriginElement

  • reassignOriginElement(originElement: HTMLElement): BarcodePicker
  • Reassign the barcode picker to a different HTML element.

    All the barcode picker elements inside the current origin element will be moved to the new given one.

    Parameters

    • originElement: HTMLElement

      The HTMLElement into which all the necessary elements for the picker will be moved.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeProcessFrameListener

  • Removes the specified listener from the "processFrame" event listener array. This will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times then this method must be called multiple times to remove each instance.

    Parameters

    • listener: function

      The listener function to be removed.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeProcessFrameListeners

  • Removes all listeners from the "processFrame" event listener array.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeScanErrorListener

  • Removes the specified listener from the "scan error" event listener array. This will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times then this method must be called multiple times to remove each instance.

    Parameters

    • listener: function

      The listener function to be removed.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeScanErrorListeners

  • Removes all listeners from the "scan error" event listener array.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeScanListener

  • Removes the specified listener from the "scan" event listener array. This will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times then this method must be called multiple times to remove each instance.

    Parameters

    • listener: function

      The listener function to be removed.

    Returns BarcodePicker

    The updated BarcodePicker object.

removeScanListeners

  • Removes all listeners from the "scan" event listener array.

    Returns BarcodePicker

    The updated BarcodePicker object.

resumeScanning

  • Resume the recognition of codes in the input image.

    If the camera stream was stopped when calling pauseScanning, the camera stream is also resumed and user permissions are requested if needed to resume video input.

    Returns Promise<BarcodePicker>

    The updated BarcodePicker object.

setActiveCamera

  • Select a camera to be used for video input.

    If camera access is enabled, the camera is enabled and accessed.

    Depending on device features and user permissions for camera access, any of the following errors could be the rejected result of the returned promise:

    • PermissionDeniedError
    • NotAllowedError
    • NotFoundError
    • AbortError
    • NotReadableError
    • InternalError
    • NoCameraAvailableError

    Parameters

    • camera: Camera

      The new camera to be used.

    • Optional cameraSettings: CameraSettings

      The camera options used when accessing the camera, by default HD resolution is used.

    Returns Promise<BarcodePicker>

    A promise resolving to the updated BarcodePicker object when the camera is set (and accessed, if camera access is currently enabled).

setGuiStyle

  • Set the GUI style for the picker.

    Parameters

    • guiStyle: GuiStyle

      The new GUI style to be applied.

    Returns BarcodePicker

    The updated BarcodePicker object.

setMirrorImageEnabled

  • Enable or disable camera video mirroring along the vertical axis.

    Parameters

    • enabled: boolean

      Whether the camera video is mirrored along the vertical axis.

    Returns BarcodePicker

    The updated BarcodePicker object.

setPlaySoundOnScanEnabled

  • Enable or disable playing a sound on barcode recognition (iOS requires user input).

    Parameters

    • enabled: boolean

      Whether a sound should be played on barcode recognition.

    Returns BarcodePicker

    The updated BarcodePicker object.

setTargetScanningFPS

  • Set the target frames per second to be processed by the scanning engine.

    The final speed is limited by the camera framerate (usually 30 FPS) and the frame processing time of the device. By setting this to lower numbers devices can save power by performing less work during scanning operations, depending on device speed (faster devices can "sleep" for longer periods).

    Parameters

    • targetScanningFPS: number

      The target frames per second to be processed. Must be a number bigger than 0, by default set to 30.

    Returns BarcodePicker

    The updated BarcodePicker object.

setTorchEnabled

  • Enable or disable the torch/flashlight of the device (when available, only Chrome). Changing active camera or camera settings will cause the torch to become disabled.

    A button on the BarcodePicker GUI to let the user toggle this functionality can also be set on creation via the enableTorchToggle option (enabled by default, when available).

    Parameters

    • enabled: boolean

      Whether the torch should be enabled or disabled.

    Returns BarcodePicker

    The updated BarcodePicker object.

setVibrateOnScanEnabled

  • Enable or disable vibrating the device on barcode recognition (only Chrome & Firefox, requires user input).

    Parameters

    • enabled: boolean

      Whether the device should vibrate on barcode recognition.

    Returns BarcodePicker

    The updated BarcodePicker object.

setVideoFit

  • Set the fit type for the video element of the picker.

    If the "cover" type is selected the maximum available search area for barcode detection is (continuously) adjusted automatically according to the visible area of the picker.

    Parameters

    • objectFit: ObjectFit

      The new fit type to be applied.

    Returns BarcodePicker

    The updated BarcodePicker object.

setVisible

  • Enable or disable picker visibility.

    Parameters

    • visible: boolean

      Whether the picker is in a visible state or not.

    Returns BarcodePicker

    The updated BarcodePicker object.

setZoom

  • Set the zoom level of the device (when available, only Chrome). Changing active camera or camera settings will cause the zoom to be reset.

    Parameters

    • zoomPercentage: number

      The percentage of the max zoom (between 0 and 1).

    Returns BarcodePicker

    The updated BarcodePicker object.

Static create

  • create(originElement: HTMLElement, __namedParameters?: object): Promise<BarcodePicker>
  • Creates a BarcodePicker instance, creating the needed HTML in the given origin element. If the accessCamera option is enabled (active by default) the available cameras are accessed and a camera access permission is requested to the user if needed. This object expects that at least a camera is available. The active camera is accessed and kept active during the lifetime of the picker (also when hidden or scanning is paused), and is only released when destroy is called.

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

    By default an alert is shown if an internal error during scanning is encountered which prevents the scanning procedure from continuing. As this uses the built-in onScanError event functionality, if unwanted it can be disabled by calling removeScanErrorListeners on the BarcodePicker instance (right after creation).

    Depending on parameters, device features and user permissions for camera access, any of the following errors could be the rejected result of the returned promise:

    • LibraryNotConfiguredError
    • NoOriginElementError
    • UnsupportedBrowserError
    • PermissionDeniedError
    • NotAllowedError
    • NotFoundError
    • AbortError
    • NotReadableError
    • InternalError
    • NoCameraAvailableError

    Parameters

    • originElement: HTMLElement

      The HTMLElement inside which all the necessary elements for the picker will be added.

    • Default value __namedParameters: object = {}
      • accessCamera: boolean

        Default = true
        Whether to immediately access the camera (and requesting user permissions if needed) on picker creation.

      • camera: undefined | Camera

        Default = undefined
        The camera to be used for video input, if not specified the back or only camera will be used.

      • cameraSettings: undefined | CameraSettings

        Default = undefined
        The camera options used when accessing the camera, by default HD resolution is used.

      • enableCameraSwitcher: boolean

        Default = true
        Whether to show a GUI button to switch between different cameras (when available).

      • enablePinchToZoom: boolean

        Default = true
        Whether to control the zoom of the camera when doing a pinching gesture on the video (when available, only Chrome).

      • enableTapToFocus: boolean

        Default = true
        Whether to trigger a manual focus of the camera when clicking/tapping on the video (when available, only Chrome).

      • enableTorchToggle: boolean

        Default = true
        Whether to show a GUI button to toggle device torch on/off (when available, only Chrome).

      • guiStyle: GuiStyle

        Default = GuiStyle.LASER
        The GUI style for the picker.

      • playSoundOnScan: boolean

        Default = false
        Whether a sound is played on barcode scanned (iOS requires user input).

      • scanSettings: ScanSettings

        Default = new ScanSettings()
        The configuration object for scanning options (All symbologies disabled by default).

      • scanningPaused: boolean

        Default = false
        Whether the picker starts in a paused scanning state.

      • targetScanningFPS: number

        Default = 30
        The target frames per second to be processed, the final speed is limited by the camera framerate (usually 30 FPS) and the frame processing time of the device. By setting this to lower numbers devices can save power by performing less work during scanning operations, depending on device speed (faster devices can "sleep" for longer periods). Must be a number bigger than 0.

      • vibrateOnScan: boolean

        Default = false
        Whether the device vibrates on barcode scanned (only Chrome & Firefox, requires user input).

      • videoFit: ObjectFit

        Default = ObjectFit.CONTAIN
        The fit type for the video element of the picker.

      • visible: boolean

        Default = true
        Whether the picker starts in a visible state.

    Returns Promise<BarcodePicker>

    A promise resolving to the created ready BarcodePicker object.

Generated using TypeDoc