2022-06-17 00:48:15 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang='en'>
|
|
|
|
|
|
|
|
<head>
|
2022-09-16 02:08:53 +00:00
|
|
|
<meta charset='UTF-8'/>
|
|
|
|
<meta content='width=device-width, initial-scale=1.0' name='viewport'/>
|
|
|
|
<title>JS-Waku store script tag example</title>
|
2022-06-17 00:48:15 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
2022-09-16 02:08:53 +00:00
|
|
|
<div><h1>Timestamp of the latest message seen in store</h1></div>
|
2022-06-17 00:48:15 +00:00
|
|
|
<div id='timestamp'></div>
|
|
|
|
|
2022-08-31 03:18:24 +00:00
|
|
|
<script type='module'>
|
2022-11-18 03:00:46 +00:00
|
|
|
import {createLightNode} from 'https://unpkg.com/@waku/create@0.0.4/bundle/index.js'
|
|
|
|
import {waitForRemotePeer} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/wait_for_remote_peer.js'
|
|
|
|
import {DecoderV0} from 'https://unpkg.com/@waku/core@0.0.6/bundle/lib/waku_message/version_0.js'
|
2022-08-31 03:18:24 +00:00
|
|
|
|
2022-09-16 02:08:53 +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-08-31 03:18:24 +00:00
|
|
|
timestampDiv.innerHTML = '<p>Creating waku.</p>';
|
2022-10-28 00:30:05 +00:00
|
|
|
const node = await createLightNode({defaultBootstrap: true});
|
2022-08-31 03:18:24 +00:00
|
|
|
|
2022-06-17 00:48:15 +00:00
|
|
|
timestampDiv.innerHTML = '<p>Starting waku.</p>';
|
2022-08-31 03:18:24 +00:00
|
|
|
await node.start();
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-08-31 03:18:24 +00:00
|
|
|
timestampDiv.innerHTML = '<p>Connecting to a peer.</p>';
|
2022-11-18 03:00:46 +00:00
|
|
|
await waitForRemotePeer(node, ["store"]);
|
2022-08-31 03:18:24 +00:00
|
|
|
|
|
|
|
timestampDiv.innerHTML = '<p>Retrieving messages.</p>';
|
2022-09-16 02:08:53 +00:00
|
|
|
const callback = (wakuMessage) => {
|
|
|
|
// 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-08-31 03:18:24 +00:00
|
|
|
};
|
2022-06-17 00:48:15 +00:00
|
|
|
|
2022-10-28 00:30:05 +00:00
|
|
|
await node.store
|
|
|
|
.queryOrderedCallback([new DecoderV0("/relay-ping/1/ping/null")],
|
|
|
|
callback,
|
|
|
|
{pageDirection: 'backward'});
|
2022-06-17 00:48:15 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
|
|
|
|
</html>
|