From d2b7db18afbeb4e66ed3d6b0084c7110c9d3a9df Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Wed, 4 Jun 2025 20:19:29 -0700 Subject: [PATCH] Show socket status on space dashboard --- src/app/state.ts | 23 ++++++++++++++-- src/lib/components/StatusIndicator.svelte | 15 +++++++++++ src/routes/spaces/[relay]/+page.svelte | 33 ++++++++++++++++++++--- 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 src/lib/components/StatusIndicator.svelte diff --git a/src/app/state.ts b/src/app/state.ts index 2567d3c..c33aa95 100644 --- a/src/app/state.ts +++ b/src/app/state.ts @@ -2,6 +2,8 @@ import twColors from "tailwindcss/colors" import {get, derived} from "svelte/store" import * as nip19 from "nostr-tools/nip19" import { + on, + call, remove, uniqBy, sortBy, @@ -19,8 +21,9 @@ import { groupBy, always, } from "@welshman/lib" -import {load} from "@welshman/net" -import {collection} from "@welshman/store" +import type {Socket} from "@welshman/net" +import {Pool, load, AuthStateEvent, SocketEvent} from "@welshman/net" +import {collection, custom} from "@welshman/store" import { getIdFilters, WRAP, @@ -682,3 +685,19 @@ export const displayReaction = (content: string) => { if (content === "-") return "👎" return content } + +export const deriveSocket = (url: string) => + custom(set => { + const pool = Pool.get() + const socket = pool.get(url) + + set(socket) + + const subs = [ + on(socket, SocketEvent.Error, () => set(socket)), + on(socket, SocketEvent.Status, () => set(socket)), + on(socket.auth, AuthStateEvent.Status, () => set(socket)), + ] + + return () => subs.forEach(call) + }) diff --git a/src/lib/components/StatusIndicator.svelte b/src/lib/components/StatusIndicator.svelte new file mode 100644 index 0000000..7dec323 --- /dev/null +++ b/src/lib/components/StatusIndicator.svelte @@ -0,0 +1,15 @@ + + +
+
+ {@render children()} +
diff --git a/src/routes/spaces/[relay]/+page.svelte b/src/routes/spaces/[relay]/+page.svelte index 4f0c383..692cd65 100644 --- a/src/routes/spaces/[relay]/+page.svelte +++ b/src/routes/spaces/[relay]/+page.svelte @@ -3,12 +3,14 @@ import type {TrustedEvent} from "@welshman/util" import {displayRelayUrl} from "@welshman/util" import {deriveRelay} from "@welshman/app" + import {AuthStatus, SocketStatus} from "@welshman/net" import {fade} from "@lib/transition" import Icon from "@lib/components/Icon.svelte" import Link from "@lib/components/Link.svelte" import Button from "@lib/components/Button.svelte" import PageBar from "@lib/components/PageBar.svelte" import PageContent from "@lib/components/PageContent.svelte" + import StatusIndicator from "@lib/components/StatusIndicator.svelte" import MenuSpaceButton from "@app/components/MenuSpaceButton.svelte" import ProfileFeed from "@app/components/ProfileFeed.svelte" import ChannelName from "@app/components/ChannelName.svelte" @@ -24,6 +26,7 @@ deriveUserRooms, deriveOtherRooms, userRoomsByUrl, + deriveSocket, } from "@app/state" import {makeChatPath, makeThreadPath, makeCalendarPath, makeRoomPath} from "@app/routes" import {notifications} from "@app/notifications" @@ -31,6 +34,7 @@ const url = decodeRelay($page.params.relay) const relay = deriveRelay(url) + const socket = deriveSocket(url) const userRooms = deriveUserRooms(url) const otherRooms = deriveOtherRooms(url) const threadsPath = makeThreadPath(url) @@ -236,10 +240,31 @@ Relay Status
-
-
- Connected -
+ {#if $socket.status === SocketStatus.Open} + {#if $socket.auth.status === AuthStatus.None} + Connected + {:else if $socket.auth.status === AuthStatus.Requested} + Authenticating + {:else if $socket.auth.status === AuthStatus.PendingSignature} + Authenticating + {:else if $socket.auth.status === AuthStatus.DeniedSignature} + Failed to Authenticate + {:else if $socket.auth.status === AuthStatus.PendingResponse} + Authenticating + {:else if $socket.auth.status === AuthStatus.Forbidden} + Access Denied + {:else if $socket.auth.status === AuthStatus.Ok} + Connected + {/if} + {:else if $socket.status === SocketStatus.Opening} + Connecting + {:else if $socket.status === SocketStatus.Closing} + Not Connected + {:else if $socket.status === SocketStatus.Closed} + Not Connected + {:else if $socket.status === SocketStatus.Error} + Failed to Connect + {/if} {#if $relay?.profile} {@const {software, version, supported_nips, limitation} = $relay.profile}