@scr2em/capacitor-scanner 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -121,7 +121,7 @@ removeAllListeners() => Promise<void>
|
|
|
121
121
|
|
|
122
122
|
#### ScannerOptions
|
|
123
123
|
|
|
124
|
-
<code>{ formats?: BarcodeFormat[]; cameraDirection?: 'BACK' | 'FRONT'; }</code>
|
|
124
|
+
<code>{ formats?: BarcodeFormat[]; cameraDirection?: 'BACK' | 'FRONT'; debounceTimeInMilli?: number }</code>
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
#### CapturePhotoResult
|
|
@@ -169,7 +169,7 @@ public class CapacitorScannerPlugin extends Plugin {
|
|
|
169
169
|
cameraProviderFuture.addListener(() -> {
|
|
170
170
|
try {
|
|
171
171
|
cameraProvider = cameraProviderFuture.get();
|
|
172
|
-
bindCamera(cameraProvider, previewView, lensFacing);
|
|
172
|
+
bindCamera(cameraProvider, previewView, lensFacing, call);
|
|
173
173
|
|
|
174
174
|
orientationEventListener = new OrientationEventListener(getContext()) {
|
|
175
175
|
@Override
|
|
@@ -209,7 +209,7 @@ public class CapacitorScannerPlugin extends Plugin {
|
|
|
209
209
|
});
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
private void bindCamera(@NonNull ProcessCameraProvider cameraProvider, PreviewView previewView, int lensFacing) {
|
|
212
|
+
private void bindCamera(@NonNull ProcessCameraProvider cameraProvider, PreviewView previewView, int lensFacing, PluginCall call) {
|
|
213
213
|
cameraProvider.unbindAll();
|
|
214
214
|
|
|
215
215
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
@@ -240,7 +240,7 @@ public class CapacitorScannerPlugin extends Plugin {
|
|
|
240
240
|
.setTargetRotation(rotation)
|
|
241
241
|
.build();
|
|
242
242
|
|
|
243
|
-
imageAnalysis.setAnalyzer(executor, new BarcodeAnalyzer());
|
|
243
|
+
imageAnalysis.setAnalyzer(executor, new BarcodeAnalyzer(call));
|
|
244
244
|
|
|
245
245
|
imageCapture = new ImageCapture.Builder()
|
|
246
246
|
.setTargetResolution(targetResolution)
|
|
@@ -260,18 +260,30 @@ public class CapacitorScannerPlugin extends Plugin {
|
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
@ExperimentalGetImage private class BarcodeAnalyzer implements ImageAnalysis.Analyzer {
|
|
263
|
+
final PluginCall call;
|
|
264
|
+
BarcodeAnalyzer(PluginCall call) {
|
|
265
|
+
this.call = call;
|
|
266
|
+
}
|
|
267
|
+
|
|
263
268
|
@Override
|
|
264
269
|
public void analyze(@NonNull ImageProxy imageProxy) {
|
|
265
270
|
@androidx.camera.core.ExperimentalGetImage
|
|
266
271
|
android.media.Image mediaImage = imageProxy.getImage();
|
|
267
272
|
if (mediaImage != null) {
|
|
268
273
|
InputImage image = InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees());
|
|
269
|
-
scanner
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
274
|
+
if (scanner != null) {
|
|
275
|
+
scanner.process(image)
|
|
276
|
+
.addOnSuccessListener(executor, CapacitorScannerPlugin.this::processBarcodes)
|
|
277
|
+
.addOnFailureListener(executor, e -> {
|
|
278
|
+
echo("Failed to process image: " + e.getMessage());
|
|
279
|
+
call.reject("Failed to process image: " + e.getMessage());
|
|
280
|
+
})
|
|
281
|
+
.addOnCompleteListener(task -> imageProxy.close());
|
|
282
|
+
} else {
|
|
283
|
+
imageProxy.close();
|
|
284
|
+
echo("Scanner is null, skipping analysis");
|
|
285
|
+
call.reject("Scanner is null, skipping analysis");
|
|
286
|
+
}
|
|
275
287
|
} else {
|
|
276
288
|
imageProxy.close();
|
|
277
289
|
}
|
package/dist/docs.json
CHANGED
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
"docs": "",
|
|
198
198
|
"types": [
|
|
199
199
|
{
|
|
200
|
-
"text": "{\n formats?: BarcodeFormat[];\n cameraDirection?: 'BACK' | 'FRONT';\n}",
|
|
200
|
+
"text": "{\n formats?: BarcodeFormat[];\n cameraDirection?: 'BACK' | 'FRONT';\n debounceTimeInMilli?: number\n}",
|
|
201
201
|
"complexTypes": [
|
|
202
202
|
"BarcodeFormat"
|
|
203
203
|
]
|
|
@@ -11,6 +11,7 @@ export interface CapacitorScannerPlugin {
|
|
|
11
11
|
export declare type ScannerOptions = {
|
|
12
12
|
formats?: BarcodeFormat[];
|
|
13
13
|
cameraDirection?: 'BACK' | 'FRONT';
|
|
14
|
+
debounceTimeInMilli?: number;
|
|
14
15
|
};
|
|
15
16
|
export declare type BarcodeScannedEvent = {
|
|
16
17
|
scannedCode: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAuBA,MAAM,CAAN,IAAY,aAYX;AAZD,WAAY,aAAa;IACvB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,qCAAoB,CAAA;IACpB,2CAA0B,CAAA;IAC1B,+BAAc,CAAA;IACd,iCAAgB,CAAA;IAChB,gCAAe,CAAA;IACf,mCAAkB,CAAA;IAClB,mCAAkB,CAAA;IAClB,+BAAc,CAAA;AAChB,CAAC,EAZW,aAAa,KAAb,aAAa,QAYxB","sourcesContent":["export interface CapacitorScannerPlugin {\n startScanning(options?: ScannerOptions): Promise<void>;\n stopScanning(): Promise<void>;\n openSettings(): Promise<void>;\n capturePhoto(): Promise<CapturePhotoResult>;\n checkPermissions(): Promise<PermissionsResult>;\n requestPermissions(): Promise<PermissionsResult>;\n addListener(event: 'barcodeScanned', listenerFunc: (result: BarcodeScannedEvent) => void): Promise<void>;\n removeAllListeners(): Promise<void>;\n}\n\nexport type ScannerOptions = {\n formats?: BarcodeFormat[];\n cameraDirection?: 'BACK' | 'FRONT';\n debounceTimeInMilli?: number\n};\n\nexport type BarcodeScannedEvent = { scannedCode: string; format: string };\n\nexport type PermissionsResult = { camera: 'prompt' | 'denied' | 'granted' };\n\nexport type CapturePhotoResult = { imageBase64: string };\n\nexport enum BarcodeFormat {\n Aztec = 'AZTEC',\n Code39 = 'CODE_39',\n Code93 = 'CODE_93',\n Code128 = 'CODE_128',\n DataMatrix = 'DATA_MATRIX',\n Ean8 = 'EAN_8',\n Ean13 = 'EAN_13',\n Itf14 = 'ITF14',\n Pdf417 = 'PDF_417',\n QrCode = 'QR_CODE',\n UpcE = 'UPC_E',\n}\n\ndeclare global {\n interface PluginRegistry {\n QRScanner: CapacitorScannerPlugin;\n }\n}\n"]}
|