chore(web-chat): bump js-waku to 0.27.0

This commit is contained in:
fryorcraken.eth 2022-09-14 22:49:32 +10:00
parent ac98251464
commit 081981a08a
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
5 changed files with 31 additions and 42 deletions

View File

@ -6,7 +6,7 @@
"dependencies": { "dependencies": {
"@livechat/ui-kit": "^0.5.0-20", "@livechat/ui-kit": "^0.5.0-20",
"@multiformats/multiaddr": "^10.4.0", "@multiformats/multiaddr": "^10.4.0",
"js-waku": "0.26.0", "js-waku": "0.27.0",
"process": "^0.11.10", "process": "^0.11.10",
"protons-runtime": "^3.1.0", "protons-runtime": "^3.1.0",
"react": "^17.0.2", "react": "^17.0.2",

View File

@ -9,7 +9,7 @@ specifiers:
'@types/react-dom': ^17.0.11 '@types/react-dom': ^17.0.11
cspell: ^6.0.0 cspell: ^6.0.0
gh-pages: ^4.0.0 gh-pages: ^4.0.0
js-waku: 0.26.0 js-waku: 0.27.0
npm-run-all: ^4.1.5 npm-run-all: ^4.1.5
prettier: ^2.6.2 prettier: ^2.6.2
process: ^0.11.10 process: ^0.11.10
@ -26,7 +26,7 @@ specifiers:
dependencies: dependencies:
'@livechat/ui-kit': 0.5.0-20_ibvs32p3vr2bbtbo3dwziny444 '@livechat/ui-kit': 0.5.0-20_ibvs32p3vr2bbtbo3dwziny444
'@multiformats/multiaddr': 10.4.0 '@multiformats/multiaddr': 10.4.0
js-waku: 0.26.0 js-waku: 0.27.0
process: 0.11.10 process: 0.11.10
protons-runtime: 3.1.0_uint8arraylist@2.3.2 protons-runtime: 3.1.0_uint8arraylist@2.3.2
react: 17.0.2 react: 17.0.2
@ -8382,8 +8382,8 @@ packages:
/js-tokens/4.0.0: /js-tokens/4.0.0:
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==} resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
/js-waku/0.26.0: /js-waku/0.27.0:
resolution: {integrity: sha512-BcgMeYj9wYGNt4fs3lFUSLpFqQttpju4FAmVbB19oYK1IWR8nGKu52eLAFBrh0uH3r73Ud9PXG3I1099THqlOQ==} resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==}
engines: {node: '>=16'} engines: {node: '>=16'}
dependencies: dependencies:
'@chainsafe/libp2p-gossipsub': 4.1.1 '@chainsafe/libp2p-gossipsub': 4.1.1
@ -8395,6 +8395,7 @@ packages:
'@libp2p/interface-peer-id': 1.0.4 '@libp2p/interface-peer-id': 1.0.4
'@libp2p/interface-peer-info': 1.0.2 '@libp2p/interface-peer-info': 1.0.2
'@libp2p/interface-peer-store': 1.2.1 '@libp2p/interface-peer-store': 1.2.1
'@libp2p/interface-pubsub': 2.0.1
'@libp2p/interfaces': 3.0.3 '@libp2p/interfaces': 3.0.3
'@libp2p/mplex': 5.1.1 '@libp2p/mplex': 5.1.1
'@libp2p/peer-id': 1.1.15 '@libp2p/peer-id': 1.1.15

View File

