mirror of
https://github.com/status-im/js-waku-examples.git
synced 2025-01-11 14:34:17 +00:00
Merge pull request #108 from waku-org/js-waku-0.28.0
This commit is contained in:
commit
a895f2cc4d
@ -8,9 +8,9 @@
|
||||
"@ethersproject/providers": "5.7.0",
|
||||
"@material-ui/core": "^4.12.3",
|
||||
"@material-ui/icons": "^4.11.2",
|
||||
"ethers": "5.7.0",
|
||||
"ethers": "5.7.1",
|
||||
"fontsource-roboto": "^4.0.0",
|
||||
"js-waku": "0.27.0",
|
||||
"js-waku": "0.28.0",
|
||||
"protobufjs": "^7.1.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
70
eth-pm/pnpm-lock.yaml
generated
70
eth-pm/pnpm-lock.yaml
generated
@ -12,9 +12,9 @@ specifiers:
|
||||
'@types/react-dom': ^18.0.6
|
||||
cspell: ^6.0.0
|
||||
eslint: ^8.9.0
|
||||
ethers: 5.7.0
|
||||
ethers: 5.7.1
|
||||
fontsource-roboto: ^4.0.0
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
npm-run-all: ^4.1.5
|
||||
prettier: ^2.5.1
|
||||
protobufjs: ^7.1.0
|
||||
@ -29,9 +29,9 @@ dependencies:
|
||||
'@ethersproject/providers': 5.7.0
|
||||
'@material-ui/core': 4.12.4_zxljzmqdrxwnuenbkrz77w74uy
|
||||
'@material-ui/icons': 4.11.3_upnjamd3tbaukgopcqqdlc7jbm
|
||||
ethers: 5.7.0
|
||||
ethers: 5.7.1
|
||||
fontsource-roboto: 4.0.0
|
||||
js-waku: 0.27.0_undici@5.10.0
|
||||
js-waku: 0.28.0_undici@5.10.0
|
||||
protobufjs: 7.1.0
|
||||
react: 18.2.0
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
@ -2099,10 +2099,10 @@ packages:
|
||||
'@ethersproject/bignumber': 5.7.0
|
||||
'@ethersproject/bytes': 5.7.0
|
||||
'@ethersproject/logger': 5.7.0
|
||||
'@ethersproject/networks': 5.7.0
|
||||
'@ethersproject/networks': 5.7.1
|
||||
'@ethersproject/properties': 5.7.0
|
||||
'@ethersproject/transactions': 5.7.0
|
||||
'@ethersproject/web': 5.7.0
|
||||
'@ethersproject/web': 5.7.1
|
||||
dev: false
|
||||
|
||||
/@ethersproject/abstract-signer/5.7.0:
|
||||
@ -2239,6 +2239,12 @@ packages:
|
||||
'@ethersproject/logger': 5.7.0
|
||||
dev: false
|
||||
|
||||
/@ethersproject/networks/5.7.1:
|
||||
resolution: {integrity: sha512-n/MufjFYv3yFcUyfhnXotyDlNdFb7onmkSy8aQERi2PjNcnWQ66xXxa3XlS8nCcA8aJKJjIIMNJTC7tu80GwpQ==}
|
||||
dependencies:
|
||||
'@ethersproject/logger': 5.7.0
|
||||
dev: false
|
||||
|
||||
/@ethersproject/pbkdf2/5.7.0:
|
||||
resolution: {integrity: sha512-oR/dBRZR6GTyaofd86DehG72hY6NpAjhabkhxgr3X2FpJtJuodEl2auADWBZfhDHgVCbu3/H/Ocq2uC6dpNjjw==}
|
||||
dependencies:
|
||||
@ -2280,6 +2286,34 @@ packages:
|
||||
- utf-8-validate
|
||||
dev: false
|
||||
|
||||
/@ethersproject/providers/5.7.1:
|
||||
resolution: {integrity: sha512-vZveG/DLyo+wk4Ga1yx6jSEHrLPgmTt+dFv0dv8URpVCRf0jVhalps1jq/emN/oXnMRsC7cQgAF32DcXLL7BPQ==}
|
||||
dependencies:
|
||||
'@ethersproject/abstract-provider': 5.7.0
|
||||
'@ethersproject/abstract-signer': 5.7.0
|
||||
'@ethersproject/address': 5.7.0
|
||||
'@ethersproject/base64': 5.7.0
|
||||
'@ethersproject/basex': 5.7.0
|
||||
'@ethersproject/bignumber': 5.7.0
|
||||
'@ethersproject/bytes': 5.7.0
|
||||
'@ethersproject/constants': 5.7.0
|
||||
'@ethersproject/hash': 5.7.0
|
||||
'@ethersproject/logger': 5.7.0
|
||||
'@ethersproject/networks': 5.7.1
|
||||
'@ethersproject/properties': 5.7.0
|
||||
'@ethersproject/random': 5.7.0
|
||||
'@ethersproject/rlp': 5.7.0
|
||||
'@ethersproject/sha2': 5.7.0
|
||||
'@ethersproject/strings': 5.7.0
|
||||
'@ethersproject/transactions': 5.7.0
|
||||
'@ethersproject/web': 5.7.1
|
||||
bech32: 1.1.4
|
||||
ws: 7.4.6
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
- utf-8-validate
|
||||
dev: false
|
||||
|
||||
/@ethersproject/random/5.7.0:
|
||||
resolution: {integrity: sha512-19WjScqRA8IIeWclFme75VMXSBvi4e6InrUNuaR4s5pTF2qNhcGdCUwdxUVGtDDqC00sDLCO93jPQoDUH4HVmQ==}
|
||||
dependencies:
|
||||
@ -2388,6 +2422,16 @@ packages:
|
||||
'@ethersproject/strings': 5.7.0
|
||||
dev: false
|
||||
|
||||
/@ethersproject/web/5.7.1:
|
||||
resolution: {integrity: sha512-Gueu8lSvyjBWL4cYsWsjh6MtMwM0+H4HvqFPZfB6dV8ctbP9zFAO73VG1cMWae0FLPCtz0peKPpZY8/ugJJX2w==}
|
||||
dependencies:
|
||||
'@ethersproject/base64': 5.7.0
|
||||
'@ethersproject/bytes': 5.7.0
|
||||
'@ethersproject/logger': 5.7.0
|
||||
'@ethersproject/properties': 5.7.0
|
||||
'@ethersproject/strings': 5.7.0
|
||||
dev: false
|
||||
|
||||
/@ethersproject/wordlists/5.7.0:
|
||||
resolution: {integrity: sha512-S2TFNJNfHWVHNE6cNDjbVlZ6MgE17MIxMbMg2zv3wn+3XSJGosL1m9ZVv3GXCf/2ymSsQ+hRI5IzoMJTG6aoVA==}
|
||||
dependencies:
|
||||
@ -6559,8 +6603,8 @@ packages:
|
||||
engines: {node: '>= 0.6'}
|
||||
dev: true
|
||||
|
||||
/ethers/5.7.0:
|
||||
resolution: {integrity: sha512-5Xhzp2ZQRi0Em+0OkOcRHxPzCfoBfgtOQA+RUylSkuHbhTEaQklnYi2hsWbRgs3ztJsXVXd9VKBcO1ScWL8YfA==}
|
||||
/ethers/5.7.1:
|
||||
resolution: {integrity: sha512-5krze4dRLITX7FpU8J4WscXqADiKmyeNlylmmDLbS95DaZpBhDe2YSwRQwKXWNyXcox7a3gBgm/MkGXV1O1S/Q==}
|
||||
dependencies:
|
||||
'@ethersproject/abi': 5.7.0
|
||||
'@ethersproject/abstract-provider': 5.7.0
|
||||
@ -6577,10 +6621,10 @@ packages:
|
||||
'@ethersproject/json-wallets': 5.7.0
|
||||
'@ethersproject/keccak256': 5.7.0
|
||||
'@ethersproject/logger': 5.7.0
|
||||
'@ethersproject/networks': 5.7.0
|
||||
'@ethersproject/networks': 5.7.1
|
||||
'@ethersproject/pbkdf2': 5.7.0
|
||||
'@ethersproject/properties': 5.7.0
|
||||
'@ethersproject/providers': 5.7.0
|
||||
'@ethersproject/providers': 5.7.1
|
||||
'@ethersproject/random': 5.7.0
|
||||
'@ethersproject/rlp': 5.7.0
|
||||
'@ethersproject/sha2': 5.7.0
|
||||
@ -6590,7 +6634,7 @@ packages:
|
||||
'@ethersproject/transactions': 5.7.0
|
||||
'@ethersproject/units': 5.7.0
|
||||
'@ethersproject/wallet': 5.7.0
|
||||
'@ethersproject/web': 5.7.0
|
||||
'@ethersproject/web': 5.7.1
|
||||
'@ethersproject/wordlists': 5.7.0
|
||||
transitivePeerDependencies:
|
||||
- bufferutil
|
||||
@ -8443,8 +8487,8 @@ packages:
|
||||
/js-tokens/4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
|
||||
/js-waku/0.27.0_undici@5.10.0:
|
||||
resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
|
||||
/js-waku/0.28.0_undici@5.10.0:
|
||||
resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-gossipsub': 4.1.1_undici@5.10.0
|
||||
|
@ -18,16 +18,18 @@
|
||||
<div><h2>Remote Peer Id</h2></div>
|
||||
<div id='remote-peer-id'></div>
|
||||
|
||||
<label for='remote-multiaddr'>Remote peer's multiaddr</label>
|
||||
<input id='remote-multiaddr'
|
||||
type='text'
|
||||
value="/dns4/node-01.ac-cn-hongkong-c.wakuv2.test.statusim.net/tcp/443/wss/p2p/16Uiu2HAkvWiyFsgRhuJEb9JfjYxEkoHLgnUQmr1N5mKWnYjxYRVm">
|
||||
<button id='dial' type='button'>Dial</button>
|
||||
<br/>
|
||||
<button id='subscribe' type='button'>Subscribe</button>
|
||||
<button id='unsubscribe' type='button'>Unsubscribe</button>
|
||||
<button id='subscribe' type='button'>Subscribe with Filter</button>
|
||||
<button id='unsubscribe' type='button'>Unsubscribe with Filter</button>
|
||||
<br/>
|
||||
<label for='textInput'>Message text</label>
|
||||
<input id='textInput' placeholder='Type your message here' type='text'>
|
||||
<button id='sendButton' type='button'>Send Message</button>
|
||||
<button id='sendButton' type='button'>Send message using Light Push</button>
|
||||
<br/>
|
||||
<div id="messages"></div>
|
||||
|
||||
@ -35,13 +37,13 @@
|
||||
import {
|
||||
utils,
|
||||
WakuMessage
|
||||
} 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'
|
||||
} 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'
|
||||
|
||||
const peerIdDiv = document.getElementById('peer-id');
|
||||
const remotePeerIdDiv = document.getElementById('remote-peer-id');
|
||||
|
@ -21,7 +21,7 @@
|
||||
"@angular/platform-browser": "~14.2.0",
|
||||
"@angular/platform-browser-dynamic": "~14.2.0",
|
||||
"@angular/router": "~14.2.0",
|
||||
"js-waku": "0.27.0",
|
||||
"js-waku": "0.28.0",
|
||||
"protobufjs": "^7.1.0",
|
||||
"rxjs": "~7.5.0",
|
||||
"tslib": "^2.3.0",
|
||||
|
8
relay-angular-chat/pnpm-lock.yaml
generated
8
relay-angular-chat/pnpm-lock.yaml
generated
@ -16,7 +16,7 @@ specifiers:
|
||||
'@types/node': ^17.0.21
|
||||
is-ci-cli: ^2.2.0
|
||||
jasmine-core: ~4.3.0
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
karma: ~6.4.0
|
||||
karma-chrome-launcher: ~3.1.0
|
||||
karma-coverage: ~2.2.0
|
||||
@ -37,7 +37,7 @@ dependencies:
|
||||
'@angular/platform-browser': 14.2.0_afytwol7hs4qio34buyx2grhfa
|
||||
'@angular/platform-browser-dynamic': 14.2.0_owch6soaoexeadly32xw5vendq
|
||||
'@angular/router': 14.2.0_6lk4yxyxfaqzosenawf2bqx6vy
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
protobufjs: 7.1.0
|
||||
rxjs: 7.5.6
|
||||
tslib: 2.4.0
|
||||
@ -5440,8 +5440,8 @@ packages:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
dev: true
|
||||
|
||||
/js-waku/0.27.0:
|
||||
resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
|
||||
/js-waku/0.28.0:
|
||||
resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-gossipsub': 4.1.1
|
||||
|
@ -12,9 +12,9 @@
|
||||
<div><h1>Waku Node Status</h1></div>
|
||||
<div id='status'></div>
|
||||
|
||||
<label for='textInput'>Message text</label>
|
||||
<input id='textInput' placeholder='Type your message here' type='text'>
|
||||
<button id='sendButton' type='button'>Send Message
|
||||
</button>
|
||||
<button id='sendButton' type='button'>Send Message using Relay</button>
|
||||
|
||||
<div><h1>Messages</h1></div>
|
||||
<div id='messages'></div>
|
||||
@ -28,13 +28,13 @@
|
||||
|
||||
import {
|
||||
WakuMessage
|
||||
} 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 {
|
||||
createWaku
|
||||
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js'
|
||||
createPrivacyNode
|
||||
} 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'
|
||||
|
||||
const statusDiv = document.getElementById('status');
|
||||
const messagesDiv = document.getElementById('messages');
|
||||
@ -60,7 +60,7 @@
|
||||
// We are currently working on migrating this method to DNS Discovery.
|
||||
//
|
||||
// https://js-waku.wakuconnect.dev/classes/waku.Waku.html#create
|
||||
const waku = await createWaku({defaultBootstrap: true});
|
||||
const waku = await createPrivacyNode({defaultBootstrap: true});
|
||||
await waku.start();
|
||||
|
||||
// Had a hook to process all incoming messages on a specified content topic.
|
||||
|
@ -7,7 +7,7 @@
|
||||
"@testing-library/jest-dom": "^5.16.5",
|
||||
"@testing-library/react": "^13.3.0",
|
||||
"@testing-library/user-event": "^13.5.0",
|
||||
"js-waku": "0.27.0",
|
||||
"js-waku": "0.28.0",
|
||||
"protobufjs": "^7.0.0",
|
||||
"react": "^18.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
|
8
relay-reactjs-chat/pnpm-lock.yaml
generated
8
relay-reactjs-chat/pnpm-lock.yaml
generated
@ -6,7 +6,7 @@ specifiers:
|
||||
'@testing-library/react': ^13.3.0
|
||||
'@testing-library/user-event': ^13.5.0
|
||||
eslint: ^8.22.0
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
protobufjs: ^7.0.0
|
||||
react: ^18.2.0
|
||||
react-dom: ^18.2.0
|
||||
@ -17,7 +17,7 @@ dependencies:
|
||||
'@testing-library/jest-dom': 5.16.5
|
||||
'@testing-library/react': 13.3.0_biqbaboplfbrettd7655fr4n2y
|
||||
'@testing-library/user-event': 13.5.0_wl4iynrlixafokvgqnhzlvigei
|
||||
js-waku: 0.27.0_undici@5.10.0
|
||||
js-waku: 0.28.0_undici@5.10.0
|
||||
protobufjs: 7.0.0
|
||||
react: 18.2.0
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
@ -7001,8 +7001,8 @@ packages:
|
||||
/js-tokens/4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
|
||||
/js-waku/0.27.0_undici@5.10.0:
|
||||
resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
|
||||
/js-waku/0.28.0_undici@5.10.0:
|
||||
resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-gossipsub': 4.1.1_undici@5.10.0
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { WakuMessage } from "js-waku";
|
||||
import * as React from "react";
|
||||
import protobuf from "protobufjs";
|
||||
import { createWaku } from "js-waku/lib/create_waku";
|
||||
import { createPrivacyNode } from "js-waku/lib/create_waku";
|
||||
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
|
||||
|
||||
const ContentTopic = `/relay-reactjs-chat/1/chat/proto`;
|
||||
@ -23,7 +23,7 @@ function App() {
|
||||
|
||||
setWakuStatus("Starting");
|
||||
(async () => {
|
||||
const waku = await createWaku({ defaultBootstrap: true });
|
||||
const waku = await createPrivacyNode({ defaultBootstrap: true });
|
||||
|
||||
setWaku(waku);
|
||||
await waku.start();
|
||||
|
@ -2,39 +2,38 @@
|
||||
<html lang='en'>
|
||||
|
||||
<head>
|
||||
<meta charset='UTF-8' />
|
||||
<meta content='width=device-width, initial-scale=1.0' name='viewport' />
|
||||
<title>JS-Waku store script tag example</title>
|
||||
<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';
|
||||
import {
|
||||
createWaku
|
||||
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/create_waku.js'
|
||||
import {
|
||||
waitForRemotePeer
|
||||
} from 'https://unpkg.com/js-waku@0.27.0/bundle/lib/wait_for_remote_peer.js'
|
||||
import {
|
||||
Protocols
|
||||
} from 'https://unpkg.com/js-waku@0.28.0/bundle/index.js';
|
||||
import {
|
||||
createWaku
|
||||
} from 'https://unpkg.com/js-waku@0.28.0/bundle/lib/create_waku.js'
|
||||
import {
|
||||
waitForRemotePeer
|
||||
} 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
|
||||
* 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');
|
||||
/**
|
||||
* 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');
|
||||
|
||||
try {
|
||||
timestampDiv.innerHTML = '<p>Creating waku.</p>';
|
||||
const node = await createWaku({ defaultBootstrap: true });
|
||||
const node = await createWaku({defaultBootstrap: true});
|
||||
|
||||
timestampDiv.innerHTML = '<p>Starting waku.</p>';
|
||||
await node.start();
|
||||
@ -43,40 +42,34 @@
|
||||
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.
|
||||
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);
|
||||
|
||||
|
||||
await node.store
|
||||
.queryHistory([], {
|
||||
callback,
|
||||
pageDirection: 'backward',
|
||||
pageSize: 1,
|
||||
timeFilter: {
|
||||
startTime,
|
||||
endTime: new Date()
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
timestampDiv.innerHTML = 'Error encountered: ' + e.toString();
|
||||
}
|
||||
try {
|
||||
await node.store
|
||||
.queryOrderedCallback([],
|
||||
callback,
|
||||
{
|
||||
pageDirection: 'backward',
|
||||
pageSize: 1,
|
||||
timeFilter: {
|
||||
startTime,
|
||||
endTime: new Date()
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Known issue: https://github.com/status-im/nwaku/issues/1157
|
||||
console.log(e)
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
"@testing-library/jest-dom": "^5.16.4",
|
||||
"@testing-library/react": "^13.2.0",
|
||||
"@testing-library/user-event": "^14.1.1",
|
||||
"js-waku": "0.27.0",
|
||||
"js-waku": "0.28.0",
|
||||
"protobufjs": "^7.1.0",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0",
|
||||
|
8
store-reactjs-chat/pnpm-lock.yaml
generated
8
store-reactjs-chat/pnpm-lock.yaml
generated
@ -5,7 +5,7 @@ specifiers:
|
||||
'@testing-library/jest-dom': ^5.16.4
|
||||
'@testing-library/react': ^13.2.0
|
||||
'@testing-library/user-event': ^14.1.1
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
protobufjs: ^7.1.0
|
||||
react: ^18.1.0
|
||||
react-dom: ^18.1.0
|
||||
@ -17,7 +17,7 @@ dependencies:
|
||||
'@testing-library/jest-dom': 5.16.5
|
||||
'@testing-library/react': 13.3.0_biqbaboplfbrettd7655fr4n2y
|
||||
'@testing-library/user-event': 14.4.2_znfriv3ismgf3ybh2woqwlpfea
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
protobufjs: 7.1.0
|
||||
react: 18.2.0
|
||||
react-dom: 18.2.0_react@18.2.0
|
||||
@ -7375,8 +7375,8 @@ packages:
|
||||
/js-tokens/4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
|
||||
/js-waku/0.27.0:
|
||||
resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
|
||||
/js-waku/0.28.0:
|
||||
resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-gossipsub': 4.1.1
|
||||
|
@ -55,32 +55,40 @@ function App() {
|
||||
React.useEffect(() => {
|
||||
if (wakuStatus !== "Connected") return;
|
||||
|
||||
const processMessages = (retrievedMessages) => {
|
||||
const messages = retrievedMessages.map(decodeMessage).filter(Boolean);
|
||||
(async () => {
|
||||
const startTime = new Date();
|
||||
// 7 days/week, 24 hours/day, 60min/hour, 60secs/min, 100ms/sec
|
||||
startTime.setTime(startTime.getTime() - 7 * 24 * 60 * 60 * 1000);
|
||||
|
||||
setMessages((currentMessages) => {
|
||||
return currentMessages.concat(messages.reverse());
|
||||
});
|
||||
};
|
||||
// TODO: Remove this timeout once https://github.com/status-im/js-waku/issues/913 is done
|
||||
await new Promise((resolve) => setTimeout(resolve, 200));
|
||||
|
||||
const startTime = new Date();
|
||||
// 7 days/week, 24 hours/day, 60min/hour, 60secs/min, 100ms/sec
|
||||
startTime.setTime(startTime.getTime() - 7 * 24 * 60 * 60 * 1000);
|
||||
|
||||
// TODO: Remove this timeout once https://github.com/status-im/js-waku/issues/913 is done
|
||||
setTimeout(
|
||||
() =>
|
||||
waku.store
|
||||
.queryHistory([ContentTopic], {
|
||||
callback: processMessages,
|
||||
try {
|
||||
for await (const messagesPromises of waku.store.queryGenerator(
|
||||
[ContentTopic],
|
||||
{
|
||||
timeFilter: { startTime, endTime: new Date() },
|
||||
})
|
||||
.catch((e) => {
|
||||
console.log("Failed to retrieve messages", e);
|
||||
setWakuStatus("Error Encountered");
|
||||
}),
|
||||
200
|
||||
);
|
||||
pageDirection: "forward",
|
||||
}
|
||||
)) {
|
||||
const messages = await Promise.all(
|
||||
messagesPromises
|
||||
.map(async (p) => {
|
||||
const msg = await p;
|
||||
return decodeMessage(msg);
|
||||
})
|
||||
.filter(Boolean)
|
||||
);
|
||||
|
||||
setMessages((currentMessages) => {
|
||||
return currentMessages.concat(messages.reverse());
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Failed to retrieve messages", e);
|
||||
setWakuStatus("Error Encountered");
|
||||
}
|
||||
})();
|
||||
}, [waku, wakuStatus]);
|
||||
|
||||
return (
|
||||
|
@ -6,7 +6,7 @@
|
||||
"dependencies": {
|
||||
"@livechat/ui-kit": "^0.5.0-20",
|
||||
"@multiformats/multiaddr": "^10.4.0",
|
||||
"js-waku": "0.27.0",
|
||||
"js-waku": "0.28.0",
|
||||
"process": "^0.11.10",
|
||||
"protons-runtime": "^3.1.0",
|
||||
"react": "^17.0.2",
|
||||
|
8
web-chat/pnpm-lock.yaml
generated
8
web-chat/pnpm-lock.yaml
generated
@ -9,7 +9,7 @@ specifiers:
|
||||
'@types/react-dom': ^17.0.11
|
||||
cspell: ^6.0.0
|
||||
gh-pages: ^4.0.0
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
npm-run-all: ^4.1.5
|
||||
prettier: ^2.6.2
|
||||
process: ^0.11.10
|
||||
@ -26,7 +26,7 @@ specifiers:
|
||||
dependencies:
|
||||
'@livechat/ui-kit': 0.5.0-20_ibvs32p3vr2bbtbo3dwziny444
|
||||
'@multiformats/multiaddr': 10.4.0
|
||||
js-waku: 0.27.0
|
||||
js-waku: 0.28.0
|
||||
process: 0.11.10
|
||||
protons-runtime: 3.1.0_uint8arraylist@2.3.2
|
||||
react: 17.0.2
|
||||
@ -8382,8 +8382,8 @@ packages:
|
||||
/js-tokens/4.0.0:
|
||||
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
|
||||
|
||||
/js-waku/0.27.0:
|
||||
resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
|
||||
/js-waku/0.28.0:
|
||||
resolution: {integrity: sha512-MEIFugvio2IaQMQT+g+bn24BvlJ5S4PdSKD0AGVZlR7q1BhECwlpRoytyz0A/hC1+EJWhrZB8cpIAmxwtYWTBw==}
|
||||
engines: {node: '>=16'}
|
||||
dependencies:
|
||||
'@chainsafe/libp2p-gossipsub': 4.1.1
|
||||
|
@ -51,19 +51,7 @@ export const ChatContentTopic = "/toy-chat/2/huilong/proto";
|
||||
async function retrieveStoreMessages(
|
||||
waku: WakuLight,
|
||||
setArchivedMessages: (value: Message[]) => void
|
||||
): Promise<number> {
|
||||
const callback = (wakuMessages: WakuMessage[]): void => {
|
||||
const messages: Message[] = [];
|
||||
wakuMessages
|
||||
.map((wakuMsg) => Message.fromWakuMessage(wakuMsg))
|
||||
.forEach((message) => {
|
||||
if (message) {
|
||||
messages.push(message);
|
||||
}
|
||||
});
|
||||
setArchivedMessages(messages);
|
||||
};
|
||||
|
||||
): Promise<void> {
|
||||
const startTime = new Date();
|
||||
// Only retrieve a week of history
|
||||
startTime.setTime(Date.now() - 1000 * 60 * 60 * 24 * 7);
|
||||
@ -71,20 +59,32 @@ async function retrieveStoreMessages(
|
||||
const endTime = new Date();
|
||||
|
||||
try {
|
||||
const res = await waku.store.queryHistory([ChatContentTopic], {
|
||||
pageSize: 5,
|
||||
pageDirection: PageDirection.FORWARD,
|
||||
timeFilter: {
|
||||
startTime,
|
||||
endTime,
|
||||
},
|
||||
callback,
|
||||
});
|
||||
for await (const messagesPromises of waku.store.queryGenerator(
|
||||
[ChatContentTopic],
|
||||
{
|
||||
pageSize: 5,
|
||||
pageDirection: PageDirection.FORWARD,
|
||||
timeFilter: {
|
||||
startTime,
|
||||
endTime,
|
||||
},
|
||||
}
|
||||
)) {
|
||||
const messages: Message[] = [];
|
||||
const wakuMessages = await Promise.all(messagesPromises);
|
||||
|
||||
return res.length;
|
||||
wakuMessages
|
||||
.filter(isWakuMessageDefined)
|
||||
.map((wakuMsg) => Message.fromWakuMessage(wakuMsg))
|
||||
.forEach((message) => {
|
||||
if (message) {
|
||||
messages.push(message);
|
||||
}
|
||||
});
|
||||
setArchivedMessages(messages);
|
||||
}
|
||||
} catch (e) {
|
||||
console.log("Failed to retrieve messages", e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,3 +228,9 @@ function selectFleetEnv() {
|
||||
function reduceMessages(state: Message[], newMessages: Message[]) {
|
||||
return state.concat(newMessages);
|
||||
}
|
||||
|
||||
const isWakuMessageDefined = (
|
||||
msg: WakuMessage | undefined
|
||||
): msg is WakuMessage => {
|
||||
return !!msg;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user