({ enabled = process.env.NODE_ENV !== "production", className }: Props)
| 13 | }; |
| 14 | |
| 15 | export function SocketStatusDebug({ enabled = process.env.NODE_ENV !== "production", className }: Props) { |
| 16 | const [status, setStatus] = useState<WebSocketStatusSnapshot>(() => getWebSocketStatusSnapshot()); |
| 17 | |
| 18 | useEffect(() => { |
| 19 | if (!enabled) return; |
| 20 | return subscribeWebSocketStatus(setStatus); |
| 21 | }, [enabled]); |
| 22 | |
| 23 | if (!enabled) return null; |
| 24 | |
| 25 | const badge = |
| 26 | status.state === "connected" |
| 27 | ? "bg-emerald-600" |
| 28 | : status.state === "connecting" |
| 29 | ? "bg-amber-600" |
| 30 | : status.state === "error" |
| 31 | ? "bg-red-600" |
| 32 | : "bg-slate-600"; |
| 33 | |
| 34 | return ( |
| 35 | <div |
| 36 | className={[ |
| 37 | "fixed bottom-3 right-3 z-9999 w-[340px] rounded-md border border-white/10 bg-black/70 backdrop-blur px-3 py-2 text-xs text-white", |
| 38 | className, |
| 39 | ].join(" ")} |
| 40 | > |
| 41 | <div className="flex items-center justify-between gap-2"> |
| 42 | <div className="font-semibold">Socket</div> |
| 43 | <div className="flex items-center gap-2"> |
| 44 | <span className={`inline-block h-2 w-2 rounded-full ${badge}`} /> |
| 45 | <span className="uppercase tracking-wide">{status.state}</span> |
| 46 | </div> |
| 47 | </div> |
| 48 | |
| 49 | <div className="mt-2 grid grid-cols-2 gap-x-3 gap-y-1 text-white/80"> |
| 50 | <div className="text-white/50">connected</div> |
| 51 | <div>{String(status.connected)}</div> |
| 52 | |
| 53 | <div className="text-white/50">socketId</div> |
| 54 | <div className="truncate" title={status.socketId ?? ""}> |
| 55 | {status.socketId ?? "-"} |
| 56 | </div> |
| 57 | |
| 58 | <div className="text-white/50">transport</div> |
| 59 | <div>{status.transport ?? "-"}</div> |
| 60 | |
| 61 | <div className="text-white/50">reconnect</div> |
| 62 | <div> |
| 63 | {status.reconnectAttempts}/{status.maxReconnectAttempts} |
| 64 | </div> |
| 65 | |
| 66 | <div className="text-white/50">lastError</div> |
| 67 | <div className="truncate" title={status.lastError ?? ""}> |
| 68 | {status.lastError ?? "-"} |
| 69 | </div> |
| 70 | </div> |
| 71 | </div> |
| 72 | ); |
nothing calls this directly
no test coverage detected