build(store-js): bump js-waku to next

This commit is contained in:
fryorcraken.eth 2022-08-31 13:18:24 +10:00
parent b48a65f87d
commit 2c5a1a192a
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 36 additions and 38 deletions

View File

@ -12,9 +12,15 @@
<div><h1>Timestamp of latest relay ping</h1></div>
<div id='timestamp'></div>
<script
src='https://unpkg.com/js-waku@latest/build/umd/js-waku.min.bundle.js'></script>
<script>
<script type='module'>
import {
waitForRemotePeer,
Protocols
} from 'https://unpkg.com/js-waku@next/bundle/index.js';
import {
createWaku
} from 'https://unpkg.com/js-waku@next/bundle/lib/create_waku.js'
/**
* This example demonstrates how to use the js-waku minified bundle
* available on unpkg.com.
@ -25,40 +31,37 @@
const timestampDiv = document.getElementById('timestamp');
try {
timestampDiv.innerHTML = '<p>Creating waku.</p>';
const node = await createWaku({ defaultBootstrap: true });
timestampDiv.innerHTML = '<p>Starting waku.</p>';
jswaku.Waku.create({ bootstrap: { default: true } }).catch(e => {
timestampDiv.innerHTML = 'Failed to create Waku: ' + e.toString();
await node.start();
timestampDiv.innerHTML = '<p>Connecting to a peer.</p>';
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 ping message available</p>';
}
).then(waku => {
timestampDiv.innerHTML = '<p>Connecting to a peer.</p>';
waku.waitForRemotePeer()
.catch((e) => {
timestampDiv.innerHTML = 'Failed to connect to peers' + e.toString();
})
.then(() => {
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 ping message available</p>';
}
// When returning true, `queryHistory` stops retrieving pages
// In our case, we only want one message, hence one page.
return true;
};
// When returning true, `queryHistory` stops retrieving pages
// In our case, we only want one message, hence one page.
return true;
};
const startTime = new Date();
// Only retrieve a week of messages
startTime.setTime(Date.now() - 7 * 24 * 60 * 60 * 1000);
const startTime = new Date();
// Only retrieve a week of messages
startTime.setTime(Date.now() - 7 * 24 * 60 * 60 * 1000);
waku.store
await node.store
.queryHistory(['/relay-ping/1/ping/null'], {
callback,
pageDirection: 'backward',
@ -67,14 +70,9 @@
startTime,
endTime: new Date()
}
})
.catch((e) => {
timestampDiv.innerHTML = 'Failed to retrieve messages' + e.toString();
});
});
});
} catch (e) {
timestampDiv.innerHTML = 'Failed to start application' + e.toString();
timestampDiv.innerHTML = 'Error encountered: ' + e.toString();
}
</script>
</body>