🔧 Fix: modo AR travando em loading — timeout de segurança, feedback visual no botão e auto-return retardado

- Viewer: loading state no botão 'Entrar em Modo XR' com Loader2 e texto 'Iniciando AR...'
- Viewer: timeout de 15s que limpa o loading e mostra toast de erro se não entrar
- Viewer: marca __setXrEntering(true) antes de navegar para bloquear auto-return prematuro
- XRSession: delay do auto-return aumentado de 500ms para 2000ms
- XRSession: novo flag isEnteringAR que previne navegação prematura para /viewer
- XRSession: expõe __setXrEntering via window para Viewer setar o flag
- Versão: v1.10 → v1.11

[31/05/2026 17:33:29]
This commit is contained in:
2026-05-31 17:33:29 +00:00
parent c798179560
commit 8154951fa5
3 changed files with 50 additions and 13 deletions
+28 -9
View File
@@ -218,17 +218,36 @@ const Viewer = () => {
// Removido o bloqueio para permitir carregamento de modelo na sala
const handleEnterXR = async () => {
const [enteringXR, setEnteringXR] = useState(false);
const handleEnterXR = useCallback(async () => {
if (!xrSupported) {
toast.error("WebXR não é suportado neste navegador. Use o navegador do Meta Quest 3.");
return;
}
// Entra diretamente no AR para não perder o clique do usuário!
import('@/stores/useXRStore').then(({ xrStore }) => {
xrStore.enterAR().catch(e => console.error('[Viewer] XR enterAR error:', e));
setEnteringXR(true);
// Timeout de segurança — se não entrar em 15s, cancela
const timeoutId = setTimeout(() => {
setEnteringXR(false);
toast.error("Tempo limite ao iniciar modo AR. Verifique se o Meta Quest Browser está conectado.");
}, 15000);
try {
const { xrStore } = await import('@/stores/useXRStore');
// Marca que está entrando no AR antes de navegar — bloqueia auto-return prematuro
(window as unknown as { __setXrEntering?: (v: boolean) => void }).__setXrEntering?.(true);
await xrStore.enterAR();
clearTimeout(timeoutId);
navigate("/xr");
});
};
} catch (e) {
clearTimeout(timeoutId);
setEnteringXR(false);
(window as unknown as { __setXrEntering?: (v: boolean) => void }).__setXrEntering?.(false);
console.error('[Viewer] XR enterAR error:', e);
toast.error("Falha ao iniciar modo AR. Verifique se o Meta Quest Browser está conectado.");
}
}, [xrSupported, navigate]);
const handleEnterMeeting = () => {
// Coleta o eixo habilitado de seção no Viewer
@@ -297,9 +316,9 @@ const Viewer = () => {
Reunião Virtual
</Button>
<ShareButton />
<Button className="gap-2 glow-primary h-9" disabled={!xrSupported} onClick={handleEnterXR}>
<Glasses className="h-4 w-4" />
Entrar em Modo XR
<Button className="gap-2 glow-primary h-9" disabled={!xrSupported || enteringXR} onClick={handleEnterXR}>
{enteringXR ? <Loader2 className="h-4 w-4 animate-spin" /> : <Glasses className="h-4 w-4" />}
{enteringXR ? 'Iniciando AR…' : 'Entrar em Modo XR'}
</Button>
</div>
</header>