From 4fa0419ba9d689c43610b05f3ea3e99b9c16cdf8 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Mon, 17 Mar 2025 13:30:49 +0000 Subject: [PATCH] added more clue buttons and positioned them correctly, need to fix elapsed timer on clue page.... Error handling with clues improved. --- app/(main)/clue/[clueId]/page.js | 6 ++-- clue_hunt.db | Bin 155648 -> 155648 bytes components/EnhancedQRScanner.js | 47 +++++++++++++++++-------------- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/app/(main)/clue/[clueId]/page.js b/app/(main)/clue/[clueId]/page.js index fe37aef..9709f04 100644 --- a/app/(main)/clue/[clueId]/page.js +++ b/app/(main)/clue/[clueId]/page.js @@ -567,9 +567,9 @@ export default function CluePage({ params }) { {/* QR Scanner Section */}

Scan QR Code

- diff --git a/clue_hunt.db b/clue_hunt.db index 84414f5c74436c9680d10270fae24ce6ac1f67bf..e678017b5a38768fad8c52b60def16b941bf93e0 100644 GIT binary patch delta 841 zcmbV}J5Iwu6h-}!uw5CD5CuO=gg-X(W;}Lc2}L3mRT?Uk!aG1>14&0?K_UuofCYeD zq)nHC0!mhp1-PW*O^}Tej~m+2x#!N@8BDCf#2Rj?)6sTEoxa7Lw#u`YcI@by{hk@| zmu;|!wjv&8v%B3-Q?ql${nLZW~<^d0@MT9{@Wue~;34D15>N3O&gJ3aZ ziI)-r2}wV$w2eJnk9%PY7ODBF9FmI?5~}5TF+G~R0`k$c+$T&vn%ojXQz)tP(R5xw zOqe8f3{7VxRC6bWrqcqVH71ItlM)gpR-J&N>9~MEm?RLO>8ONiOn|1t0wQQ?N+uv^ kIw&ErlcY}kT_b(!X`4IZ=c+eq;*UbIKS##*J?&Bd0o7f@EdT%j delta 100 zcmV-q0Gt1SzzKlB36L8Bw2>S`0kpATLq7o{v!p*@AOisp=CcQ2*bfIVIxsOhGcdE} zZywMH0T22B5Bd-Cw-F!#<`0MRPXU+mPXZDH5)4?A2aqMRF%T>a12K#vmycWm7q@a; G0*(X4$RPay diff --git a/components/EnhancedQRScanner.js b/components/EnhancedQRScanner.js index e4a6ec5..f011680 100644 --- a/components/EnhancedQRScanner.js +++ b/components/EnhancedQRScanner.js @@ -19,7 +19,7 @@ export default function EnhancedQRScanner({ const [cameraPermissionDenied, setCameraPermissionDenied] = useState(false); const cameraStreamRef = useRef(null); const [retryCount, setRetryCount] = useState(0); - + // We're keeping torchEnabled state but only using it if torch is enabled const [torchEnabled, setTorchEnabled] = useState(false); const inputRef = useRef(null); @@ -50,15 +50,16 @@ export default function EnhancedQRScanner({ try { // Release any stream that might be stored in our ref if (cameraStreamRef.current) { - cameraStreamRef.current.getTracks().forEach(track => { + cameraStreamRef.current.getTracks().forEach((track) => { track.stop(); }); cameraStreamRef.current = null; console.log("Released existing camera resources"); } - + // Also try to find and release any active video tracks that might be running - navigator.mediaDevices.getUserMedia({ audio: false, video: false }) + navigator.mediaDevices + .getUserMedia({ audio: false, video: false }) .catch(() => { // This intentionally fails but helps release resources in some browsers }); @@ -180,13 +181,13 @@ export default function EnhancedQRScanner({ try { setError(null); setCameraActive(false); - + // First release any existing camera resources releaseCameraResources(); - + // Add a small delay to ensure resources are properly released - await new Promise(resolve => setTimeout(resolve, 500)); - + await new Promise((resolve) => setTimeout(resolve, 500)); + // Now try to get fresh camera access const stream = await navigator.mediaDevices.getUserMedia({ video: true, @@ -197,20 +198,20 @@ export default function EnhancedQRScanner({ if (stream) { // Store the stream reference for potential future release cameraStreamRef.current = stream; - + // Release this stream since useZxing will request its own stream.getTracks().forEach((track) => track.stop()); - + setCameraActive(true); setCameraPermissionDenied(false); setRetryCount(0); // Reset retry count on success } } catch (err) { console.error("Failed to get camera permission:", err); - + // Increment retry count - setRetryCount(prev => prev + 1); - + setRetryCount((prev) => prev + 1); + if ( err.name === "NotAllowedError" || err.name === "PermissionDeniedError" @@ -224,9 +225,13 @@ export default function EnhancedQRScanner({ err.name === "TrackStartError" || retryCount < 2 // Try a few times before showing hardware error ) { - setError(`Camera temporarily unavailable. Please try again in a few moments.`); + setError( + `Camera temporarily unavailable. Please try again in a few moments.` + ); } else { - setError(`Camera error: ${err.message}. You may need to restart your browser or device.`); + setError( + `Camera error: ${err.message}. You may need to restart your browser or device.` + ); } } }; @@ -242,10 +247,13 @@ export default function EnhancedQRScanner({ // Handle camera errors const handleError = (error) => { console.error("QR Scanner error:", error); - + // Don't immediately deactivate camera on all errors // Some errors can be temporary - if (error.name === "NotAllowedError" || error.name === "PermissionDeniedError") { + if ( + error.name === "NotAllowedError" || + error.name === "PermissionDeniedError" + ) { setCameraActive(false); } @@ -327,10 +335,7 @@ export default function EnhancedQRScanner({
) : ( - )}