From 7d7bee8e77e49a00a882f188a30112ebe742c49c Mon Sep 17 00:00:00 2001 From: padreug Date: Sun, 10 Aug 2025 11:48:33 +0200 Subject: [PATCH] feat: Integrate Relay Hub for centralized Nostr connection management - Introduce a new composable, useRelayHub, to manage all Nostr WebSocket connections, enhancing connection stability and performance. - Update existing components and composables to utilize the Relay Hub for connecting, publishing events, and subscribing to updates, streamlining the overall architecture. - Add a RelayHubStatus component to display connection status and health metrics, improving user feedback on the connection state. - Implement a RelayHubDemo page to showcase the functionality of the Relay Hub, including connection tests and subscription management. - Ensure proper error handling and logging throughout the integration process to facilitate debugging and user experience. --- src/App.vue | 12 + src/components/RelayHubStatus.vue | 257 ++++++++++ src/components/layout/Navbar.vue | 10 + src/composables/useMarket.ts | 787 +++++++++++++----------------- src/composables/useNostr.ts | 3 +- src/composables/useNostrChat.ts | 463 +++++++----------- src/composables/useNostrFeed.ts | 84 ++-- src/composables/useRelayHub.ts | 267 ++++++++++ src/composables/useSocial.ts | 49 +- src/lib/nostr/client.ts | 184 ++----- src/lib/nostr/relayHub.ts | 480 ++++++++++++++++++ src/pages/RelayHubDemo.vue | 271 ++++++++++ src/router/index.ts | 9 + src/stores/nostr.ts | 61 ++- 14 files changed, 1982 insertions(+), 955 deletions(-) create mode 100644 src/components/RelayHubStatus.vue create mode 100644 src/composables/useRelayHub.ts create mode 100644 src/lib/nostr/relayHub.ts create mode 100644 src/pages/RelayHubDemo.vue diff --git a/src/App.vue b/src/App.vue index cd68390..2019bcf 100644 --- a/src/App.vue +++ b/src/App.vue @@ -9,6 +9,7 @@ import 'vue-sonner/style.css' import { auth } from '@/composables/useAuth' import { useMarketPreloader } from '@/composables/useMarketPreloader' import { nostrChat } from '@/composables/useNostrChat' +import { useRelayHub } from '@/composables/useRelayHub' import { toast } from 'vue-sonner' const route = useRoute() @@ -17,6 +18,9 @@ const showLoginDialog = ref(false) // Initialize preloader const marketPreloader = useMarketPreloader() +// Initialize relay hub +const relayHub = useRelayHub() + // Hide navbar on login page const showNavbar = computed(() => { return route.path !== '/login' @@ -50,6 +54,14 @@ onMounted(async () => { } catch (error) { console.error('Failed to initialize authentication:', error) } + + // Initialize relay hub + try { + await relayHub.initialize() + console.log('Relay hub initialized successfully') + } catch (error) { + console.error('Failed to initialize relay hub:', error) + } }) // Watch for authentication changes and trigger preloading diff --git a/src/components/RelayHubStatus.vue b/src/components/RelayHubStatus.vue new file mode 100644 index 0000000..d9a5126 --- /dev/null +++ b/src/components/RelayHubStatus.vue @@ -0,0 +1,257 @@ + + + + + diff --git a/src/components/layout/Navbar.vue b/src/components/layout/Navbar.vue index 1232946..00e5908 100644 --- a/src/components/layout/Navbar.vue +++ b/src/components/layout/Navbar.vue @@ -33,6 +33,7 @@ const navigation = computed(() => [ { name: t('nav.events'), href: '/events' }, { name: t('nav.market'), href: '/market' }, { name: t('nav.chat'), href: '/chat' }, + { name: 'Relay Hub', href: '/relay-hub-demo' }, ]) // Compute total wallet balance @@ -149,6 +150,10 @@ const handleLogout = async () => { My Tickets + + + Relay Hub Demo + @@ -230,6 +235,11 @@ const handleLogout = async () => { My Tickets +