forked from trent_larson/crowd-funder-for-time-pwa
fix: lint
This commit is contained in:
@@ -30,40 +30,54 @@ export class WebDialogQRScanner implements QRScannerService {
|
||||
try {
|
||||
// First check if we have any video devices
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
const videoDevices = devices.filter(device => device.kind === 'videoinput');
|
||||
|
||||
const videoDevices = devices.filter(
|
||||
(device) => device.kind === "videoinput",
|
||||
);
|
||||
|
||||
if (videoDevices.length === 0) {
|
||||
logger.error('No video devices found');
|
||||
throw new Error('No camera found on this device');
|
||||
logger.error("No video devices found");
|
||||
throw new Error("No camera found on this device");
|
||||
}
|
||||
|
||||
// Try to get a stream with specific constraints
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: {
|
||||
facingMode: 'environment',
|
||||
facingMode: "environment",
|
||||
width: { ideal: 1280 },
|
||||
height: { ideal: 720 }
|
||||
}
|
||||
height: { ideal: 720 },
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
// Stop the test stream immediately
|
||||
stream.getTracks().forEach(track => track.stop());
|
||||
stream.getTracks().forEach((track) => track.stop());
|
||||
return true;
|
||||
} catch (error) {
|
||||
const wrappedError = error instanceof Error ? error : new Error(String(error));
|
||||
logger.error('Error requesting camera permissions:', {
|
||||
const wrappedError =
|
||||
error instanceof Error ? error : new Error(String(error));
|
||||
logger.error("Error requesting camera permissions:", {
|
||||
error: wrappedError.message,
|
||||
stack: wrappedError.stack,
|
||||
name: wrappedError.name
|
||||
name: wrappedError.name,
|
||||
});
|
||||
|
||||
// Provide more specific error messages
|
||||
if (wrappedError.name === 'NotFoundError' || wrappedError.name === 'DevicesNotFoundError') {
|
||||
throw new Error('No camera found on this device');
|
||||
} else if (wrappedError.name === 'NotAllowedError' || wrappedError.name === 'PermissionDeniedError') {
|
||||
throw new Error('Camera access denied. Please grant camera permission and try again');
|
||||
} else if (wrappedError.name === 'NotReadableError' || wrappedError.name === 'TrackStartError') {
|
||||
throw new Error('Camera is in use by another application');
|
||||
if (
|
||||
wrappedError.name === "NotFoundError" ||
|
||||
wrappedError.name === "DevicesNotFoundError"
|
||||
) {
|
||||
throw new Error("No camera found on this device");
|
||||
} else if (
|
||||
wrappedError.name === "NotAllowedError" ||
|
||||
wrappedError.name === "PermissionDeniedError"
|
||||
) {
|
||||
throw new Error(
|
||||
"Camera access denied. Please grant camera permission and try again",
|
||||
);
|
||||
} else if (
|
||||
wrappedError.name === "NotReadableError" ||
|
||||
wrappedError.name === "TrackStartError"
|
||||
) {
|
||||
throw new Error("Camera is in use by another application");
|
||||
} else {
|
||||
throw new Error(`Camera error: ${wrappedError.message}`);
|
||||
}
|
||||
@@ -72,32 +86,34 @@ export class WebDialogQRScanner implements QRScannerService {
|
||||
|
||||
async isSupported(): Promise<boolean> {
|
||||
try {
|
||||
// Check for secure context first
|
||||
if (!window.isSecureContext) {
|
||||
logger.warn('Camera access requires HTTPS (secure context)');
|
||||
// Check for secure context first
|
||||
if (!window.isSecureContext) {
|
||||
logger.warn("Camera access requires HTTPS (secure context)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for camera API support
|
||||
if (!navigator.mediaDevices || !navigator.mediaDevices.getUserMedia) {
|
||||
logger.warn('Camera API not supported in this browser');
|
||||
logger.warn("Camera API not supported in this browser");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we have any video devices
|
||||
const devices = await navigator.mediaDevices.enumerateDevices();
|
||||
const hasVideoDevices = devices.some(device => device.kind === 'videoinput');
|
||||
|
||||
const hasVideoDevices = devices.some(
|
||||
(device) => device.kind === "videoinput",
|
||||
);
|
||||
|
||||
if (!hasVideoDevices) {
|
||||
logger.warn('No video devices found');
|
||||
logger.warn("No video devices found");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error('Error checking camera support:', {
|
||||
logger.error("Error checking camera support:", {
|
||||
error: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? error.stack : undefined
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user