Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
set back camera to default on web. do something with the CameraDirect…
Browse files Browse the repository at this point in the history
…ion option - choose front or back camera if it exists. (#254)
  • Loading branch information
pkunszt authored May 31, 2023
1 parent 7767935 commit 5a1e8d6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import {
} from './definitions';

export class BarcodeScannerWeb extends WebPlugin implements BarcodeScannerPlugin {
private static _FORWARD = { facingMode: 'user' };
private static _BACK = { facingMode: 'environment' };
private _formats: number[] = [];
private _controls: IScannerControls | null = null;
private _torchState = false;
private _video: HTMLVideoElement | null = null;
private _options: ScanOptions | null = null;
private _backgroundColor: string | null = null;
private _facingMode: MediaTrackConstraints = BarcodeScannerWeb._BACK;

async prepare(): Promise<void> {
await this._getVideoElement();
Expand Down Expand Up @@ -49,6 +52,9 @@ export class BarcodeScannerWeb extends WebPlugin implements BarcodeScannerPlugin
console.error(format, 'is not supported on web');
}
});
if (!!_options?.cameraDirection) {
this._facingMode = _options.cameraDirection === CameraDirection.BACK ? BarcodeScannerWeb._BACK : BarcodeScannerWeb._FORWARD;
}
const video = await this._getVideoElement();
if (video) {
return await this._getFirstResultFromReader();
Expand Down Expand Up @@ -232,7 +238,7 @@ export class BarcodeScannerWeb extends WebPlugin implements BarcodeScannerPlugin

if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
const constraints: MediaStreamConstraints = {
video: {},
video: this._facingMode,
};

navigator.mediaDevices.getUserMedia(constraints).then(
Expand Down

0 comments on commit 5a1e8d6

Please sign in to comment.