chore(store-js): bump js-waku to 0.28.0

This commit is contained in:
fryorcraken.eth 2022-09-16 12:08:53 +10:00
parent 2d7989efca
commit 439e6cb708
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 44 additions and 51 deletions

View File

@ -2,26 +2,26 @@
<html lang='en'>
<head>
<meta charset='UTF-8' />
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
<meta charset='UTF-8'/>
<meta content='width=device-width, initial-scale=1.0' name='viewport'/>
<title>JS-Waku store script tag example</title>
</head>
<body>
<div><h1>Timestamp of latest message seen in store</h1></div>
<div><h1>Timestamp of the latest message seen in store</h1></div>
<div id='timestamp'></div>
<script type='module'>
import {
Protocols
} from 'https://unpkg.com/js-waku@0.27.0/bundle/index.js';
} from 'https://unpkg.com/js-waku@0.28.0/bundle/index.js';
import {
createLightNode
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js'
createWaku
} from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/create_waku.js'
import {
waitForRemotePeer
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/wait_for_remote_peer.js'
} from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/wait_for_remote_peer.js'
/**
* This example demonstrates how to use the js-waku minified bundle
@ -32,9 +32,8 @@
*/
const timestampDiv = document.getElementById('timestamp');
try {
timestampDiv.innerHTML = '<p>Creating waku.</p>';
const node = await createLightNode({ defaultBootstrap: true });
const node = await createWaku({defaultBootstrap: true});
timestampDiv.innerHTML = '<p>Starting waku.</p>';
await node.start();
@ -43,16 +42,9 @@
await waitForRemotePeer(node, [Protocols.Store]);
timestampDiv.innerHTML = '<p>Retrieving messages.</p>';
const callback = (wakuMessages) => {
// Messages are ordered with oldest first
// even with page direction `backward`
const latestFirst = wakuMessages.reverse();
const latestMessage = latestFirst[0];
if (latestMessage) {
timestampDiv.innerHTML = latestMessage.timestamp;
} else {
timestampDiv.innerHTML = '<p>No message available, go to <a href="https://js-waku.wakuconnect.dev/examples/web-chat/">web-chat</a> to send a message</p>';
}
const callback = (wakuMessage) => {
// When `backward` direction is passed, first message is the most recent
timestampDiv.innerHTML = wakuMessage.timestamp;
// When returning true, `queryHistory` stops retrieving pages
// In our case, we only want one message, hence one page.
@ -62,11 +54,11 @@
const startTime = new Date();
// Only retrieve a week of messages
startTime.setTime(Date.now() - 7 * 24 * 60 * 60 * 1000);
try {
await node.store
.queryHistory([], {
.queryOrderedCallback([],
callback,
{
pageDirection: 'backward',
pageSize: 1,
timeFilter: {
@ -75,7 +67,8 @@
}
});
} catch (e) {
timestampDiv.innerHTML = 'Error encountered: ' + e.toString();
// Known issue: https://github.com/status-im/nwaku/issues/1157
console.log(e)
}
</script>
</body>