2026-08-25 07:51:38 +02:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useButtplugStore } from "@/lib/buttplug/store";
|
2026-08-25 21:26:18 +02:00
|
|
|
|
|
|
|
|
type IndicatorState = "scanning" | "connected" | "recording";
|
2026-08-25 07:51:38 +02:00
|
|
|
|
|
|
|
|
export function ConnectionStatus() {
|
2026-08-25 21:26:18 +02:00
|
|
|
const scanning = useButtplugStore((s) => s.scanning);
|
|
|
|
|
const recording = useButtplugStore((s) => s.recording);
|
2026-08-25 07:51:38 +02:00
|
|
|
const deviceCount = useButtplugStore((s) => Object.keys(s.devices).length);
|
|
|
|
|
|
2026-08-25 21:26:18 +02:00
|
|
|
// Priority: an active recording is the most important thing to surface,
|
|
|
|
|
// then whether toys are actually connected, then a bare scan-in-progress -
|
|
|
|
|
// this is deliberately independent of the Buttplug client's own `connected`
|
|
|
|
|
// flag, which goes true as soon as the embedded server initializes (i.e. as
|
|
|
|
|
// soon as scanning starts), not when a device is actually paired.
|
|
|
|
|
const state: IndicatorState | null = recording
|
|
|
|
|
? "recording"
|
|
|
|
|
: deviceCount > 0
|
|
|
|
|
? "connected"
|
|
|
|
|
: scanning
|
|
|
|
|
? "scanning"
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
if (!state) return null;
|
|
|
|
|
|
|
|
|
|
return <span className="bp-led bp-pulse" data-state={state} aria-hidden />;
|
2026-08-25 07:51:38 +02:00
|
|
|
}
|