Skip to content

Commit

Permalink
chore: render the peer ID
Browse files Browse the repository at this point in the history
  • Loading branch information
danisharora099 committed Dec 3, 2024
1 parent 42a45f0 commit 066be09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions examples/experimental/railgun-repro/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
</style>
</head>
<body>
<div id="status">Status: Initializing...</div>
<div id="lastMessageTime">No messages received yet</div>
<div id="peerId">Peer ID: Initializing...</div>
<div id="messageContainer"></div>
<div class="input-container">
<input type="text" id="messageInput" placeholder="Enter message">
Expand Down
18 changes: 15 additions & 3 deletions examples/experimental/railgun-repro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -204,6 +209,10 @@ class Railgun {
addMessageToUI(`Sent: ${message}`);
}
}

getWaku(): LightNode | null {
return this.waku;
}
}

const railgun = new Railgun();
Expand All @@ -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<void>;
waku: LightNode | null;
}
}

Expand All @@ -227,4 +237,6 @@ window.sendMessage = async (): Promise<void> => {
await railgun.push(message);
input.value = '';
}
};
};

window.waku = railgun.getWaku();

0 comments on commit 066be09

Please sign in to comment.