@ -1,15 +1,6 @@
import { useEffect, useReducer, useState } from "react"; import { useEffect, useReducer, useState } from "react";
import "./App.css"; import "./App.css";
import { import { PageDirection, Protocols, WakuMessage } from "js-waku";
PageDirection,
Protocols,
Waku,
WakuFilter,
WakuLightPush,
WakuMessage,
WakuRelay,
WakuStore,
} from "js-waku";
import handleCommand from "./command"; import handleCommand from "./command";
import Room from "./Room"; import Room from "./Room";
import { WakuContext } from "./WakuContext"; import { WakuContext } from "./WakuContext";
@ -22,8 +13,9 @@ import {
} from "js-waku/lib/predefined_bootstrap_nodes"; } from "js-waku/lib/predefined_bootstrap_nodes";
import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer";
import { PeerDiscoveryStaticPeers } from "js-waku/lib/peer_discovery_static_list"; import { PeerDiscoveryStaticPeers } from "js-waku/lib/peer_discovery_static_list";
import { defaultLibp2p } from "js-waku/lib/create_waku"; import type { WakuLight } from "js-waku/lib/interfaces";
import process from "process"; import process from "process";
import { createLightNode } from "js-waku/lib/create_waku";
const themes = { const themes = {
AuthorName: { AuthorName: {
@ -57,7 +49,7 @@ const themes = {
export const ChatContentTopic = "/toy-chat/2/huilong/proto"; export const ChatContentTopic = "/toy-chat/2/huilong/proto";
async function retrieveStoreMessages( async function retrieveStoreMessages(
waku: Waku, waku: WakuLight,
setArchivedMessages: (value: Message[]) => void setArchivedMessages: (value: Message[]) => void
): Promise<number> { ): Promise<number> {
const callback = (wakuMessages: WakuMessage[]): void => { const callback = (wakuMessages: WakuMessage[]): void => {
@ -98,7 +90,7 @@ async function retrieveStoreMessages(
export default function App() { export default function App() {
const [messages, dispatchMessages] = useReducer(reduceMessages, []); const [messages, dispatchMessages] = useReducer(reduceMessages, []);
const [waku, setWaku] = useState<Waku | undefined>(undefined); const [waku, setWaku] = useState<WakuLight | undefined>(undefined);
const [nick, setNick] = useState<string>(() => { const [nick, setNick] = useState<string>(() => {
const persistedNick = window.localStorage.getItem("nick"); const persistedNick = window.localStorage.getItem("nick");
return persistedNick !== null ? persistedNick : generate(); return persistedNick !== null ? persistedNick : generate();
@ -204,24 +196,17 @@ export default function App() {
); );
} }
async function initWaku(setter: (waku: Waku) => void) { async function initWaku(setter: (waku: WakuLight) => void) {
try { try {
// TODO: Remove this declaration once there are optional in js-waku const waku = await createLightNode({
const wakuRelay = new WakuRelay({ emitSelf: true }); libp2p: {
peerDiscovery: [
const libp2p = await defaultLibp2p(wakuRelay, { new PeerDiscoveryStaticPeers(
peerDiscovery: [ getPredefinedBootstrapNodes(selectFleetEnv())
new PeerDiscoveryStaticPeers( ),
getPredefinedBootstrapNodes(selectFleetEnv()) ],
), },
],
}); });
const wakuStore = new WakuStore(libp2p);
const wakuLightPush = new WakuLightPush(libp2p);
const wakuFilter = new WakuFilter(libp2p);
const waku = new Waku({}, libp2p, wakuStore, wakuLightPush, wakuFilter);
await waku.start(); await waku.start();
setter(waku); setter(waku);

View File

@ -1,8 +1,8 @@
import { createContext, useContext } from "react"; import { createContext, useContext } from "react";
import { Waku } from "js-waku"; import type { WakuLight } from "js-waku/lib/interfaces";
export type WakuContextType = { export type WakuContextType = {
waku?: Waku; waku?: WakuLight;
}; };
export const WakuContext = createContext<WakuContextType>({ waku: undefined }); export const WakuContext = createContext<WakuContextType>({ waku: undefined });

View File

@ -1,5 +1,5 @@
import { multiaddr } from "@multiformats/multiaddr"; import { multiaddr } from "@multiformats/multiaddr";
import { Waku } from "js-waku"; import type { WakuLight } from "js-waku/lib/interfaces";
function help(): string[] { function help(): string[] {
return [ return [
@ -21,14 +21,17 @@ function nick(
return [`New nick: ${nick}`]; return [`New nick: ${nick}`];
} }
function info(waku: Waku | undefined): string[] { function info(waku: WakuLight | undefined): string[] {
if (!waku) { if (!waku) {
return ["Waku node is starting"]; return ["Waku node is starting"];
} }
return [`PeerId: ${waku.libp2p.peerId.toString()}`]; return [`PeerId: ${waku.libp2p.peerId.toString()}`];
} }
function connect(peer: string | undefined, waku: Waku | undefined): string[] { function connect(
peer: string | undefined,
waku: WakuLight | undefined
): string[] {
if (!waku) { if (!waku) {
return ["Waku node is starting"]; return ["Waku node is starting"];
} }
@ -50,7 +53,7 @@ function connect(peer: string | undefined, waku: Waku | undefined): string[] {
} }
} }
async function peers(waku: Waku | undefined): Promise<string[]> { async function peers(waku: WakuLight | undefined): Promise<string[]> {
if (!waku) { if (!waku) {
return ["Waku node is starting"]; return ["Waku node is starting"];
} }
@ -77,7 +80,7 @@ async function peers(waku: Waku | undefined): Promise<string[]> {
return response; return response;
} }
function connections(waku: Waku | undefined): string[] { function connections(waku: WakuLight | undefined): string[] {
if (!waku) { if (!waku) {
return ["Waku node is starting"]; return ["Waku node is starting"];
} }
@ -98,7 +101,7 @@ function connections(waku: Waku | undefined): string[] {
export default async function handleCommand( export default async function handleCommand(
input: string, input: string,
waku: Waku | undefined, waku: WakuLight | undefined,
setNick: (nick: string) => void setNick: (nick: string) => void
): Promise<{ command: string; response: string[] }> { ): Promise<{ command: string; response: string[] }> {
let response: string[] = []; let response: string[] = [];