Skip to content

Commit

Permalink
Update scan.html
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-shaojun authored Jan 25, 2025
1 parent 8c8e5de commit 30c8031
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
const videoElement = document.getElementById('videoElement');
// Stop the current stream (if exists) before starting a new one
// When the video feed is ready, start detection
videoElement.onloadeddata = undefined

if (stream) {
const tracks = stream.getTracks();
Expand All @@ -126,16 +125,15 @@
videoElement.setAttribute('autoplay', '');
videoElement.setAttribute('muted', '');
videoElement.setAttribute('playsinline', '')

// When the video feed is ready, start detection
videoElement.onloadeddata = async () => {
detectReceipt();
};
}

async function enumerateAndSetupCameras() {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
const deviceList = await navigator.mediaDevices.enumerateDevices();
devices = deviceList.filter(device => device.kind === 'videoinput'); // Only video devices
for(const d of deviceList) {
console.log(d)
}
devices = deviceList // Only video devices
if (devices.length > 0) {
// Start with the first camera
await getCameraStream(devices[currentCameraIndex].deviceId);
Expand All @@ -162,6 +160,11 @@
croppedImageContainer = document.getElementById('croppedImageContainer');
croppedImage = document.getElementById('croppedImage');

// When the video feed is ready, start detection
videoElement.onloadeddata = async () => {
detectReceipt();
};

enumerateAndSetupCameras();

// Set capture button click action
Expand Down

0 comments on commit 30c8031

Please sign in to comment.