mirror of https://github.com/waku-org/waku-lab.git
chore: add filter counter (#87)
This commit is contained in:
parent
2a8424e04c
commit
50d3cac3a8
|
@ -31,6 +31,9 @@
|
||||||
<br />
|
<br />
|
||||||
<label for="numSent">Messages Sent:</label>
|
<label for="numSent">Messages Sent:</label>
|
||||||
<span id="numSent">0</span>
|
<span id="numSent">0</span>
|
||||||
|
<br />
|
||||||
|
<label for="numReceived">Messages Received:</label>
|
||||||
|
<span id="numReceived">0</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
|
@ -45,4 +48,4 @@
|
||||||
</div>
|
</div>
|
||||||
<script src="./index.js"></script>
|
<script src="./index.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -29,6 +29,7 @@ const ProtoSequencedMessage = new Type("SequencedMessage")
|
||||||
|
|
||||||
const sequenceCompletedEvent = new CustomEvent("sequenceCompleted");
|
const sequenceCompletedEvent = new CustomEvent("sequenceCompleted");
|
||||||
const messageSentEvent = new CustomEvent("messageSent");
|
const messageSentEvent = new CustomEvent("messageSent");
|
||||||
|
const messageReceivedEvent = new CustomEvent("messageReceived");
|
||||||
|
|
||||||
const wakuNode = async (): Promise<LightNode> => {
|
const wakuNode = async (): Promise<LightNode> => {
|
||||||
return await createLightNode({
|
return await createLightNode({
|
||||||
|
@ -165,6 +166,8 @@ export async function app(telemetryClient: TelemetryClient) {
|
||||||
messageElement.textContent = `Message: ${sequencedMessage.hash} ${sequencedMessage.index} of ${sequencedMessage.total}`;
|
messageElement.textContent = `Message: ${sequencedMessage.hash} ${sequencedMessage.index} of ${sequencedMessage.total}`;
|
||||||
messagesReceived.appendChild(messageElement);
|
messagesReceived.appendChild(messageElement);
|
||||||
messagesReceived.appendChild(document.createElement("br"));
|
messagesReceived.appendChild(document.createElement("br"));
|
||||||
|
|
||||||
|
document.dispatchEvent(messageReceivedEvent);
|
||||||
};
|
};
|
||||||
|
|
||||||
await node.filter.subscribe(decoder, subscriptionCallback);
|
await node.filter.subscribe(decoder, subscriptionCallback);
|
||||||
|
@ -199,6 +202,15 @@ export async function app(telemetryClient: TelemetryClient) {
|
||||||
sentMessagesCounter.textContent = sentMessagesCount.toString();
|
sentMessagesCounter.textContent = sentMessagesCount.toString();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let receivedMessagesCount = 0;
|
||||||
|
const receivedMessagesCounter = document.getElementById(
|
||||||
|
"numReceived"
|
||||||
|
) as HTMLSpanElement;
|
||||||
|
document.addEventListener("messageReceived", () => {
|
||||||
|
receivedMessagesCount++;
|
||||||
|
receivedMessagesCounter.textContent = receivedMessagesCount.toString();
|
||||||
|
});
|
||||||
|
|
||||||
function startSequence() {
|
function startSequence() {
|
||||||
const numMessages = Math.floor(Math.random() * 16) + 5;
|
const numMessages = Math.floor(Math.random() * 16) + 5;
|
||||||
const messagePeriod = Math.floor(Math.random() * 2001) + 5000;
|
const messagePeriod = Math.floor(Math.random() * 2001) + 5000;
|
||||||
|
@ -207,4 +219,4 @@ export async function app(telemetryClient: TelemetryClient) {
|
||||||
|
|
||||||
document.addEventListener(sequenceCompletedEvent.type, () => startSequence());
|
document.addEventListener(sequenceCompletedEvent.type, () => startSequence());
|
||||||
startSequence();
|
startSequence();
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue