From 48039c6042166919f4f7f26c90c327f76897a9f5 Mon Sep 17 00:00:00 2001 From: status-im-auto Date: Mon, 10 Jul 2023 22:33:47 +0000 Subject: [PATCH] Updates --- light-js/index.html | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/light-js/index.html b/light-js/index.html index 02a800d..71f9892 100644 --- a/light-js/index.html +++ b/light-js/index.html @@ -20,11 +20,7 @@
- +
@@ -50,6 +46,10 @@ utf8ToBytes, bytesToUtf8, } from "https://unpkg.com/@waku/sdk@0.0.16/bundle/index.js"; + import { + enrTree, + DnsNodeDiscovery, + } from "https://unpkg.com/@waku/dns-discovery@0.0.14/bundle/index.js"; const peerIdDiv = document.getElementById("peer-id"); const remotePeerIdDiv = document.getElementById("remote-peer-id"); @@ -74,6 +74,14 @@ div.innerHTML += ""; }; + try { + await searchForPeer(statusDiv, remoteMultiAddrDiv); + } catch (e) { + console.log("Failed to find a peer", e); + remoteMultiAddrDiv.value = + "/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/8000/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm"; + } + statusDiv.innerHTML = "

Creating Waku node.

"; const node = await createLightNode(); @@ -130,6 +138,21 @@ console.log("Message sent!"); textInput.value = null; }; + + async function searchForPeer(statusNode, multiaddrNode) { + statusDiv.innerHTML = "

Discovering peer

"; + + const dnsDiscovery = await DnsNodeDiscovery.dnsOverHttp(); + const peersIterator = await dnsDiscovery.getNextPeer( + [enrTree["TEST"]], + { lightPush: 1, filter: 1 } + ); + const peerEnr = await peersIterator.next(); + const ma = peerEnr.value.multiaddrs.map((v) => v.toString())[1]; + const peerId = peerEnr.value.peerId.toString(); + + multiaddrNode.value = `${ma}/p2p/${peerId}`; + }