Add XR diagnostic logs
Added console-based diagnostics to XRSession.tsx to help debug AR session issues on Quest 3: - Log store initialization and XR feature support checks via navigator.xr. - Emit runtime logs for store state changes, session activation, and session end. - Enhanced AR button to log click and wrap store.enterAR() with console traces for resolution/rejection. X-Lovable-Edit-ID: edt-22fab2e4-d64c-4e9b-9ef2-093ce20274d8
This commit is contained in:
+17
-1
@@ -10,11 +10,23 @@ import { ArrowLeft, Move, RotateCw, QrCode, Download, Crosshair } from 'lucide-r
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { generateMarkerDownloadURL } from '@/lib/trackingMarker';
|
||||
|
||||
// --- Diagnóstico XR ---
|
||||
console.log('[XR] Inicializando store...');
|
||||
console.log('[XR] navigator.xr disponível:', !!navigator.xr);
|
||||
if (navigator.xr) {
|
||||
navigator.xr.isSessionSupported('immersive-ar').then((supported) => {
|
||||
console.log('[XR] immersive-ar suportado:', supported);
|
||||
}).catch((err) => {
|
||||
console.error('[XR] Erro ao checar suporte AR:', err);
|
||||
});
|
||||
}
|
||||
|
||||
// --- XR Store at MODULE level (required by Quest 3 browser) ---
|
||||
const store = createXRStore({
|
||||
hand: { left: true, right: true },
|
||||
controller: { left: true, right: true },
|
||||
});
|
||||
console.log('[XR] Store criado com sucesso');
|
||||
|
||||
// ─── XRModel ───────────────────────────────────────────
|
||||
function XRModel({ url }: { url: string }) {
|
||||
@@ -160,13 +172,17 @@ const XRSession = () => {
|
||||
|
||||
// Listen for XR session state changes
|
||||
useEffect(() => {
|
||||
console.log('[XR] Subscribing to store state changes');
|
||||
const unsubscribe = store.subscribe((state) => {
|
||||
console.log('[XR] Store state changed — session:', !!state.session, 'mode:', state.mode);
|
||||
const session = state.session;
|
||||
if (session && !inXR) {
|
||||
console.log('[XR] ✅ Sessão AR ativa! Features:', (session as any).enabledFeatures);
|
||||
setInXR(true);
|
||||
setAnchorMode('manual');
|
||||
toast.success('Sessão AR iniciada!');
|
||||
session.addEventListener('end', () => {
|
||||
console.log('[XR] ❌ Sessão AR encerrada');
|
||||
setInXR(false);
|
||||
setAnchorMode('manual');
|
||||
});
|
||||
@@ -208,7 +224,7 @@ const XRSession = () => {
|
||||
<span className="font-mono text-xs">Marcador QR</span>
|
||||
</Button>
|
||||
{/* CRITICAL: Direct call without async wrapper to preserve user gesture */}
|
||||
<Button className="gap-2 glow-primary" onClick={() => store.enterAR()}>
|
||||
<Button className="gap-2 glow-primary" onClick={() => { console.log('[XR] Botão AR clicado — chamando store.enterAR()'); store.enterAR().then((s) => console.log('[XR] enterAR resolveu:', s)).catch((e) => console.error('[XR] enterAR rejeitado:', e)); }}>
|
||||
Iniciar Sessão AR
|
||||
</Button>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user