diff --git a/examples/dogfooding/index.html b/examples/dogfooding/index.html index 0b100f7..4e86cc3 100644 --- a/examples/dogfooding/index.html +++ b/examples/dogfooding/index.html @@ -31,6 +31,9 @@

Waku Dogfooding App


0 +
+ + 0
@@ -45,4 +48,4 @@

Received

- + \ No newline at end of file diff --git a/examples/dogfooding/src/index.ts b/examples/dogfooding/src/index.ts index cffd04b..c6fbb01 100644 --- a/examples/dogfooding/src/index.ts +++ b/examples/dogfooding/src/index.ts @@ -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 => { 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(); -})(); +})(); \ No newline at end of file