2022-06-17 00:48:15 +00:00
|
|
|
<!DOCTYPE html>
|
2022-12-09 10:55:19 +00:00
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
2022-09-16 02:08:53 +00:00
|
|
|
<title>JS-Waku store script tag example</title>
|
2022-12-23 21:56:24 +00:00
|
|
|
<link rel="apple-touch-icon" href="./favicon.png" />
|
|
|
|
<link rel="manifest" href="./manifest.json" />
|
|
|
|
<link rel="icon" href="./favicon.ico" />
|
2022-12-09 10:55:19 +00:00
|
|
|
</head>
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
<body>
|
|
|
|
<div><h1>Timestamp of the latest message seen in store</h1></div>
|
|
|
|
<div id="timestamp"></div>
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
<script type="module">
|
|
|
|
import {
|
|
|
|
defaultLibp2p,
|
|
|
|
defaultPeerDiscovery,
|
2023-05-09 20:40:04 +00:00
|
|
|
} from "https://unpkg.com/@waku/create@0.0.13/bundle/index.js";
|
2022-12-09 10:55:19 +00:00
|
|
|
import {
|
|
|
|
wakuStore,
|
|
|
|
WakuNode,
|
2022-12-16 02:00:22 +00:00
|
|
|
waitForRemotePeer,
|
|
|
|
createDecoder,
|
2023-05-09 20:40:04 +00:00
|
|
|
} from "https://unpkg.com/@waku/core@0.0.17/bundle/index.js";
|
2022-08-31 03:18:24 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
/**
|
|
|
|
* This example demonstrates how to use the js-waku minified bundle
|
|
|
|
* available on unpkg.com.
|
|
|
|
*
|
|
|
|
* It is a simple script that uses Waku Store to retrieve ping relay messages
|
|
|
|
* and displays the timestamp of the most recent ping relay message.
|
|
|
|
*/
|
|
|
|
const timestampDiv = document.getElementById("timestamp");
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
timestampDiv.innerHTML = "<p>Creating waku.</p>";
|
2022-11-18 03:05:09 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
const libp2p = await defaultLibp2p(undefined, {
|
|
|
|
peerDiscovery: [defaultPeerDiscovery()],
|
|
|
|
});
|
|
|
|
const store = wakuStore();
|
|
|
|
const node = new WakuNode({}, libp2p, store);
|
2022-08-31 03:18:24 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
timestampDiv.innerHTML = "<p>Starting waku.</p>";
|
|
|
|
await node.start();
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
timestampDiv.innerHTML = "<p>Connecting to a peer.</p>";
|
|
|
|
await waitForRemotePeer(node, ["store"]);
|
2022-08-31 03:18:24 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
timestampDiv.innerHTML = "<p>Retrieving messages.</p>";
|
|
|
|
const callback = (wakuMessage) => {
|
2022-09-16 02:08:53 +00:00
|
|
|
// When `backward` direction is passed, first message is the most recent
|
|
|
|
timestampDiv.innerHTML = wakuMessage.timestamp;
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-09-16 02:08:53 +00:00
|
|
|
// When returning true, `queryHistory` stops retrieving pages
|
|
|
|
// In our case, we only want one message, hence one page.
|
|
|
|
return true;
|
2022-12-09 10:55:19 +00:00
|
|
|
};
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-12-09 10:55:19 +00:00
|
|
|
await node.store.queryOrderedCallback(
|
2022-12-16 02:00:22 +00:00
|
|
|
[createDecoder("/relay-ping/1/ping/null")],
|
2022-12-09 10:55:19 +00:00
|
|
|
callback,
|
|
|
|
{ pageDirection: "backward" }
|
|
|
|
);
|
|
|
|
</script>
|
|
|
|
</body>
|
2022-06-17 00:48:15 +00:00
|
|
|
</html>
|