chore: render the peer ID

This commit is contained in:
Danish Arora 2024-12-03 17:08:57 +05:30
parent 42a45f0e8d
commit 066be09ee1
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
2 changed files with 24 additions and 3 deletions

View File

@ -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">

View File

@ -102,6 +102,11 @@ class Railgun {
}
});
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);
await this.waku.waitForPeers([Protocols.Filter]);
@ -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<void>;
waku: LightNode | null;
}
}
@ -228,3 +238,5 @@ window.sendMessage = async (): Promise<void> => {
input.value = '';
}
};
window.waku = railgun.getWaku();