fix: use new js-waku API
This commit is contained in:
parent
08daac8a7f
commit
568f3f83f2
|
@ -1,6 +1,7 @@
|
|||
import { Waku } from "js-waku";
|
||||
import { waitForRemotePeer, utils } from "js-waku";
|
||||
import * as React from "react";
|
||||
import protons from "protons";
|
||||
import { createWaku } from "js-waku/lib/create_waku";
|
||||
|
||||
const ContentTopic = "/toy-chat/2/huilong/proto";
|
||||
|
||||
|
@ -22,9 +23,11 @@ function App() {
|
|||
|
||||
setWakuStatus("Starting");
|
||||
|
||||
Waku.create({ bootstrap: { default: true } }).then((waku) => {
|
||||
setWaku(waku);
|
||||
setWakuStatus("Connecting");
|
||||
createWaku({ defaultBootstrap: true }).then((waku) => {
|
||||
waku.start().then(() => {
|
||||
setWaku(waku);
|
||||
setWakuStatus("Connecting");
|
||||
});
|
||||
});
|
||||
}, [waku, wakuStatus]);
|
||||
|
||||
|
@ -34,7 +37,7 @@ function App() {
|
|||
// We do not handle disconnection/re-connection in this example
|
||||
if (wakuStatus === "Connected") return;
|
||||
|
||||
waku.waitForRemotePeer().then(() => {
|
||||
waitForRemotePeer(waku, ["store"]).then(() => {
|
||||
// We are now connected to a store node
|
||||
setWakuStatus("Connected");
|
||||
});
|
||||
|
@ -62,6 +65,7 @@ function App() {
|
|||
})
|
||||
.catch((e) => {
|
||||
console.log("Failed to retrieve messages", e);
|
||||
setWakuStatus("Error Encountered");
|
||||
});
|
||||
}, [waku, wakuStatus]);
|
||||
|
||||
|
@ -92,15 +96,20 @@ function decodeMessage(wakuMessage) {
|
|||
const time = new Date();
|
||||
time.setTime(timestamp);
|
||||
|
||||
const utf8Text = Buffer.from(text).toString("utf-8");
|
||||
const utf8Text = utils.bytesToUtf8(text);
|
||||
|
||||
return { text: utf8Text, timestamp: time, nick };
|
||||
return {
|
||||
text: utf8Text,
|
||||
timestamp: time,
|
||||
nick,
|
||||
timestampInt: wakuMessage.timestamp,
|
||||
};
|
||||
}
|
||||
|
||||
function Messages(props) {
|
||||
return props.messages.map(({ text, timestamp, nick }) => {
|
||||
return props.messages.map(({ text, timestamp, nick, timestampInt }) => {
|
||||
return (
|
||||
<li>
|
||||
<li key={timestampInt}>
|
||||
({formatDate(timestamp)}) {nick}: {text}
|
||||
</li>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue