mirror of
https://github.com/ruvnet/RuView
synced 2026-06-27 13:13:21 +00:00
fdc7142dfa
- Added IosRssiService to handle synthetic RSSI data for iOS. - Created WebRssiService to simulate RSSI scanning on the web. - Defined shared types for WifiNetwork and RssiService in rssi.service.ts. - Introduced simulation service to generate synthetic sensing data. - Implemented WebSocket service for real-time data handling with reconnection logic. - Established Zustand stores for managing application state related to MAT and pose data. - Developed theme context and utility functions for consistent styling and formatting. - Added type definitions for various application entities including API responses and sensing data. - Created utility functions for color mapping and URL validation. - Configured TypeScript settings for the mobile application.
53 lines
1.0 KiB
TypeScript
53 lines
1.0 KiB
TypeScript
import { useEffect, useState } from 'react';
|
|
import { apiService } from '@/services/api.service';
|
|
|
|
interface ServerReachability {
|
|
reachable: boolean;
|
|
latencyMs: number | null;
|
|
}
|
|
|
|
const POLL_MS = 10000;
|
|
|
|
export function useServerReachability(): ServerReachability {
|
|
const [state, setState] = useState<ServerReachability>({
|
|
reachable: false,
|
|
latencyMs: null,
|
|
});
|
|
|
|
useEffect(() => {
|
|
let active = true;
|
|
|
|
const check = async () => {
|
|
const started = Date.now();
|
|
try {
|
|
await apiService.getStatus();
|
|
if (!active) {
|
|
return;
|
|
}
|
|
setState({
|
|
reachable: true,
|
|
latencyMs: Date.now() - started,
|
|
});
|
|
} catch {
|
|
if (!active) {
|
|
return;
|
|
}
|
|
setState({
|
|
reachable: false,
|
|
latencyMs: null,
|
|
});
|
|
}
|
|
};
|
|
|
|
void check();
|
|
const timer = setInterval(check, POLL_MS);
|
|
|
|
return () => {
|
|
active = false;
|
|
clearInterval(timer);
|
|
};
|
|
}, []);
|
|
|
|
return state;
|
|
}
|