Web SDK for barKoder - API Reference
The initialize method must be called first. After it completes, it returns an object with the following members:
Api Reference #
startScanner(resultCallback?: function): number. #
Starts the scanner. This will access and start the camera, creates a preview to show the stream and adds it to a container element, and decode frames from it.
startScanner: (resultCallback?: (result: Result) => void) => number
stopScanner(). #
Stops a previously started scanning session by startScanner.
stopScanner: () => void
scanImage(imageUri: string, resultCallback?: function). #
Scans a single image.
scanImage: (imageUri: string, resultCallback?: (result: Result) => void) => void | Promise<Result>
setPauseDecoding(pause: boolean). #
Pause the decoding.
setPauseDecoding: (pause: boolean) => void
setRegionOfInterest(left: number, top: number, width: number, height: number). #
Set the desired region of interested. The decoder will only look at this area for barcodes.
setRegionOfInterest: (left: number, top: number, width: number, height: number) => void
Name | Type | Description |
---|---|---|
left | number | Percentage of the starting point on the x-axis of the preview. |
top | number | Percentage of the starting point on the y-axis of the preview. |
width | number | Percentage of the width of the preview. |
height | number | Percentage of the height of the preview. |
setCameraResolution(cameraResolution: number). #
Set the desired camera resolution.
Note that if device is not capable of providing the exact resolution, the closest available one will be used.
setCameraResolution: (cameraResolution: CameraResolution) => number
getCameras #
Get all available cameras from the device.
Note that this method may prompt the user for camera access permissions, if they are not already granted.
getCameras: () => Promise<Cameras>
setCameraId(cameraId: string). #
Set the desired camera to use.The camera id previously obtained from getCameras.
setCameraId: (cameraId: string) => void
setFlashEnabled(flashEnabled: boolean): number. #
Enable or disable flash button on camera preview. Default is enabled.
setFlashEnabled: (flashEnabled: boolean) => number
setZoomEnabled(zoomEnabled: boolean): number. #
Enable or disable zoom button on camera preview. Default is enabled.
setZoomEnabled: (zoomEnabled: boolean) => number
setCloseEnabled(closeEnabled: boolean): number. #
Enable or disable close button on camera preview. Default is enabled.
setCloseEnabled: (closeEnabled: boolean) => number
setCameraPickerEnabled(cameraPickerEnabled: boolean): number. #
Enable or disable cameraPicker button on camera preview. Default is enabled.
setCameraPickerEnabled: (cameraPickerEnabled: boolean) => number
changeFlashState(). #
Change i.e. toggle the current flash state.
Should be used only during an active scanning session. Outside of one, there is no effect.
changeFlashState: () => void
changeZoomState(). #
Change i.e. cycle through the current zoom state.
Should be used only during an active scanning session. Outside of one, there is no effect.
changeZoomState: () => void
setContinuous(continuous: boolean): number. #
Enable or disable continuous scanning. Default is disabled.
setContinuous: (continuous: boolean) => number
setScannerTimeout(timeout: number). #
Set the desired timeout in seconds.
This setting affects how long the scanner will run i.e. the camera preview will be open, the camera stream will run, and the decoder will actively scan for barcodes. Note that in mobile devices scanning for a longer period of time can result in higher heat output and battery drain.
The timeout to apply. Default value is 60. Accepts values in the range of 10-3600. Accepts 0 to disable the timeout.
setScannerTimeout: (timeout: number) => number
setDpsLimit #
Set the desired decodes per second limit.
This setting affects how often the scanner will try to decode a frame. Higher values increase the likelihood of barcodes being detected faster, but is also more demanding on the device.
The DPS limit to apply. Default value is 28. Accepts values in the range of 1-30.
setDpsLimit: ((dpsLimit) => number)
applyTemplate(templateFile: string, templateMode: string). #
Apply a set of pre-defined settings from a file.The template file in json format, containing settings for different template modes.
applyTemplate: (templateFile: string, templateMode: string) => void
setLengthRange(decoder: number, minimumLength: number, maximumLength: number). #
Set the minimum and maximum length to be detected.
setLengthRange: (decoder: Decoders, minimumLength: number, maximumLength: number) => number
setCode11ChecksumType(code11ChecksumType: number): number. #
Set checksum type for Code 11.
setCode11ChecksumType: (code11ChecksumType: number) => number
setCode39ChecksumType(code39ChecksumType: number): number. #
Set checksum type for Code 39.
setCode39hecksumType: (code39ChecksumType: number) => number
setMsiChecksumType(msiChecksumType: number): number. #
Set checksum type for MSI.
setMsiChecksumType: (msiChecksumType: number) => number
setDatamatrixDpmModeEnabled(dpmModeEnabled: boolean): number. #
Enable Datamatrix dpm mode.
setDatamatrixDpmModeEnabled: (dpmModeEnabled: boolean) => number
setEncodingCharacterSet(encodingCharacterSet: number). #
Set the character set to be used for encoding the results.
setEncodingCharacterSet: (encodingCharacterSet: number) => void
setDecodingSpeed #
Set the pace and effort at which the scanner will try to decode barcodes.The decoding speed to apply. Default is Normal.
setDecodingSpeed: ((decodingSpeed) => number)
setEnabledDecoders(...args: number). #
Set the decoders to enable.
Note that this method uses a rest parameter i.e. accepts an indefinite number of arguments.
setEnabledDecoders: (...decoders: Decoders[]) => void
setFormatting #
Set the type of formatting to apply to results.Default is Disabled.
setFormatting: (formatting: Formatting) => number
setMulticodeCachingEnabled(multicodeCachingEnabled: number). #
Enable or disable multicode caching. Default is Disabled.
setMulticodeCachingEnabled: (multicodeCachingEnabled: number) => number
setMulticodeCachingDuration(multicodeCachingDuration: number). #
Set the duration for multicode caching.The duration in ms.
setMulticodeCachingDuration: (multicodeCachingDuration: number) => number
setDuplicatesDelayMs(duplicatesDelayMs: number). #
Set the delay for duplicate results.
setDuplicatesDelayMs: (duplicatesDelayMs: number) => number
setEnableVINRestrictions(enableVINRestrictions: number). #
Enable or disable VIN restrictions. Default is Disabled.
setEnableVINRestrictions: (enableVINRestrictions: number) => number
getVersion(): { barkoderWebVersion: string, barkoderVersion: string, barkoderFullVersion: string }. #
Get the BarkoderSDK version details.
getVersion: () => { barkoderWebVersion: string ; barkoderVersion: string ; barkoderFullVersion: string }
getRegionOfInterest(): { x:number, y:number, width: number, height: number }. #
Note that these values may be different during active scanning than the ones set by setRegionOfInterest.
Get the currently used region of interest.
getRegionOfInterest: () => { x: number ; y: number ; width: number ; height: number }
setUpcEanDeblur(deblur: number). #
setUpcEanDeblur: (deblur: number) => number
Description: Enable or disable deblur. Default is Disabled.
setEnableMisshaped1D(enableMisshaped1D: number). #
Enable detection of misshaped 1D barcodes.
setEnableMisshaped1D: (enableMisshaped1D: number) => number
getDecodingSpeed(): number. getFormatting(): number. getDuplicatesDelayMs(): number. #
Get the decoding speed.
getDecodingSpeed: () => DecodingSpeed
getUpcEanDeblur(): number. #
Get the UPC/EAN deblur state.
getUpcEanDeblur: () => number
getEnableVINRestrictions(): number #
Get the VIN restrictions state.
getEnableVINRestrictions: () => number
getEnableMisshaped1D(): number. #
Get the misshaped 1D state.
getEnableMisshaped1D: () => number
getLocationLineColor(): string. #
getLocationLineColor: () => string
Retrieves the color code representing the line color used to indicate the location of detected barcodes.
getLocationLineWidth(): number. #
getLocationLineWidth: () => number
Retrieves the current width setting for the lines indicating the location of detected barcodes on the camera feed.
getRoiLineColor(): string. #
getRoiLineColor: () => string
Retrieves the color code representing the line color of the Region of Interest (ROI) on the camera preview.
getRoiLineWidth(): number. #
getRoiLineWidth: () => number
Retrieves the current width setting for the lines outlining the Region of Interest (ROI) on the camera preview.
isRegionOfInterestVisible(): boolean. #
isRegionOfInterestVisible: () => boolean
Checks if the region of interest (ROI) is visible.
isImageResultEnabled(): boolean. #
isImageResultEnabled: () => boolean
Checks if the inclusion of the captured frame in the result is enabled.
isLocationInPreviewEnabled(): boolean #
isLocationInPreviewEnabled: () => boolean
Check if the location in the preview is enabled.
setRoiLineColor #
setRoiLineColor: ((color) => void)
Sets the color of the lines outlining the Region of Interest (ROI) for barcode scanning on the camera feed.
setRoiLineWidth #
setRoiLineWidth:((width) => void)
Sets the width of the lines outlining the Region of Interest (ROI) for barcode scanning on the camera feed.
setImageResultEnabled #
setImageResultEnabled: ((enabled) => void)
Enables or disables the capturing and processing of image data when a barcode is successfully detected.
setLocationInPreviewEnabled #
setLocationInPreviewEnabled: ((enabled) => void)
Enables or disables the display of barcode location information on the camera preview.
setRegionOfInterestVisible #
setRegionOfInterestVisible: ((visible) => void)
Sets the visibility of the Region of Interest (ROI) on the camera preview
setLocationLineWidth #
setLocationLineWidth: ((width) => void)
Sets the width of the lines indicating the location of detected barcodes on the camera feed.
setLocationLineColor #
setLocationLineColor: ((color) => void)
Sets the color of the lines used to indicate the location of detected barcodes on the camera feed.getDecodingSpeed
getDecodingSpeed #
getDecodingSpeed: (() => DecodingSpeed)
Get the decoding speed.
setMaximumResultsCount #
setMaximumResultsCount: ((maximumResultsCount) => number)
Set the maximum amount of results to be detected from a single frame or image.
getMaximumResultsCount #
getMaximumResultsCount: (() => number)
Get the maximum results count.
getDuplicatesDelayMs #
getDuplicatesDelayMs: (() => number)
Get the duplicates delay.
configureBarkoder #
configureBarkoder: ((barkoderConfig) => boolean)
Configure the barkoder scanner with a defined model of settings.
Example:
let cfg = new Barkoder.configTypes.BarkoderConfig({
closeSessionOnResultEnabled: true,
barkoderResolution: Barkoder.constants.CameraResolution.HD,
decoder: new Barkoder.configTypes.DekoderConfig({
qr: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
ean8: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
pdf417: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
general: new Barkoder.configTypes.GeneralSettings({
decodingSpeed: Barkoder.constants.DecodingSpeed.Normal
})
})
});
Barkoder.configureBarkoder(cfg);
Type declaration:
(barkoderConfig): boolean
Configure the barkoder scanner with a defined model of settings.
Example:
let cfg = new Barkoder.configTypes.BarkoderConfig({
closeSessionOnResultEnabled: true,
barkoderResolution: Barkoder.constants.CameraResolution.HD,
decoder: new Barkoder.configTypes.DekoderConfig({
qr: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
ean8: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
pdf417: new Barkoder.configTypes.BarcodeConfig({enabled: true}),
general: new Barkoder.configTypes.GeneralSettings({
decodingSpeed: Barkoder.constants.DecodingSpeed.Normal
})
})
});
Barkoder.configureBarkoder(cfg);
scanFromLocalFileSystem #
scanFromLocalFileSystem: ((input, resultCallback?) => void)
Scans a file from an input element of type file.
Example usage:
<form><input type="file" value="Scan file"
onchange="Barkoder.scanFromLocalFileSystem(this)"/></form>
Type declaration
(input, resultCallback?): void
Scans a file from an input element of type file.
Example usage:
<form><input type="file" value="Scan file"
onchange="Barkoder.scanFromLocalFileSystem(this)"/></form>
setBeepOnSuccessEnabled #
setBeepOnSuccessEnabled: (beepEnabled: boolean) => number;
Enables or disables the audible beep sound upon successfully decoding a barcode.
getCameraResolution #
getCameraResolution: () => number;
Retrieves the resolution for barcode scanning.
getEncodingCharacterSet #
getEncodingCharacterSet: () => number;
Retrieves the character set used for encoding barcode data.
getFormatting #
getFormatting: () => number
Retrieves the formatting type used for presenting decoded barcode data.
getMsiChecksumType #
getMsiChecksumType: () => number;
Retrieves the MSI checksum type.
getCode11ChecksumType #
getCode11ChecksumType: () => number;
Retrieves the Code11 checksum type
getCode39ChecksumType #
getCode39ChecksumType: () => number;
Retrieves the checksum type for Code 39 barcodes
getContinuous #
getContinuous: () => boolean;
Get the continuous scanning state.
isBeepOnSuccessEnabled #
isBeepOnSuccessEnabled: () => boolean;
Retrieves the value indicating whether a beep sound is played on successful barcode scanning.
isBarcodeTypeEnabled #
isBarcodeTypeEnabled: (decoder: number) => boolean | -1
Checks if a specific barcode type is enabled
setBarcodeTypeEnabled #
setBarcodeTypeEnabled: (decoder: number, enable: boolean) => number;
Sets a specific barcode type to be enabled
getBarcodeTypeLengthRange #
getBarcodeTypeLengthRange: (decoder: number) => [number, number] | -1;
Retrieves the length range of a specific barcode type
getMulticodeCachingEnabled #
getMulticodeCachingEnabled: () => number;
Retrieves whether multi-code caching is enabled
getMulticodeCachingDuration #
getMulticodeCachingDuration: () => number;
Retrieves the caching duration (in milliseconds) for multi-code results
getActiveCamera #
getActiveCamera: () => string | null;
Get a used camera. It should be used only during an active scanning session. Outside of one, it returns null.
setQRDpmModeEnabled #
setQRDpmModeEnabled: (dpmModeEnabled: boolean) => number;
Sets whether the Direct Part Marking (DPM) mode for QR barcodes is enabled.
setQRMicroDpmModeEnabled #
setQRMicroDpmModeEnabled: (dpmModeEnabled: boolean) => number;
Sets whether the Direct Part Marking (DPM) mode for QRMicro barcodes is enabled.
getDatamatrixDpmModeEnabled #
setDatamatrixDpmModeEnabled: (dpmModeEnabled: boolean) => number;
Retrieves whether the Direct Part Marking (DPM) mode for Datamatrix barcodes is enabled.
setBarcodeThumbnailOnResultEnabled #
setBarcodeThumbnailOnResultEnabled: (enabled: boolean) => void;
Sets whether to enable barcode thumbnail on result.
isBarcodeThumbnailOnResultEnabled #
isBarcodeThumbnailOnResultEnabled: () => boolean;
Checks if the barcode thumbnail on the result is enabled.
getMaxZoomFactor #
getMaxZoomFactor: () => number;
Retrieves the maximum available zoom factor for the device's camera.
isFlashAvailable #
isFlashAvailable: () => boolean;
Checks whether the device has a built-in flash (torch) that can be used for illumination during barcode scanning.
setEnableComposite #
setEnableComposite: (enableComposite: EnableComposite) => number;
Sets whether GS1 Composite Barcodes is enabled.
getEnableComposite #
getEnableComposite: () => number;
Retrieves whether GS1 Composite Barcodes is enabled.
getEnabledDecoders #
getEnabledDecoders: () => number[];
Retrieves an array of enabled decoders.
setRoiOverlayBackgroundColor #
setRoiOverlayBackgroundColor: (color: string) => void;
Sets the background color of the overlay within the Region of Interest (ROI) for barcode scanning on the camera feed.
setLocationInImageResultEnabled #
setLocationInImageResultEnabled: (enabled: boolean) => void;
Enables or disables the inclusion of barcode location information within the image data result.
getRoiOverlayBackgroundColor #
getRoiOverlayBackgroundColor: () => string;
Retrieves the color code representing the background color of the overlay within the Region of Interest (ROI) on the camera preview.
isLocationInImageResultEnabled #
isLocationInImageResultEnabled: () => boolean;
Retrieves whether the inclusion of barcode location information within the image data result is enabled.
Barkoder.constants #
DecodingSpeed #
This setting determines the pace at which the system processes and decodes barcode information, affecting the speed of barcode scanning.
* Fast: 0 - Scanner will spend less time on decoding. While this if faster, it may not detect more demanding barcodes.
* Normal: 1 - Default. Scanner holds a balance between how long decoding takes, and the success rate of detecting barcodes.
* Slow: 2 - Scanner will spend more time on decoding. While this is slower, it may detect very demanding barcodes that cannot be read otherwise.
* Rigorous: 3 - Scanner will spend the most time on decoding. This is quite demanding on the device hardware - it may find more results, but will also take longer to do so. It is only recommended when scanning from an image.
Example:
Barkoder.setDecodingSpeed(Barkoder.constants.DecodingSpeed.Slow);
Decoders #
Supported decoders (barcode types).
Barkoder.constants.Decoders.Aztec //: 0,
Barkoder.constants.Decoders.AztecCompact //: 1,
Barkoder.constants.Decoders.QR //: 2,
Barkoder.constants.Decoders.QRMicro //: 3,
Barkoder.constants.Decoders.Code128 //: 4,
Barkoder.constants.Decoders.Code93 //: 5,
Barkoder.constants.Decoders.Code39 //: 6,
Barkoder.constants.Decoders.Codabar //: 7,
Barkoder.constants.Decoders.Code11 //: 8,
Barkoder.constants.Decoders.Msi //: 9,
Barkoder.constants.Decoders.UpcA //: 10,
Barkoder.constants.Decoders.UpcE //: 11,
Barkoder.constants.Decoders.UpcE1 //: 12,
Barkoder.constants.Decoders.Ean13 //: 13,
Barkoder.constants.Decoders.Ean8 //: 14,
Barkoder.constants.Decoders.PDF417 //: 15,
Barkoder.constants.Decoders.PDF417Micro //: 16,
Barkoder.constants.Decoders.Datamatrix //: 17,
Barkoder.constants.Decoders.Code25 //: 18,
Barkoder.constants.Decoders.Interleaved25 //: 19,
Barkoder.constants.Decoders.ITF14 //: 20,
Barkoder.constants.Decoders.IATA25 //: 21,
Barkoder.constants.Decoders.Matrix25 //: 22,
Barkoder.constants.Decoders.Datalogic25 //: 23,
Barkoder.constants.Decoders.COOP25 //: 24,
Barkoder.constants.Decoders.Code32 //: 25,
Barkoder.constants.Decoders.Telepen //: 26,
Barkoder.constants.Decoders.Dotcode //: 27,
Barkoder.constants.Decoders.Databar14 //: 29,
Barkoder.constants.Decoders.DatabarLimited //: 30,
Barkoder.constants.Decoders.DatabarExpanded //: 31,
Barkoder.constants.Decoders.PostalIMB //: 32,
Barkoder.constants.Decoders.Postnet //: 33,
Barkoder.constants.Decoders.Planet //: 34,
Barkoder.constants.Decoders.AustralianPost //: 35,
Barkoder.constants.Decoders.RoyalMail //: 36,
Barkoder.constants.Decoders.KIX //: 37,
Barkoder.constants.Decoders.JapanesePost //: 38
Example:
Barkoder.setEnabledDecoders(
Barkoder.constants.Decoders.QR,
Barkoder.constants.Decoders.Ean8,
Barkoder.constants.Decoders.PDF417
);
Code11ChecksumType #
- disabled: 0
- single: 1
- double: 2
Example:
Barkoder.setCode11ChecksumType(Barkoder.constants.Code11ChecksumType.single);
Code39ChecksumType #
- disabled: 0
- enabled: 1
Example:
Barkoder.setCode39ChecksumType(Barkoder.constants.Code39ChecksumType.enabled);
MsiChecksumType #
- disabled: 0
- mod10: 1
- mode11: 2
- mode1010: 3
- mode1110: 4
- mod11IBM: 5
- mod1110IBM: 6
Example:
Barkoder.setMsiChecksumType(Barkoder.constants.MsiChecksumType.mod1010);
Formatting #
This setting determines if the decoder should apply a specific formatting to results.
- Disabled: 0 - Keep the raw result.
- Automatic: 1 - Detect if result is parsable and apply parsing if so.
- GS1: 2 - Use GS1 parser.
- AAMVA: 3 - Use AAMVA parser.
- SADL: 4 - Use South African Drivers License parser.
Example:
Barkoder.setFormatting(Barkoder.constants.Formatting.AAMVA);
EncodingCharacterSet #
- None: 0
- ISO_8859_2: 1
- ISO_8859_5: 2
- Shift_JIS: 3
- US_ASCII: 4
- UTF_8: 5
- UTF_16: 6
- windows_1251: 7
- windows_1256: 8
Example:
Barkoder.setEncodingCharacterSet(Barkoder.constants.EncodingCharacterSet.UTF_8);
CameraResolution #
- HD: 0 - High Definition: 1280x720
- FHD: 1 - Full HD: 1920x1080
Example:
Barkoder.setCameraResolution(Barkoder.constants.CameraResolution.FHD);
EnableComposite #
- Disable: 0
- Enable: 1
Example:
Barkoder.setEnableComposite(Barkoder.constants.EnableComposite.Enable);
UpcEanDeblur #
- Disable: 0
- Enable: 1
Example:
Barkoder.setUpcEanDeblur(Barkoder.constants.UpcEanDeblur.Enable);
MulticodeCachingEnabled #
- Disable: 0
- Enable: 1
Example:
Barkoder.setMulticodeCachingEnabled(Barkoder.constants.MulticodeCachingEnabled.Enable);
EnableMisshaped1D #
- Disable: 0
- Enable: 1
Example:
Barkoder.setEnableMisshaped1D(Barkoder.constants.EnableMisshaped1D.Enable);
EnableVINRestrictions #
- Disable: 0
- Enable: 1
Barkoder.setEnableVINRestrictions(Barkoder.constants.EnableVINRestrictions.Enable);
Barkoder.Events #
startScanner #
Description: Fires after a startScanner() call, when the first frame from the camera is received
Example:
Barkoder.addEventListener("startScanner", function(e) {
console.log(e.detail); //Prints "Camera started."
});
stopScanner #
Description: Fires after a stopScanner() call, when the camera is stopped and the camera preview is removed.
Example:
Barkoder.addEventListener("stopScanner", function(e) {
console.log(e.detail); //Prints "Camera stopped."
});
scannerTimeout #
Description: Fires after a startScanner() call, when the scanner timeout runs out if the scanning session is not closed by other means (i.e. successfully scanning a barcode in non-continuous mode, calling stopScanner(), etc.), and there is a non-zero timeout value (set via setScannerTimeout method)
Example:
Barkoder.addEventListener("scannerTimeout", function(e) {
console.log(e.detail); //Prints "Scanner timed out."
});