mirror of
https://github.com/waku-org/js-waku-lab.git
synced 2025-01-12 10:04:07 +00:00
chore: render the peer ID
This commit is contained in:
parent
42a45f0e8d
commit
066be09ee1
@ -61,11 +61,20 @@
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
font-family: monospace;
|
font-family: monospace;
|
||||||
}
|
}
|
||||||
|
#peerId {
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
background-color: #e3f2fd;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-family: monospace;
|
||||||
|
word-break: break-all;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="status">Status: Initializing...</div>
|
<div id="status">Status: Initializing...</div>
|
||||||
<div id="lastMessageTime">No messages received yet</div>
|
<div id="lastMessageTime">No messages received yet</div>
|
||||||
|
<div id="peerId">Peer ID: Initializing...</div>
|
||||||
<div id="messageContainer"></div>
|
<div id="messageContainer"></div>
|
||||||
<div class="input-container">
|
<div class="input-container">
|
||||||
<input type="text" id="messageInput" placeholder="Enter message">
|
<input type="text" id="messageInput" placeholder="Enter message">
|
||||||
|
@ -100,7 +100,12 @@ class Railgun {
|
|||||||
shards: [shard],
|
shards: [shard],
|
||||||
clusterId: clusterId,
|
clusterId: clusterId,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const peerIdElement = document.getElementById('peerId');
|
||||||
|
if (peerIdElement) {
|
||||||
|
peerIdElement.textContent = `Peer ID: ${this.waku.libp2p.peerId.toString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
updateStatus('Connecting to peer...');
|
updateStatus('Connecting to peer...');
|
||||||
await this.waku.dial(railgunMa);
|
await this.waku.dial(railgunMa);
|
||||||
@ -204,6 +209,10 @@ class Railgun {
|
|||||||
addMessageToUI(`Sent: ${message}`);
|
addMessageToUI(`Sent: ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getWaku(): LightNode | null {
|
||||||
|
return this.waku;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const railgun = new Railgun();
|
const railgun = new Railgun();
|
||||||
@ -213,10 +222,11 @@ export default railgun;
|
|||||||
await railgun.start();
|
await railgun.start();
|
||||||
await railgun.subscribe();
|
await railgun.subscribe();
|
||||||
|
|
||||||
// Add global function for sending messages
|
// Add global functions and objects
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
sendMessage: () => Promise<void>;
|
sendMessage: () => Promise<void>;
|
||||||
|
waku: LightNode | null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,4 +237,6 @@ window.sendMessage = async (): Promise<void> => {
|
|||||||
await railgun.push(message);
|
await railgun.push(message);
|
||||||
input.value = '';
|
input.value = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.waku = railgun.getWaku();
|
Loading…
x
Reference in New Issue
Block a user