useTrackingSession is the recommended entry point for tracking-aware plugins. It wraps the lower-level useFlightManager and adds derived state: isTracking, isPaused, elapsedTime (ticking locally every second), phase, and crash recovery handling.
Use this hook when your plugin needs to know whether a flight is active or wants to show elapsed time. Fall back to useFlightManager only when you need the raw CurrentFlight object without derived fields, or want to avoid the extra effect for the elapsed timer.
Import
Signature
Return value
| Field | Type | Description |
|---|---|---|
isTracking | boolean | true when a flight is active or paused |
isPaused | boolean | true when the active flight is paused |
currentFlight | CurrentFlight | null | Full flight state object, or null when idle |
pendingRecovery | RecoverableFlight | null | A previous flight that can be recovered, if one exists |
elapsedTime | number | Elapsed flight time in milliseconds, updating every second |
phase | FlightPhase | Current flight phase (defaults to FlightPhase.BOARDING when idle) |
startFlight | Function | Start a new flight; accepts optional start options |
pauseFlight | () => Promise<boolean> | Pause the active flight |
resumeFlight | () => Promise<boolean> | Resume a paused flight |
endFlight | (status?) => Promise<{ success, error? }> | End the active flight |
recoverFlight | () => Promise<boolean> | Recover a previously interrupted flight |
dismissRecovery | () => Promise<boolean> | Dismiss the pending recovery prompt |
isLoading | boolean | true during the initial REST hydration |
RecoverableFlight
When Stratos detects a flight was interrupted (e.g. the app crashed mid-flight), pendingRecovery is populated with a lean summary of that flight:
Usage
Basic tracking display
Start a flight with options
Recovery handling
Notes
elapsedTimeis computed locally via a 1-secondsetIntervalso it ticks smoothly between server broadcasts (which occur every ~15 seconds).- The hook uses
staleTime: Infinityand refetches on socket reconnect to catch flights started before the UI loaded. - The TanStack Query cache key is
["tracking-session", "state"]— this is the same key used across the shell and all plugins, ensuring consistent state with no duplicate requests.