import { api, API_BASE_URL } from './client'; export interface RawTelemetryPacket { id: string; timestamp: number; // unix seconds lat: number; lon: number; alt: number; payload: Record; raw_data: Record; } /** Derives a WebSocket URL from the configured API base URL. */ export function buildWsUrl(satelliteId: string): string { let base = API_BASE_URL; if (!base.startsWith('http')) { base = `${window.location.protocol}//${window.location.host}${base}`; } const url = new URL(base); url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'; return `${url.origin}${url.pathname}/ws/satellite/${satelliteId}/telemetry/`; } export const telemetryApi = { fetchHistory: async ( satelliteId: string, params?: { from?: number; till?: number }, ): Promise => { const res = await api.get( `/${satelliteId}/telemetry/`, { query: params }, ); return Array.isArray(res) ? res : res.results; }, };