Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ ext {
}
```

Note: Android with `ZXING` scanning library supports all formats, while `MLKIT` supports all but `MAXICODE`, `RSS_14`, `RSS_EXPANDED` and `UPC_EAN_EXTENSION` - using one of these in `hint` will default to scanning any format.
Note: Android with `ZXING` scanning library supports all formats, while `MLKIT` supports all except `MAXICODE`, `RSS_14`, `RSS_EXPANDED` and `UPC_EAN_EXTENSION` - using one of these in `hint` will default to scanning any format.

#### iOS

The barcode scanner uses the camera on the device. Ensure you configure the Privacy - Camera Usage Description in your Info.plist file so that your application can access the device's camera.

Note: iOS supports all formats but `MAXICODE` and `UPC_EAN_EXTENSION` - using them in `hint` will default to scanning any format. Also, Apple Vision does not distinguish between `UPC_A` and `EAN_13`, so specifying one of these in `hint` will allow to scan both.
Note: iOS supports all formats except `MAXICODE` and `UPC_EAN_EXTENSION` - using them in `hint` will default to scanning any format. Also, Apple Vision does not distinguish between `UPC_A` and `EAN_13`, so specifying one of these in `hint` will allow to scan both.

---

Expand Down
2 changes: 1 addition & 1 deletion plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@
"src": "android"
}
}
}
}
24 changes: 20 additions & 4 deletions plugin/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ import type {
CapacitorBarcodeScannerOptions,
CapacitorBarcodeScannerScanResult,
} from './definitions';
import { CapacitorBarcodeScannerScanOrientation, CapacitorBarcodeScannerTypeHint } from './definitions';
import {
CapacitorBarcodeScannerCameraDirection,
CapacitorBarcodeScannerScanOrientation,
CapacitorBarcodeScannerTypeHint,
} from './definitions';

/**
* Implements OSBarcodePlugin to provide web functionality for barcode scanning.
*/
export class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBarcodeScannerPlugin {
private static _FORWARD = { facingMode: 'user' };
private static _BACK = { facingMode: 'environment' };
private _facingMode: MediaTrackConstraints = CapacitorBarcodeScannerWeb._BACK;
/**
* Stops the barcode scanner and hides its UI.
* @private
Expand Down Expand Up @@ -81,9 +88,18 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBa
this.buildScannerElement();
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
document.getElementById('cap-os-barcode-scanner-container-dialog')!.style.display = 'block';

// Set the facing mode based on camera direction option
if (options.cameraDirection !== undefined) {
this._facingMode =
options.cameraDirection === CapacitorBarcodeScannerCameraDirection.BACK
? CapacitorBarcodeScannerWeb._BACK
: CapacitorBarcodeScannerWeb._FORWARD;
}

return new Promise((resolve, reject) => {
const param = {
facingMode: options.cameraDirection === 1 ? 'environment' : 'user',
facingMode: this._facingMode.facingMode,
hasScannerButton: false,
scanButton: options.scanButton === undefined ? false : options.scanButton,
showScanLine: false,
Expand Down Expand Up @@ -114,7 +130,7 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBa
focusMode: 'continuous',
height: { min: 576, ideal: 1920 },
deviceId: undefined,
facingMode: param.facingMode,
facingMode: this._facingMode.facingMode,
},
};

Expand Down Expand Up @@ -142,7 +158,7 @@ export class CapacitorBarcodeScannerWeb extends WebPlugin implements CapacitorBa
};

(window as any).OSBarcodeWebScanner.start(
{ facingMode: param.facingMode },
this._facingMode,
Html5QrcodeConfig,
OSBarcodeWebScannerSuccessCallback,
OSBarcodeWebScannerErrorCallback
Expand Down