Skip to main content
useFlightManager provides direct control over the flight lifecycle: starting, pausing, resuming, ending, and commenting on flights. It hydrates state from GET /api/flight-manager/state and subscribes to flight:manager Socket.io events for real-time updates. For most plugins, useTrackingSession is the better starting point — it wraps useFlightManager with derived state (isTracking, isPaused, elapsedTime, phase) and recovery handling. Use useFlightManager when you need lower-level control or want to avoid the extra derived state computation.

Import

import { useFlightManager } from "@skyvexsoftware/stratos-sdk";

Signature

function useFlightManager(): UseFlightManagerReturn

type UseFlightManagerReturn = {
  currentFlight: CurrentFlight | null;
  startFlight: (plan: FlightPlan) => Promise<StartFlightResult>;
  pauseFlight: () => Promise<boolean>;
  resumeFlight: () => Promise<boolean>;
  endFlight: (
    status?: "completed" | "diverted" | "crashed" | "cancelled"
  ) => Promise<boolean>;
  addComment: (message: string) => Promise<boolean>;
  runPreflightChecks: (plan: FlightPlan) => Promise<PreflightCheckResult | null>;
};

Return value

FieldTypeDescription
currentFlightCurrentFlight | nullActive flight state, or null when no flight is in progress
startFlight(plan: FlightPlan) => Promise<StartFlightResult>Begin a new flight with the given flight plan
pauseFlight() => Promise<boolean>Pause the active flight
resumeFlight() => Promise<boolean>Resume a paused flight
endFlight(status?) => Promise<boolean>End the active flight with an optional terminal status
addComment(message: string) => Promise<boolean>Attach a pilot comment to the active flight
runPreflightChecks(plan: FlightPlan) => Promise<PreflightCheckResult | null>Validate a flight plan before starting

Types

FlightPlan

See FlightPlan for the full shape.

StartFlightResult

See StartFlightResult for the full shape.

PreflightCheckResult

See PreflightCheckResult for the full shape (includes the nested PreflightCheck per-check entries).

CurrentFlight

See CurrentFlight for the full shape.

Usage

Start a flight

import { useFlightManager } from "@skyvexsoftware/stratos-sdk";

export function StartFlightButton() {
  const { startFlight, currentFlight } = useFlightManager();

  const handleStart = async () => {
    const result = await startFlight({
      source: "manual",
      callsign: "SWR123",
      departureIcao: "YSSY",
      arrivalIcao: "YMML",
      route: ["SY", "ML"],
      aircraftIcao: "B738",
    });

    if (!result.success) {
      console.error("Failed to start flight:", result.error);
    }
  };

  return (
    <button onClick={handleStart} disabled={currentFlight !== null}>
      Start Flight
    </button>
  );
}

Run preflight checks first

const { runPreflightChecks, startFlight } = useFlightManager();

const plan: FlightPlan = { /* ... */ };

const checks = await runPreflightChecks(plan);
if (checks && !checks.passed) {
  const errors = checks.checks.filter((c) => c.severity === "error");
  console.error("Preflight failed:", errors);
  return;
}

await startFlight(plan);

End a flight

const { endFlight } = useFlightManager();

// End with a specific status
await endFlight("completed");

// Without a status — defaults to "completed" on the server
await endFlight();

Notes

  • All action methods (startFlight, pauseFlight, etc.) call REST endpoints on the local shell server. They return a boolean or result object indicating success.
  • State updates arrive via flight:manager Socket.io events — the currentFlight value updates reactively without polling.
  • runPreflightChecks returns null if the server is unreachable.