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
02a0088d28
commit
a1c6e599c3
5 files changed
+174
-163
No files matched your search
@@ -18,16 +18,19 @@ export const ensureScannerCompatibility = () => {
|
||||
|
||||
// Polyfill for older browsers that don't implement getUserMedia
|
||||
if (!navigator.mediaDevices.getUserMedia) {
|
||||
navigator.mediaDevices.getUserMedia = function(constraints) {
|
||||
const getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
|
||||
|
||||
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'));
|
||||
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) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
getUserMedia.call(navigator, constraints, resolve, reject);
|
||||
});
|
||||
};
|
||||
@@ -50,29 +53,31 @@ export const ensureScannerCompatibility = () => {
|
||||
export const checkCameraAvailability = async () => {
|
||||
try {
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||
return { available: false, error: 'MediaDevices API not supported' };
|
||||
return { available: false, error: "MediaDevices API not supported" };
|
||||
}
|
||||
|
||||
|
||||
// Try to access the camera with explicit video request
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: true,
|
||||
audio: false
|
||||
audio: false,
|
||||
});
|
||||
|
||||
|
||||
// If we get here, camera is available - stop the stream
|
||||
if (stream) {
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
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'
|
||||
permission:
|
||||
error.name === "NotAllowedError" ||
|
||||
error.name === "PermissionDeniedError"
|
||||
? "denied"
|
||||
: "unknown",
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user