Compare commits
4
Commits
feat/sdr-pins
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
49ef914fd2 | ||
|
|
c1a2721fbe | ||
|
|
000a5f11bd | ||
|
|
5dcf1b5e9c |
@@ -177,6 +177,18 @@ html:not(.dark) .border-indigo-800 { border-color: #a5b4fc !important; }
|
||||
z-index: 0;
|
||||
}
|
||||
|
||||
/* Pinned 511 camera tiles (MapView DotCameraLayer): strip Leaflet's tooltip
|
||||
* padding and let the tile's own theme colours show, so the tile is no bigger
|
||||
* than the video it holds. */
|
||||
.leaflet-tooltip.drb-cam-pin {
|
||||
padding: 0;
|
||||
border-radius: 6px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--line-strong);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
/* ── Form inputs ─────────────────────────────────────────────────────────── */
|
||||
html:not(.dark) input:not([type="submit"]):not([type="button"]):not([type="reset"]),
|
||||
html:not(.dark) select,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type HlsType from "hls.js";
|
||||
import type { Ny511Camera } from "@/lib/types";
|
||||
|
||||
// 511NY stills are served with max-age=60, so refreshing faster buys nothing.
|
||||
const SNAPSHOT_REFRESH_MS = 60_000;
|
||||
|
||||
/**
|
||||
* One 511NY camera: the live HLS stream when the camera has one (NYSDOT's
|
||||
* skyvdn hosts send Access-Control-Allow-Origin: *), otherwise its snapshot on
|
||||
* a timer. A stream that fails falls back to the snapshot rather than a black box.
|
||||
*/
|
||||
export function CameraFeed({ camera, className }: { camera: Ny511Camera; className?: string }) {
|
||||
const videoRef = useRef<HTMLVideoElement>(null);
|
||||
const [videoFailed, setVideoFailed] = useState(false);
|
||||
const [tick, setTick] = useState(() => Date.now());
|
||||
const useVideo = !!camera.video_url && !videoFailed;
|
||||
|
||||
useEffect(() => {
|
||||
if (useVideo) return;
|
||||
const id = setInterval(() => setTick(Date.now()), SNAPSHOT_REFRESH_MS);
|
||||
return () => clearInterval(id);
|
||||
}, [useVideo]);
|
||||
|
||||
useEffect(() => {
|
||||
const video = videoRef.current;
|
||||
const src = camera.video_url;
|
||||
if (!useVideo || !video || !src) return;
|
||||
let hls: HlsType | null = null;
|
||||
let cancelled = false;
|
||||
|
||||
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
||||
video.src = src; // Safari/iOS play HLS natively
|
||||
} else {
|
||||
import("hls.js")
|
||||
.then(({ default: Hls }) => {
|
||||
if (cancelled) return;
|
||||
if (!Hls.isSupported()) { setVideoFailed(true); return; }
|
||||
hls = new Hls({ maxBufferLength: 10, backBufferLength: 0 });
|
||||
hls.on(Hls.Events.ERROR, (_evt, data) => { if (data.fatal) setVideoFailed(true); });
|
||||
hls.loadSource(src);
|
||||
hls.attachMedia(video);
|
||||
})
|
||||
.catch(() => setVideoFailed(true));
|
||||
}
|
||||
return () => {
|
||||
cancelled = true;
|
||||
hls?.destroy();
|
||||
video.removeAttribute("src");
|
||||
video.load(); // stop the download, not just the playback
|
||||
};
|
||||
}, [useVideo, camera.video_url]);
|
||||
|
||||
if (useVideo) {
|
||||
return <video ref={videoRef} muted autoPlay playsInline className={className} onError={() => setVideoFailed(true)} />;
|
||||
}
|
||||
if (!camera.image_url) {
|
||||
return <div className={`${className ?? ""} flex items-center justify-center text-[10px] text-ink-muted`}>No image</div>;
|
||||
}
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={`${camera.image_url}?t=${tick}`} alt={`Camera: ${camera.name}`} className={className} />;
|
||||
}
|
||||
@@ -22,7 +22,8 @@ import { useAircraft } from "@/lib/useAircraft";
|
||||
import { useAircraftTrail } from "@/lib/useAircraftTrail";
|
||||
import { useVessels } from "@/lib/useVessels";
|
||||
import { use511 } from "@/lib/use511";
|
||||
import type { Ny511Event, Ny511FeedStatus } from "@/lib/types";
|
||||
import type { Ny511Camera, Ny511Event, Ny511FeedStatus } from "@/lib/types";
|
||||
import { CameraFeed } from "@/components/CameraFeed";
|
||||
|
||||
// ── Leaflet icon fix ──────────────────────────────────────────────────────────
|
||||
delete (L.Icon.Default.prototype as unknown as Record<string, unknown>)._getIconUrl;
|
||||
@@ -380,14 +381,28 @@ function FeedProblem({ map, label, status, fetchError }: { map: L.Map; label: st
|
||||
);
|
||||
}
|
||||
|
||||
// Pinned cameras: clicking a camera's snapshot pins its live feed as a small
|
||||
// tile anchored at the camera, so several views along one road can be read
|
||||
// against the map. Oldest pin drops past the cap.
|
||||
const MAX_CAMERA_PINS = 6;
|
||||
|
||||
function DotCameraLayer() {
|
||||
const map = useMap();
|
||||
const shown = useOverlayShown(map, OVERLAY_DOT_CAMERAS);
|
||||
const { data, error } = use511(map, "cameras", shown);
|
||||
const [pinned, setPinned] = useState<Ny511Camera[]>([]);
|
||||
const pinnedIds = useMemo(() => new Set(pinned.map((c) => c.id)), [pinned]);
|
||||
|
||||
const pin = (c: Ny511Camera) => {
|
||||
map.closePopup();
|
||||
setPinned((prev) => (prev.some((p) => p.id === c.id) ? prev : [...prev, c].slice(-MAX_CAMERA_PINS)));
|
||||
};
|
||||
const unpin = (id: string) => setPinned((prev) => prev.filter((p) => p.id !== id));
|
||||
|
||||
return (
|
||||
<>
|
||||
{shown && <FeedProblem map={map} label="DOT cameras" status={data.cameras_status} fetchError={error} />}
|
||||
{(data.cameras ?? []).map((c) => (
|
||||
{(data.cameras ?? []).filter((c) => !pinnedIds.has(c.id)).map((c) => (
|
||||
<Marker key={c.id} position={[c.lat, c.lon]} icon={cameraIcon()}>
|
||||
<Popup minWidth={260} maxWidth={340}>
|
||||
<div className="space-y-1">
|
||||
@@ -395,14 +410,32 @@ function DotCameraLayer() {
|
||||
{c.roadway && <div className="text-xs text-ink-muted">{c.roadway}{c.direction && c.direction !== "Unknown" ? ` · ${c.direction}` : ""}</div>}
|
||||
{c.image_url && (
|
||||
// Popup content mounts on open, so the timestamp busts the cache per open.
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img src={`${c.image_url}?t=${Date.now()}`} alt={`Camera: ${c.name}`} className="w-full rounded border border-line" loading="lazy" />
|
||||
<button type="button" onClick={() => pin(c)} title="Pin this camera to the map" className="block w-full p-0 border-0 bg-transparent cursor-pointer">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={`${c.image_url}?t=${Date.now()}`} alt={`Camera: ${c.name}`} className="w-full rounded border border-line" loading="lazy" />
|
||||
</button>
|
||||
)}
|
||||
<div className="text-[10px] text-ink-muted">Snapshot: 511NY / NYSDOT</div>
|
||||
<div className="text-[10px] text-ink-muted">
|
||||
Click the image to pin {c.video_url ? "the live feed" : "it"} to the map · 511NY / NYSDOT
|
||||
</div>
|
||||
</div>
|
||||
</Popup>
|
||||
</Marker>
|
||||
))}
|
||||
{/* Players only exist while the overlay is on, so hiding it stops every stream. */}
|
||||
{shown && pinned.map((c) => (
|
||||
<Marker key={`pin-${c.id}`} position={[c.lat, c.lon]} icon={cameraIcon()} zIndexOffset={300}>
|
||||
<Tooltip permanent interactive direction="top" offset={[0, -8]} opacity={1} className="drb-cam-pin">
|
||||
<div className="w-[192px]">
|
||||
<div className="flex items-center gap-1 px-1.5 h-4">
|
||||
<span className="flex-1 truncate text-[10px] leading-4 text-ink-2" title={c.name}>{c.name}</span>
|
||||
<button type="button" onClick={() => unpin(c.id)} aria-label={`Unpin ${c.name}`} className="text-ink-muted hover:text-ink text-xs leading-none px-0.5">×</button>
|
||||
</div>
|
||||
<CameraFeed camera={c} className="block w-[192px] h-[108px] object-cover bg-black rounded-b" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
</Marker>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -26,10 +26,11 @@ const selectClass =
|
||||
"bg-gray-800 border border-gray-700 rounded px-2 py-1 text-gray-200 text-xs focus:outline-none focus:border-indigo-500 disabled:opacity-60 max-w-[13rem]";
|
||||
|
||||
function DeviceSelect({
|
||||
value, devices, autoLabel, label, disabled, onChange,
|
||||
value, devices, devicesKnown, autoLabel, label, disabled, onChange,
|
||||
}: {
|
||||
value: string;
|
||||
devices: SdrDevice[];
|
||||
devicesKnown: boolean;
|
||||
autoLabel: string;
|
||||
label: string;
|
||||
disabled: boolean;
|
||||
@@ -44,7 +45,9 @@ function DeviceSelect({
|
||||
SDR {d.index + 1} · serial {d.serial ?? "unknown"}{d.duplicate_serial ? " (shared serial!)" : ""}
|
||||
</option>
|
||||
))}
|
||||
{value && !known && <option value={value}>serial {value} (not plugged in)</option>}
|
||||
{value && !known && (
|
||||
<option value={value}>serial {value} ({devicesKnown ? "not plugged in" : "not reported"})</option>
|
||||
)}
|
||||
</select>
|
||||
);
|
||||
}
|
||||
@@ -57,6 +60,7 @@ export function SdrSettings({ node, canEdit }: { node: NodeRecord; canEdit: bool
|
||||
const reported = node.secondary_sdr_running != null;
|
||||
const running = node.secondary_sdr_running ?? [];
|
||||
const devices = node.sdr_devices ?? [];
|
||||
const devicesKnown = reported && node.sdr_devices != null;
|
||||
|
||||
const [rows, setRows] = useState<Row[]>(() => rowsFrom(priority, pins));
|
||||
const [op25Pin, setOp25Pin] = useState(pins.op25 ?? "");
|
||||
@@ -114,7 +118,7 @@ export function SdrSettings({ node, canEdit }: { node: NodeRecord; canEdit: bool
|
||||
<section>
|
||||
<h2 className="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-1">SDRs</h2>
|
||||
<p className="text-xs text-gray-500 font-mono mb-3">
|
||||
{reported && node.sdr_devices != null
|
||||
{devicesKnown
|
||||
? `This node reports ${devices.length} SDR${devices.length === 1 ? "" : "s"}.`
|
||||
: "This node hasn't reported its SDRs yet."}
|
||||
</p>
|
||||
@@ -134,6 +138,7 @@ export function SdrSettings({ node, canEdit }: { node: NodeRecord; canEdit: bool
|
||||
<DeviceSelect
|
||||
value={op25Pin}
|
||||
devices={devices}
|
||||
devicesKnown={devicesKnown}
|
||||
autoLabel="Automatic (first SDR)"
|
||||
label="OP25 SDR"
|
||||
disabled={!canEdit}
|
||||
@@ -143,7 +148,7 @@ export function SdrSettings({ node, canEdit }: { node: NodeRecord; canEdit: bool
|
||||
|
||||
{rows.map((row, i) => {
|
||||
const meta = MODES.find((x) => x.mode === row.mode)!;
|
||||
const pinMissing = !!row.pin && !devices.some((d) => d.serial === row.pin);
|
||||
const pinMissing = devicesKnown && !!row.pin && !devices.some((d) => d.serial === row.pin);
|
||||
const state = !row.enabled
|
||||
? "Off"
|
||||
: dirty
|
||||
@@ -173,6 +178,7 @@ export function SdrSettings({ node, canEdit }: { node: NodeRecord; canEdit: bool
|
||||
<DeviceSelect
|
||||
value={row.pin}
|
||||
devices={devices}
|
||||
devicesKnown={devicesKnown}
|
||||
autoLabel="Any spare SDR"
|
||||
label={`${meta.name} SDR`}
|
||||
disabled={!canEdit}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
"react": "^18.3.0",
|
||||
"react-dom": "^18.3.0",
|
||||
"firebase": "^10.12.0",
|
||||
"hls.js": "^1.5.0",
|
||||
"leaflet": "^1.9.4",
|
||||
"react-leaflet": "^4.2.1",
|
||||
"react-markdown": "^9.0.1"
|
||||
|
||||
Reference in New Issue
Block a user