-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
566 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.