1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { Facial } from './libvbar-m-dxfacial.so';
import log from './dxLogger.js'
 
const dxFacialBarcode = {};
const _native = new Facial();
let _callbacks = {};
 
/**
 * Initializes the barcode client. Must be called before any other operation.
 * @param {object} config - The configuration object.
 * @param {number} config.scanInterval - The interval between scans in milliseconds.
 * @param {number} config.scanTimeout - The timeout for a scan in milliseconds.
 * @param {number} config.roiX - The x-coordinate of the ROI.
 * @param {number} config.roiY - The y-coordinate of the ROI.
 * @example
 * dxFacialBarcode.init();
 */
dxFacialBarcode.init = function () {
    _native.initBarCode();
};
 
/**
 * Deinitializes the barcode client and releases resources.
 * @returns {void}
 * @example
 * dxFacialBarcode.deinit();
 */
dxFacialBarcode.deinit = function () {
    _native.deinitBarCode();
};
 
/**
 * Sets the callback function for barcode events.
 * @param {object} callbacks - The callback functions.
 * @param {function(object)} [callbacks.onEvent] - The callback function to handle barcode event.
 * @returns {void}
 * @example
 * dxFacialBarcode.setCallbacks({
 *   onEvent: function(event) {
 *     logger.info('Barcode event:', event);
 *   }
 * });
 */
dxFacialBarcode.setCallbacks = function (callbacks) {
    if (!callbacks || !callbacks.onEvent) {
        throw new Error('Callbacks must be an object with onEvent function');
    }
    _callbacks = callbacks;
};
 
/**
 * Sets the configuration for the barcode scanner.
 * @param {object} config - The configuration object.
 * @param {number} config.scanInterval - The interval between scans in milliseconds.
 * @param {number} config.scanTimeout - The timeout for a scan in milliseconds.
 * @param {number} config.roiX - The x-coordinate of the ROI.
 * @param {number} config.roiY - The y-coordinate of the ROI.
 */
dxFacialBarcode.setConfig = function (config) {
    _native.setConfigBarCode(config);
};
 
/**
 * Gets the configuration for the barcode scanner.
 * @returns {object} The configuration object.
 */
dxFacialBarcode.getConfig = function () {
    return _native.getConfigBarCode();
};
 
/**
 * Sets the status of the barcode scanner.
 * @param {boolean} status - The status of the barcode scanner.
 */
dxFacialBarcode.setStatus = function (status) {
    _native.setStatusBarCode(status);
};
 
/**
 * Processes events from the barcode event queue. Should be called periodically (e.g. in setInterval).
 * Handles barcode events and calls the registered callback function.
 * 
 * @example
 * setInterval(() => {
 *   dxFacialBarcode.loop();
 * }, 10); // Process events every 10ms
 */
dxFacialBarcode.loop = function () {
    try {
        let event = _native.getBarCodeEvent();
        if (event && _callbacks.onEvent) {
            _callbacks.onEvent(event);
        }
    } catch (e) {
        log.error('Error in barcode loop:', e);
    }
};
 
/**
 * Gets the native barcode client object.
 * @returns {Object|null} The native client object, or null if not initialized.
 */
dxFacialBarcode.getNative = function () {
    return _native;
};
 
export default dxFacialBarcode;