Load barcode detection library
This commit is contained in:
@@ -21,6 +21,7 @@ import "phoenix_html"
|
||||
import { Socket } from "phoenix"
|
||||
import { LiveSocket } from "phoenix_live_view"
|
||||
import topbar from "../vendor/topbar"
|
||||
import "./barcode-scanner"
|
||||
|
||||
let csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
|
||||
let liveSocket = new LiveSocket("/live", Socket, {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { BarcodeDetector } from "barcode-detector/ponyfill";
|
||||
|
||||
const run = async function () {
|
||||
// check supported formats
|
||||
const supportedFormats = await BarcodeDetector.getSupportedFormats();
|
||||
console.log(supportedFormats);
|
||||
|
||||
const barcodeDetector = new BarcodeDetector({
|
||||
// make sure the formats are supported
|
||||
formats: ["qr_code"],
|
||||
});
|
||||
|
||||
const imageFile = await fetch(
|
||||
"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=Hello%20world!",
|
||||
).then((resp) => resp.blob());
|
||||
|
||||
barcodeDetector.detect(imageFile).then(console.log);
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user