Skip to content

Commit

Permalink
Prototype of scan
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMikes committed May 12, 2024
1 parent 0fd29c2 commit 809763d
Show file tree
Hide file tree
Showing 6 changed files with 566 additions and 7 deletions.
39 changes: 39 additions & 0 deletions assets/controllers/barcode_scanner_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Controller } from '@hotwired/stimulus';
import Quagga from 'quagga';

export default class extends Controller {
static targets = ["stream"];

connect() {
Quagga.init({
inputStream: {
name: "Live",
type: "LiveStream",
target: this.streamTarget, // This is where the video will be attached
constraints: {
facingMode: "environment"
},
},
decoder: {
readers: ["ean_reader"]
},
}, (err) => {
if (err) {
console.error(err);
return;
}
Quagga.start();
});

Quagga.onDetected(this.onDetected.bind(this));
}

onDetected(result) {
console.log(result.codeResult.code); // Log barcode to console or handle as needed
// Optionally, send the code to your backend here
}

disconnect() {
Quagga.stop();
}
}
Loading

0 comments on commit 809763d

Please sign in to comment.