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 0d1c07a commit 8c8e5de
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions scan.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@

let currentCameraIndex = 0;
let devices = [];
let stream = null;

async function getCameraStream(deviceId) {

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();
tracks.forEach(track => track.stop());
Expand All @@ -117,11 +121,16 @@
stream = await navigator.mediaDevices.getUserMedia({
video: { deviceId }
});
const videoElement = document.getElementById('videoElement');

videoElement.srcObject = stream;
videoElement.setAttribute('autoplay', '');
videoElement.setAttribute('muted', '');
videoElement.setAttribute('playsinline', '')

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

async function enumerateAndSetupCameras() {
Expand All @@ -137,6 +146,7 @@
document.getElementById('switchCameraBtn').addEventListener('click', async () => {
// Go to the next camera in the list, wrap around to the first camera if at the end
currentCameraIndex = (currentCameraIndex + 1) % devices.length;
console.log(devices.length)
await getCameraStream(devices[currentCameraIndex].deviceId);
});

Expand All @@ -154,11 +164,6 @@

enumerateAndSetupCameras();

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

// Set capture button click action
captureButton.addEventListener('click', captureImage);
}
Expand Down

0 comments on commit 8c8e5de

Please sign in to comment.