Fix location sharing: increase timeout, prevent auto-start cycling, graceful error handling

This commit is contained in:
Jeff Emmett 2025-12-15 15:44:34 -05:00
parent 45c4ebc602
commit d8e21b8cdf
2 changed files with 14 additions and 9 deletions

View File

@ -93,13 +93,16 @@ export default function RoomPage() {
highAccuracy: true, highAccuracy: true,
}); });
// Auto-start location sharing when connected // Auto-start location sharing when connected (only once)
const hasAutoStartedRef = useRef(false);
useEffect(() => { useEffect(() => {
if (isConnected && currentUser && !isSharing) { if (isConnected && currentUser && !hasAutoStartedRef.current) {
console.log('Auto-starting location sharing'); console.log('Auto-starting location sharing (first time)');
hasAutoStartedRef.current = true;
startSharing(); startSharing();
} }
}, [isConnected, currentUser, isSharing, startSharing]); }, [isConnected, currentUser, startSharing]);
// Track if we've centered on user's location yet // Track if we've centered on user's location yet
const hasCenteredRef = useRef(false); const hasCenteredRef = useRef(false);

View File

@ -8,9 +8,9 @@ interface UseLocationSharingOptions {
updateInterval?: number; updateInterval?: number;
/** Enable high accuracy mode (uses more battery) */ /** Enable high accuracy mode (uses more battery) */
highAccuracy?: boolean; highAccuracy?: boolean;
/** Maximum age of cached position in ms (default: 10000) */ /** Maximum age of cached position in ms (default: 30000) */
maxAge?: number; maxAge?: number;
/** Timeout for position request in ms (default: 10000) */ /** Timeout for position request in ms (default: 30000) */
timeout?: number; timeout?: number;
} }
@ -38,8 +38,8 @@ export function useLocationSharing(
onLocationUpdate, onLocationUpdate,
updateInterval = 5000, updateInterval = 5000,
highAccuracy = true, highAccuracy = true,
maxAge = 10000, maxAge = 30000,
timeout = 10000, timeout = 30000,
} = options; } = options;
const [isSharing, setIsSharing] = useState(false); const [isSharing, setIsSharing] = useState(false);
@ -92,7 +92,9 @@ export function useLocationSharing(
const handleError = useCallback((err: GeolocationPositionError) => { const handleError = useCallback((err: GeolocationPositionError) => {
setError(err); setError(err);
console.error('Geolocation error:', err.message); // Only log as warning, not error - timeouts are common indoors
console.warn('Geolocation warning:', err.message, '(code:', err.code, ')');
// Don't stop sharing on errors - keep trying
}, []); }, []);
const startSharing = useCallback(() => { const startSharing = useCallback(() => {