Skip to content

Commit 300564e

Browse files
committed
- playing around with the spotify API
1 parent 009a7db commit 300564e

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

tools/spotify_qr_scanner.html

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@
88
<div id="reader"></div>
99

1010
<script>
11-
function onScanSuccess(decodedText) {
12-
if (decodedText.includes('gptgames.dev')) {
13-
window.location.href = decodedText;
11+
async function startScanner() {
12+
try {
13+
// Check if we already have camera permission
14+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
15+
stream.getTracks().forEach(track => track.stop()); // Clean up test stream
16+
17+
// Initialize scanner
18+
const html5QrcodeScanner = new Html5QrcodeScanner("reader", { fps: 10 });
19+
html5QrcodeScanner.render((decodedText) => {
20+
if (decodedText.includes('gptgames.dev')) {
21+
window.location.href = decodedText;
22+
}
23+
});
24+
} catch (err) {
25+
// We don't have permission, let's request it
26+
const permissionResult = await navigator.mediaDevices.getUserMedia({ video: true });
27+
// If we get here, permission was granted, start scanner
28+
startScanner();
1429
}
1530
}
1631

17-
let html5QrcodeScanner = new Html5QrcodeScanner(
18-
"reader",
19-
{ fps: 10 }
20-
);
21-
22-
html5QrcodeScanner.render(onScanSuccess);
32+
// Start immediately when page loads
33+
startScanner();
2334
</script>
2435

2536
<style>

0 commit comments

Comments
 (0)