mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
SCANNER WORKS!!! JUST ADD THE MORE CLUE BUTTONS !!! AND NEXT CLUE ERROR CHECKING
This commit is contained in:
1 parent
07099ba6b4
commit
02a0088d28
11 files changed
+861
-217
No files matched your search
@@ -0,0 +1,78 @@
|
||||
// This is a helper function to ensure QR scanner compatibility
|
||||
export const ensureScannerCompatibility = () => {
|
||||
// Add basic polyfills for methods that might be missing
|
||||
if (typeof Function.prototype.bind !== "function") {
|
||||
Function.prototype.bind = function (context) {
|
||||
const fn = this;
|
||||
return function () {
|
||||
return fn.apply(context, arguments);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// Ensure MediaDevices API is available
|
||||
if (typeof window !== "undefined") {
|
||||
if (!navigator.mediaDevices) {
|
||||
navigator.mediaDevices = {};
|
||||
}
|
||||
|
||||
// Polyfill for older browsers that don't implement getUserMedia
|
||||
if (!navigator.mediaDevices.getUserMedia) {
|
||||
navigator.mediaDevices.getUserMedia = function(constraints) {
|
||||
const getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
||||
|
||||
// Return a rejected promise if getUserMedia is not implemented
|
||||
if (!getUserMedia) {
|
||||
return Promise.reject(new Error('getUserMedia is not implemented in this browser'));
|
||||
}
|
||||
|
||||
// Otherwise, wrap the call to the old navigator.getUserMedia with a Promise
|
||||
return new Promise(function(resolve, reject) {
|
||||
getUserMedia.call(navigator, constraints, resolve, reject);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
// Ensure console methods exist for debugging
|
||||
if (!window.console) window.console = {};
|
||||
const methods = ["log", "error", "warn", "info"];
|
||||
methods.forEach((method) => {
|
||||
if (!window.console[method]) {
|
||||
window.console[method] = function () {};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Helper function to check if camera is available and accessible
|
||||
export const checkCameraAvailability = async () => {
|
||||
try {
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||
return { available: false, error: 'MediaDevices API not supported' };
|
||||
}
|
||||
|
||||
// Try to access the camera with explicit video request
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: true,
|
||||
audio: false
|
||||
});
|
||||
|
||||
// If we get here, camera is available - stop the stream
|
||||
if (stream) {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
}
|
||||
|
||||
return { available: true };
|
||||
} catch (error) {
|
||||
return {
|
||||
available: false,
|
||||
error: error.message,
|
||||
name: error.name,
|
||||
permission: error.name === 'NotAllowedError' || error.name === 'PermissionDeniedError'
|
||||
? 'denied'
|
||||
: 'unknown'
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user