Flow logout : POST /api/logout puis retour à l'écran de pairing et déconnexion du live. 401 renvoie au pairing sans boucle. Bannière de reconnexion couvrant le cas live-only et le serveur indisponible. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
30 lines
1.0 KiB
TypeScript
30 lines
1.0 KiB
TypeScript
/**
|
|
* `useLiveConnectionState` — ticket #13, lot F6. Web-only hook exposing the shared
|
|
* live WebSocket's current {@link ConnectionState} to the UI so a reconnection
|
|
* banner can be shown even when no terminal is open (the F3 xterm notice only
|
|
* covers terminal cells; live-only surfaces had no visible signal).
|
|
*
|
|
* Inert outside web transport (no client registered), so it is safe to mount
|
|
* unconditionally: it returns `null` on desktop.
|
|
*/
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { getWebLiveClient, type ConnectionState } from "@/adapters/http";
|
|
|
|
export function useLiveConnectionState(): ConnectionState | null {
|
|
const [state, setState] = useState<ConnectionState | null>(
|
|
() => getWebLiveClient()?.getConnectionState() ?? null,
|
|
);
|
|
|
|
useEffect(() => {
|
|
const client = getWebLiveClient();
|
|
if (!client) return;
|
|
// Sync in case the state changed between the initial render and this effect.
|
|
setState(client.getConnectionState());
|
|
return client.onConnectionStateChange(setState);
|
|
}, []);
|
|
|
|
return state;
|
|
}
|