mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-20 13:48:21 +02:00
Improve camera support and photo capture, especially on tablets
Enhance camera functionalities with improved constraints, fallbacks, UI, and error handling within CameraModal and useCamera hook. Replit-Commit-Author: Agent Replit-Commit-Session-Id: dec54137-d5a2-4406-8ad4-5f2f9fb110bf Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/dcf949f8-2931-4556-aa3c-e4bf61346ee3.jpg
This commit is contained in:
1 parent
a589c8b770
commit
9b0a09614a
4 files changed
+82
-9
No files matched your search
@@ -12,9 +12,47 @@ export function useCamera() {
|
||||
|
||||
const startCamera = useCallback(async (photoType: PhotoType) => {
|
||||
try {
|
||||
const stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: { facingMode: 'environment' }
|
||||
});
|
||||
// Configuration avancée pour tablettes et appareils mobiles
|
||||
const constraints = {
|
||||
video: {
|
||||
facingMode: 'environment', // Caméra arrière par défaut
|
||||
width: { ideal: 1280, max: 1920 }, // Résolution optimale
|
||||
height: { ideal: 720, max: 1080 },
|
||||
aspectRatio: { ideal: 16/9 },
|
||||
frameRate: { ideal: 30 }
|
||||
}
|
||||
};
|
||||
|
||||
let stream: MediaStream;
|
||||
|
||||
try {
|
||||
// Essai avec caméra arrière
|
||||
stream = await navigator.mediaDevices.getUserMedia(constraints);
|
||||
} catch (backCameraError) {
|
||||
console.warn('Caméra arrière non disponible, essai avec caméra avant:', backCameraError);
|
||||
|
||||
// Fallback vers caméra avant si arrière non disponible
|
||||
const frontConstraints = {
|
||||
video: {
|
||||
facingMode: 'user',
|
||||
width: { ideal: 1280, max: 1920 },
|
||||
height: { ideal: 720, max: 1080 },
|
||||
aspectRatio: { ideal: 16/9 },
|
||||
frameRate: { ideal: 30 }
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
stream = await navigator.mediaDevices.getUserMedia(frontConstraints);
|
||||
} catch (frontCameraError) {
|
||||
console.warn('Caméra avant non disponible, essai basique:', frontCameraError);
|
||||
|
||||
// Fallback minimal pour compatibilité maximale
|
||||
stream = await navigator.mediaDevices.getUserMedia({
|
||||
video: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
streamRef.current = stream;
|
||||
setCurrentPhotoType(photoType);
|
||||
@@ -27,7 +65,7 @@ export function useCamera() {
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Camera error:', error);
|
||||
throw new Error('Impossible d\'accéder à la caméra');
|
||||
throw new Error('Impossible d\'accéder à la caméra. Vérifiez les permissions et la disponibilité des caméras.');
|
||||
}
|
||||
}, []);
|
||||
|
||||
|
||||
Reference in new issue
Block a user