From 066be09ee11fba01b3c6f8ed0e5966de88225104 Mon Sep 17 00:00:00 2001 From: Danish Arora Date: Tue, 3 Dec 2024 17:08:57 +0530 Subject: [PATCH] chore: render the peer ID --- examples/experimental/railgun-repro/index.html | 9 +++++++++ examples/experimental/railgun-repro/index.ts | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/examples/experimental/railgun-repro/index.html b/examples/experimental/railgun-repro/index.html index 14c0a4d..0ac4adc 100644 --- a/examples/experimental/railgun-repro/index.html +++ b/examples/experimental/railgun-repro/index.html @@ -61,11 +61,20 @@ border-radius: 4px; font-family: monospace; } + #peerId { + padding: 10px; + margin-bottom: 20px; + background-color: #e3f2fd; + border-radius: 4px; + font-family: monospace; + word-break: break-all; + }
Status: Initializing...
No messages received yet
+
Peer ID: Initializing...
diff --git a/examples/experimental/railgun-repro/index.ts b/examples/experimental/railgun-repro/index.ts index 718b78c..4df031d 100644 --- a/examples/experimental/railgun-repro/index.ts +++ b/examples/experimental/railgun-repro/index.ts @@ -100,7 +100,12 @@ class Railgun { shards: [shard], clusterId: clusterId, } - }); + }); + + const peerIdElement = document.getElementById('peerId'); + if (peerIdElement) { + peerIdElement.textContent = `Peer ID: ${this.waku.libp2p.peerId.toString()}`; + } updateStatus('Connecting to peer...'); await this.waku.dial(railgunMa); @@ -204,6 +209,10 @@ class Railgun { addMessageToUI(`Sent: ${message}`); } } + + getWaku(): LightNode | null { + return this.waku; + } } const railgun = new Railgun(); @@ -213,10 +222,11 @@ export default railgun; await railgun.start(); await railgun.subscribe(); -// Add global function for sending messages +// Add global functions and objects declare global { interface Window { sendMessage: () => Promise; + waku: LightNode | null; } } @@ -227,4 +237,6 @@ window.sendMessage = async (): Promise => { await railgun.push(message); input.value = ''; } -}; \ No newline at end of file +}; + +window.waku = railgun.getWaku(); \ No newline at end of file