chore(store-js): bump js-waku to 0.28.0
This commit is contained in:
parent
2d7989efca
commit
439e6cb708
|
@ -2,39 +2,38 @@
|
||||||
<html lang='en'>
|
<html lang='en'>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset='UTF-8' />
|
<meta charset='UTF-8'/>
|
||||||
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
|
<meta content='width=device-width, initial-scale=1.0' name='viewport'/>
|
||||||
<title>JS-Waku store script tag example</title>
|
<title>JS-Waku store script tag example</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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>
|
<div id='timestamp'></div>
|
||||||
|
|
||||||
<script type='module'>
|
<script type='module'>
|
||||||
import {
|
import {
|
||||||
Protocols
|
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 {
|
import {
|
||||||
createLightNode
|
createWaku
|
||||||
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js'
|
} from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/create_waku.js'
|
||||||
import {
|
import {
|
||||||
waitForRemotePeer
|
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
|
* This example demonstrates how to use the js-waku minified bundle
|
||||||
* available on unpkg.com.
|
* available on unpkg.com.
|
||||||
*
|
*
|
||||||
* It is a simple script that uses Waku Store to retrieve ping relay messages
|
* 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.
|
* and displays the timestamp of the most recent ping relay message.
|
||||||
*/
|
*/
|
||||||
const timestampDiv = document.getElementById('timestamp');
|
const timestampDiv = document.getElementById('timestamp');
|
||||||
|
|
||||||
try {
|
|
||||||
timestampDiv.innerHTML = '<p>Creating waku.</p>';
|
timestampDiv.innerHTML = '<p>Creating waku.</p>';
|
||||||
const node = await createLightNode({ defaultBootstrap: true });
|
const node = await createWaku({defaultBootstrap: true});
|
||||||
|
|
||||||
timestampDiv.innerHTML = '<p>Starting waku.</p>';
|
timestampDiv.innerHTML = '<p>Starting waku.</p>';
|
||||||
await node.start();
|
await node.start();
|
||||||
|
@ -43,40 +42,34 @@
|
||||||
await waitForRemotePeer(node, [Protocols.Store]);
|
await waitForRemotePeer(node, [Protocols.Store]);
|
||||||
|
|
||||||
timestampDiv.innerHTML = '<p>Retrieving messages.</p>';
|
timestampDiv.innerHTML = '<p>Retrieving messages.</p>';
|
||||||
const callback = (wakuMessages) => {
|
const callback = (wakuMessage) => {
|
||||||
// Messages are ordered with oldest first
|
// When `backward` direction is passed, first message is the most recent
|
||||||
// even with page direction `backward`
|
timestampDiv.innerHTML = wakuMessage.timestamp;
|
||||||
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>';
|
|
||||||
}
|
|
||||||
|
|
||||||
// When returning true, `queryHistory` stops retrieving pages
|
// When returning true, `queryHistory` stops retrieving pages
|
||||||
// In our case, we only want one message, hence one page.
|
// In our case, we only want one message, hence one page.
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const startTime = new Date();
|
const startTime = new Date();
|
||||||
// Only retrieve a week of messages
|
// Only retrieve a week of messages
|
||||||
startTime.setTime(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
startTime.setTime(Date.now() - 7 * 24 * 60 * 60 * 1000);
|
||||||
|
try {
|
||||||
|
await node.store
|
||||||
await node.store
|
.queryOrderedCallback([],
|
||||||
.queryHistory([], {
|
callback,
|
||||||
callback,
|
{
|
||||||
pageDirection: 'backward',
|
pageDirection: 'backward',
|
||||||
pageSize: 1,
|
pageSize: 1,
|
||||||
timeFilter: {
|
timeFilter: {
|
||||||
startTime,
|
startTime,
|
||||||
endTime: new Date()
|
endTime: new Date()
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
timestampDiv.innerHTML = 'Error encountered: ' + e.toString();
|
// Known issue: https://github.com/status-im/nwaku/issues/1157
|
||||||
}
|
console.log(e)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue