diff --git a/src/components/ShareButton.tsx b/src/components/ShareButton.tsx index bea6fe3..5a5d648 100644 --- a/src/components/ShareButton.tsx +++ b/src/components/ShareButton.tsx @@ -70,9 +70,27 @@ export function ShareButton({ variant = 'default', autoOpen, onHandleChange, onV streamRef.current = null; setHandle(null); setViewerCount(0); + onHandleChange?.(null); + onViewerCountChange?.(0); toast.info('Transmissão encerrada'); }; + // Auto-open dialog when requested by parent (in-XR HUD) + useEffect(() => { + if (autoOpen) setOpen(true); + }, [autoOpen]); + + // Expose start/stop via window so XR HUD can trigger from inside the scene + useEffect(() => { + (window as unknown as { __trackSteelStartLive?: () => void; __trackSteelStopLive?: () => void }).__trackSteelStartLive = () => { if (!handle) start(); }; + (window as unknown as { __trackSteelStopLive?: () => void }).__trackSteelStopLive = () => { if (handle) stop(); }; + return () => { + delete (window as unknown as { __trackSteelStartLive?: () => void }).__trackSteelStartLive; + delete (window as unknown as { __trackSteelStopLive?: () => void }).__trackSteelStopLive; + }; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [handle]); + // Cleanup on unmount useEffect(() => { return () => {