Skip to content

Commit

Permalink
feat: add possibility to configure all parameters of quagga, providin…
Browse files Browse the repository at this point in the history
…g default values if not set
  • Loading branch information
julienboulay committed Oct 10, 2020
1 parent 87fe153 commit 2c58818
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 24 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@angular/platform-browser-dynamic": "~10.1.3",
"@angular/router": "~10.1.3",
"bootstrap": ">=4.3.1",
"lodash.defaultsdeep": "^4.6.1",
"ngx-bootstrap": "^6.1.0",
"quagga": "^0.12.1",
"rxjs": "~6.6.0",
Expand All @@ -54,6 +55,7 @@
"@angular/compiler-cli": "~10.1.3",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/lodash.defaultsdeep": "^4.6.6",
"@types/node": "^12.11.1",
"angular-cli-ghpages": "^0.6.2",
"codelyzer": "^6.0.0",
Expand All @@ -70,4 +72,4 @@
"tslint": "~6.1.0",
"typescript": "~4.0.2"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<div class="barcode-scanner-livestream-overlay" [hidden]="!showScanner">
<div class="barcode-scanner-livestream-overlay-content">
<div class="barcode-scanner-livestream-overlay-close" *ngIf="isStarted" (click)="hide()">X</div>
<barcode-scanner-livestream [type]="type" [deviceId]="deviceId" (valueChanges)="onValueChanges($event)" (started)="onStarted($event)"></barcode-scanner-livestream>
<div class="barcode-scanner-livestream-overlay-content">
<div
class="barcode-scanner-livestream-overlay-close"
*ngIf="isStarted"
(click)="hide()"
>
X
</div>
</div>
<barcode-scanner-livestream
[type]="type"
[deviceId]="deviceId"
[config]="config"
(valueChanges)="onValueChanges($event)"
(started)="onStarted($event)"
></barcode-scanner-livestream>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Component, EventEmitter, Input, OnDestroy, Output, ViewChild
} from '@angular/core';
import { BarecodeScannerLivestreamComponent } from '../barcode-scanner-livestream/barcode-scanner-livestream.component';
import { QuaggaConfig } from '../barcode-scanner-livestream/barcode-scanner-livestream.config';

@Component({
selector: 'barcode-scanner-livestream-overlay',
Expand All @@ -21,6 +22,8 @@ export class BarecodeScannerLivestreamOverlayComponent implements OnDestroy {

@Input() deviceId: string;

@Input() config: QuaggaConfig;

@Output() valueChanges = new EventEmitter<string>();

@Output() started = new EventEmitter<boolean>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Component, ElementRef, EventEmitter, Input, OnChanges, OnDestroy, Output, SimpleChanges, ViewChild, ViewEncapsulation
} from '@angular/core';
import defaultsDeep from 'lodash.defaultsdeep';
import * as Quagga from 'quagga';
import { DEFAULT_CONFIG, QuaggaConfig } from './barcode-scanner-livestream.config';
import { mapToReader } from './barcode-types';
Expand All @@ -17,6 +18,8 @@ export class BarecodeScannerLivestreamComponent implements OnChanges, OnDestroy

@Input() deviceId: string;

@Input() config: QuaggaConfig;

// Outputs
@Output() valueChanges = new EventEmitter();

Expand All @@ -30,7 +33,7 @@ export class BarecodeScannerLivestreamComponent implements OnChanges, OnDestroy
return this._started;
}

private configQuagga: QuaggaConfig = DEFAULT_CONFIG;
private configQuagga: QuaggaConfig;

ngOnDestroy(): void {
this.stop();
Expand All @@ -46,6 +49,8 @@ export class BarecodeScannerLivestreamComponent implements OnChanges, OnDestroy

Quagga.onDetected((result) => this.onDetected(result));

this.configQuagga = defaultsDeep({}, this.config, DEFAULT_CONFIG);

this.configQuagga.inputStream.target = this.barecodeScanner.nativeElement;

if (this.type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const DEFAULT_CONFIG = {
constraints: {
width: { min: 640 },
height: { min: 480 },
aspectRatio: { min: 1, max: 100 },
aspectRatio: { min: 1, max: 1 },
facingMode: 'environment', // or user
},
singleChannel: false // true: only the red color-channel is read
Expand Down
12 changes: 4 additions & 8 deletions projects/ngx-barcode-scanner/tsconfig.lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
]
"lib": ["dom", "es2018"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
"exclude": ["src/test.ts", "**/*.spec.ts"]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, ViewChild } from '@angular/core';
import { Component, ViewChild } from '@angular/core';
import { BarecodeScannerLivestreamOverlayComponent } from 'ngx-barcode-scanner';

@Component({
Expand All @@ -13,15 +13,15 @@ export class BarcodeScannerOverlayRouteComponent {

barcodeValue: string;

startBarecodeScannerOverlay() {
startBarecodeScannerOverlay(): void {
this.barecodeScannerOverlay.show();
}

onValueChanges(result) {
onValueChanges(result): void {
this.barcodeValue = result.codeResult.code;
}

onStarted(event: boolean) {
onStarted(event: boolean): void {
console.log('started', event);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, ViewChild, AfterViewInit } from '@angular/core';
import { AfterViewInit, Component, ViewChild } from '@angular/core';
import { BarecodeScannerLivestreamComponent } from 'ngx-barcode-scanner';

@Component({
Expand All @@ -13,15 +13,15 @@ export class BarcodeScannerLivestreamRouteComponent implements AfterViewInit {

barcodeValue;

ngAfterViewInit() {
ngAfterViewInit(): void {
this.barecodeScanner.start();
}

onValueChanges(result) {
onValueChanges(result): void {
this.barcodeValue = result.codeResult.code;
}

onStarted(event) {
onStarted(event): void {
console.log('started', event);
}

Expand Down
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"lib": ["es2018", "dom"],
"paths": {
"ngx-barcode-scanner": ["projects/ngx-barcode-scanner/src/public-api.ts"]
}
},
"allowSyntheticDefaultImports": true,
"esModuleInterop": true
}
}

0 comments on commit 2c58818

Please sign in to comment.