diff --git a/packages/app/src/Element/Relay.tsx b/packages/app/src/Element/Relay.tsx index a96b88f..ff69c01 100644 --- a/packages/app/src/Element/Relay.tsx +++ b/packages/app/src/Element/Relay.tsx @@ -11,6 +11,7 @@ import { faWifi, faPlugCircleXmark, faGear, + faWarning, } from "@fortawesome/free-solid-svg-icons"; import { RelaySettings } from "@snort/nostr"; @@ -86,7 +87,7 @@ export default function Relay(props: RelayProps) {
- {" "} + {latency > 2000 ? formatMessage(messages.Seconds, { n: (latency / 1000).toFixed(0), @@ -95,7 +96,9 @@ export default function Relay(props: RelayProps) { n: latency.toLocaleString(), })}   - {state?.disconnects} + {state?.disconnects} + + {state?.pendingRequests?.length}
navigate(state?.id ?? "")}> diff --git a/packages/app/src/Pages/settings/RelayInfo.tsx b/packages/app/src/Pages/settings/RelayInfo.tsx index e2e8f46..f3f8783 100644 --- a/packages/app/src/Pages/settings/RelayInfo.tsx +++ b/packages/app/src/Pages/settings/RelayInfo.tsx @@ -15,7 +15,6 @@ const RelayInfo = () => { const dispatch = useDispatch(); const conn = Array.from(System.Sockets.values()).find(a => a.Id === params.id); - console.debug(conn); const stats = useRelayState(conn?.Address ?? ""); return ( @@ -75,11 +74,7 @@ const RelayInfo = () => {
{stats.info.supported_nips.map(a => ( - + NIP-{a.toString().padStart(2, "0")} ))} @@ -90,7 +85,21 @@ const RelayInfo = () => {
- TBD + {stats?.activeRequests.map(a => ( + + {a} + + ))} +
+

+ +

+
+ {stats?.pendingRequests.map(a => ( + + {a} + + ))}
; + activeRequests: Array; id: string; }; @@ -297,6 +299,7 @@ export class Connection { this.ActiveRequests.add(cmd[1]); this.#SendJson(cmd); } + this.#UpdateState(); } CloseReq(id: string) { @@ -305,6 +308,7 @@ export class Connection { this.OnEose?.(id); this.#SendQueuedRequests(); } + this.#UpdateState(); } #SendQueuedRequests() { @@ -329,6 +333,7 @@ export class Connection { this.ActiveRequests.clear(); this.PendingRequests = []; this.PendingRaw = []; + this.#UpdateState(); } #UpdateState() { @@ -343,6 +348,8 @@ export class Connection { this.CurrentState.disconnects = this.Stats.Disconnects; this.CurrentState.info = this.Info; this.CurrentState.id = this.Id; + this.CurrentState.pendingRequests = [...this.PendingRequests.map(a => a[1])]; + this.CurrentState.activeRequests = [...this.ActiveRequests]; this.Stats.Latency = this.Stats.Latency.slice(-20); // trim this.HasStateChange = true; this.#NotifyState(); diff --git a/packages/nostr/src/legacy/ConnectionStats.ts b/packages/nostr/src/legacy/ConnectionStats.ts index 8f06c81..d1248f2 100644 --- a/packages/nostr/src/legacy/ConnectionStats.ts +++ b/packages/nostr/src/legacy/ConnectionStats.ts @@ -5,39 +5,30 @@ export class ConnectionStats { /** * Last n records of how long between REQ->EOSE */ - Latency: number[]; + Latency: number[] = []; /** * Total number of REQ's sent on this connection */ - Subs: number; + Subs: number = 0; /** * Count of REQ which took too long and where abandoned */ - SubsTimeout: number; + SubsTimeout: number = 0; /** * Total number of EVENT messages received */ - EventsReceived: number; + EventsReceived: number = 0; /** * Total number of EVENT messages sent */ - EventsSent: number; + EventsSent: number = 0; /** * Total number of times this connection was lost */ - Disconnects: number; - - constructor() { - this.Latency = []; - this.Subs = 0; - this.SubsTimeout = 0; - this.EventsReceived = 0; - this.EventsSent = 0; - this.Disconnects = 0; - } + Disconnects: number = 0; }