chore: add filter counter (#87)

This commit is contained in:
Sasha 2024-09-12 02:08:58 +02:00 committed by GitHub
parent 2a8424e04c
commit 50d3cac3a8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 2 deletions

View File

@ -31,6 +31,9 @@
<br />
<label for="numSent">Messages Sent:</label>
<span id="numSent">0</span>
<br />
<label for="numReceived">Messages Received:</label>
<span id="numReceived">0</span>
</div>
</div>
<div id="container">
@ -45,4 +48,4 @@
</div>
<script src="./index.js"></script>
</body>
</html>
</html>

View File

@ -29,6 +29,7 @@ const ProtoSequencedMessage = new Type("SequencedMessage")
const sequenceCompletedEvent = new CustomEvent("sequenceCompleted");
const messageSentEvent = new CustomEvent("messageSent");
const messageReceivedEvent = new CustomEvent("messageReceived");
const wakuNode = async (): Promise<LightNode> => {
return await createLightNode({
@ -165,6 +166,8 @@ export async function app(telemetryClient: TelemetryClient) {
messageElement.textContent = `Message: ${sequencedMessage.hash} ${sequencedMessage.index} of ${sequencedMessage.total}`;
messagesReceived.appendChild(messageElement);
messagesReceived.appendChild(document.createElement("br"));
document.dispatchEvent(messageReceivedEvent);
};
await node.filter.subscribe(decoder, subscriptionCallback);
@ -199,6 +202,15 @@ export async function app(telemetryClient: TelemetryClient) {
sentMessagesCounter.textContent = sentMessagesCount.toString();
});
let receivedMessagesCount = 0;
const receivedMessagesCounter = document.getElementById(
"numReceived"
) as HTMLSpanElement;
document.addEventListener("messageReceived", () => {
receivedMessagesCount++;
receivedMessagesCounter.textContent = receivedMessagesCount.toString();
});
function startSequence() {
const numMessages = Math.floor(Math.random() * 16) + 5;
const messagePeriod = Math.floor(Math.random() * 2001) + 5000;
@ -207,4 +219,4 @@ export async function app(telemetryClient: TelemetryClient) {
document.addEventListener(sequenceCompletedEvent.type, () => startSequence());
startSequence();
})();
})();