Skip to content

Commit

Permalink
Merge PR cozmo#205: Usability improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
danimoh committed Jan 19, 2022
2 parents 2f6474a + 4d777b5 commit 94fea50
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ <h1>jsQR Demo</h1>
canvas.stroke();
}

var lastResult = null;

// Use facingMode: environment to attemt to get the front camera on phones
navigator.mediaDevices.getUserMedia({ video: { facingMode: "environment" } }).then(function(stream) {
video.srcObject = stream;
Expand All @@ -102,17 +104,21 @@ <h1>jsQR Demo</h1>
var code = jsQR(imageData.data, imageData.width, imageData.height, {
inversionAttempts: "dontInvert",
});
outputMessage.hidden = true;
outputData.parentElement.hidden = false;
var result;
if (code) {
drawLine(code.location.topLeftCorner, code.location.topRightCorner, "#FF3B58");
drawLine(code.location.topRightCorner, code.location.bottomRightCorner, "#FF3B58");
drawLine(code.location.bottomRightCorner, code.location.bottomLeftCorner, "#FF3B58");
drawLine(code.location.bottomLeftCorner, code.location.topLeftCorner, "#FF3B58");
outputMessage.hidden = true;
outputData.parentElement.hidden = false;
outputData.innerText = code.data;
result = code.data;
} else {
outputMessage.hidden = false;
outputData.parentElement.hidden = true;
result = "No code detected";
}
if (result !== lastResult) {
outputData.innerText += result + "\n";
lastResult = result;
}
}
requestAnimationFrame(tick);
Expand Down

0 comments on commit 94fea50

Please sign in to comment.