nativescript-dynamsoft-barcode-reader
Version:
Nativescript plugin for Dynamsoft Barcode Reader
128 lines • 5.37 kB
JavaScript
import { BarcodeReaderCommon } from './common';
var LicenseListenerImpl = /** @class */ (function (_super) {
__extends(LicenseListenerImpl, _super); // native delegates mostly always extend NSObject
function LicenseListenerImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
LicenseListenerImpl.new = function () {
return _super.new.call(this); // calls new() on the NSObject
};
LicenseListenerImpl.prototype.DBRLicenseVerificationCallbackError = function (isSuccess, error) {
if (this.callback) {
this.callback(isSuccess, error);
}
};
LicenseListenerImpl.prototype.setCallback = function (callback) {
this.callback = callback;
};
LicenseListenerImpl.ObjCProtocols = [DBRLicenseVerificationListener]; // define our native protocalls
return LicenseListenerImpl;
}(NSObject // native delegates mostly always extend NSObject
));
var TextResultListenerImpl = /** @class */ (function (_super) {
__extends(TextResultListenerImpl, _super); // native delegates mostly always extend NSObject
function TextResultListenerImpl() {
return _super !== null && _super.apply(this, arguments) || this;
}
TextResultListenerImpl.new = function () {
return _super.new.call(this); // calls new() on the NSObject
};
TextResultListenerImpl.prototype.textResultCallbackImageDataResults = function (frameId, imageData, results) {
if (this.callback) {
// @ts-ignore
this.callback(this.wrapResult(results));
}
};
TextResultListenerImpl.prototype.setCallback = function (callback, wrapResult) {
this.callback = callback;
this.wrapResult = wrapResult;
};
TextResultListenerImpl.ObjCProtocols = [DBRTextResultListener]; // define our native protocalls
return TextResultListenerImpl;
}(NSObject // native delegates mostly always extend NSObject
));
export class BarcodeReader extends BarcodeReaderCommon {
constructor() {
super();
this.dbr = DynamsoftBarcodeReader.alloc().init();
}
initLicense(license, listener) {
if (!this.licenseListener) {
this.licenseListener = LicenseListenerImpl.new();
}
if (listener) {
this.licenseListener.setCallback(listener);
}
DynamsoftBarcodeReader.initLicenseVerificationDelegate(license, this.licenseListener);
}
initRuntimeSettingsWithString(template) {
this.dbr.initRuntimeSettingsWithStringConflictModeError(template, 2 /* EnumConflictMode.Overwrite */);
}
decodeFrameAsync(frame) {
let pThis = this;
return new Promise(function (resolve, reject) {
let result = pThis.decodeFrame(frame);
resolve(result);
});
}
decodeFrame(frame) {
let results = this.dbr.decodeBufferWithWidthHeightStrideFormatError(frame.imageData, frame.width, frame.height, frame.stride, frame.pixelFormat);
return this.wrapResult(results);
}
decodeBitmap(bitmap) {
let results = this.dbr.decodeImageError(bitmap);
return this.wrapResult(results);
}
decodeFile(file) {
let results = this.dbr.decodeFileWithNameError(file);
return this.wrapResult(results);
}
decodeBase64(base64) {
let image = this.base642UIImage(base64);
return this.decodeBitmap(image);
}
wrapResult(results) {
let textResults = [];
if (results) {
for (let index = 0; index < results.count; index++) {
const result = results[index];
let textResult = {
barcodeText: result.barcodeText,
barcodeFormat: result.barcodeFormatString,
x1: result.localizationResult.resultPoints[0].x,
x2: result.localizationResult.resultPoints[1].x,
x3: result.localizationResult.resultPoints[2].x,
x4: result.localizationResult.resultPoints[3].x,
y1: result.localizationResult.resultPoints[0].y,
y2: result.localizationResult.resultPoints[1].y,
y3: result.localizationResult.resultPoints[2].y,
y4: result.localizationResult.resultPoints[3].y
};
textResults.push(textResult);
}
}
return textResults;
}
base642UIImage(base64) {
let data = NSData.alloc().initWithBase64EncodedStringOptions(base64, 1 /* NSDataBase64DecodingOptions.IgnoreUnknownCharacters */);
let image = UIImage.alloc().initWithData(data);
return image;
}
setCameraEnhancer(dce) {
this.dbr.setCameraEnhancer(dce);
}
startScanning() {
this.dbr.startScanning();
}
stopScanning() {
this.dbr.stopScanning();
}
setTextResultListener(listener) {
if (!this.textResultListener) {
this.textResultListener = TextResultListenerImpl.new();
}
this.textResultListener.setCallback(listener, this.wrapResult);
this.dbr.setDBRTextResultListener(this.textResultListener);
}
}
//# sourceMappingURL=index.ios.js.map