diff --git a/web-chat/package.json b/web-chat/package.json index 5fe94c6..c1f243e 100644 --- a/web-chat/package.json +++ b/web-chat/package.json @@ -6,7 +6,7 @@ "dependencies": { "@livechat/ui-kit": "^0.5.0-20", "@multiformats/multiaddr": "^10.4.0", - "js-waku": "0.26.0", + "js-waku": "0.27.0", "process": "^0.11.10", "protons-runtime": "^3.1.0", "react": "^17.0.2", diff --git a/web-chat/pnpm-lock.yaml b/web-chat/pnpm-lock.yaml index 2db889f..f3df525 100644 --- a/web-chat/pnpm-lock.yaml +++ b/web-chat/pnpm-lock.yaml @@ -9,7 +9,7 @@ specifiers: '@types/react-dom': ^17.0.11 cspell: ^6.0.0 gh-pages: ^4.0.0 - js-waku: 0.26.0 + js-waku: 0.27.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.26.0 + js-waku: 0.27.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.26.0: - resolution: {integrity: sha512-BcgMeYj9wYGNt4fs3lFUSLpFqQttpju4FAmVbB19oYK1IWR8nGKu52eLAFBrh0uH3r73Ud9PXG3I1099THqlOQ==} + /js-waku/0.27.0: + resolution: {integrity: sha512-uIh1h2Gu+aEyrGb4qmyk2Sc91in3fMfOil0kdtrps9HnA7ESbC5c6d148LeJaxqH5rfOkrfXXIhw1zwA3hlauw==} engines: {node: '>=16'} dependencies: '@chainsafe/libp2p-gossipsub': 4.1.1 @@ -8395,6 +8395,7 @@ packages: '@libp2p/interface-peer-id': 1.0.4 '@libp2p/interface-peer-info': 1.0.2 '@libp2p/interface-peer-store': 1.2.1 + '@libp2p/interface-pubsub': 2.0.1 '@libp2p/interfaces': 3.0.3 '@libp2p/mplex': 5.1.1 '@libp2p/peer-id': 1.1.15 diff --git a/web-chat/src/App.tsx b/web-chat/src/App.tsx index 802e582..1bbb34a 100644 --- a/web-chat/src/App.tsx +++ b/web-chat/src/App.tsx @@ -1,15 +1,6 @@ import { useEffect, useReducer, useState } from "react"; import "./App.css"; -import { - PageDirection, - Protocols, - Waku, - WakuFilter, - WakuLightPush, - WakuMessage, - WakuRelay, - WakuStore, -} from "js-waku"; +import { PageDirection, Protocols, WakuMessage } from "js-waku"; import handleCommand from "./command"; import Room from "./Room"; import { WakuContext } from "./WakuContext"; @@ -22,8 +13,9 @@ import { } from "js-waku/lib/predefined_bootstrap_nodes"; import { waitForRemotePeer } from "js-waku/lib/wait_for_remote_peer"; 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 { createLightNode } from "js-waku/lib/create_waku"; const themes = { AuthorName: { @@ -57,7 +49,7 @@ const themes = { export const ChatContentTopic = "/toy-chat/2/huilong/proto"; async function retrieveStoreMessages( - waku: Waku, + waku: WakuLight, setArchivedMessages: (value: Message[]) => void ): Promise { const callback = (wakuMessages: WakuMessage[]): void => { @@ -98,7 +90,7 @@ async function retrieveStoreMessages( export default function App() { const [messages, dispatchMessages] = useReducer(reduceMessages, []); - const [waku, setWaku] = useState(undefined); + const [waku, setWaku] = useState(undefined); const [nick, setNick] = useState(() => { const persistedNick = window.localStorage.getItem("nick"); 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 { - // TODO: Remove this declaration once there are optional in js-waku - const wakuRelay = new WakuRelay({ emitSelf: true }); - - const libp2p = await defaultLibp2p(wakuRelay, { - peerDiscovery: [ - new PeerDiscoveryStaticPeers( - getPredefinedBootstrapNodes(selectFleetEnv()) - ), - ], + const waku = await createLightNode({ + libp2p: { + peerDiscovery: [ + 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(); setter(waku); diff --git a/web-chat/src/WakuContext.ts b/web-chat/src/WakuContext.ts index 86a6a7c..714d500 100644 --- a/web-chat/src/WakuContext.ts +++ b/web-chat/src/WakuContext.ts @@ -1,8 +1,8 @@ import { createContext, useContext } from "react"; -import { Waku } from "js-waku"; +import type { WakuLight } from "js-waku/lib/interfaces"; export type WakuContextType = { - waku?: Waku; + waku?: WakuLight; }; export const WakuContext = createContext({ waku: undefined }); diff --git a/web-chat/src/command.ts b/web-chat/src/command.ts index 66d3684..860efe1 100644 --- a/web-chat/src/command.ts +++ b/web-chat/src/command.ts @@ -1,5 +1,5 @@ import { multiaddr } from "@multiformats/multiaddr"; -import { Waku } from "js-waku"; +import type { WakuLight } from "js-waku/lib/interfaces"; function help(): string[] { return [ @@ -21,14 +21,17 @@ function nick( return [`New nick: ${nick}`]; } -function info(waku: Waku | undefined): string[] { +function info(waku: WakuLight | undefined): string[] { if (!waku) { return ["Waku node is starting"]; } 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) { 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 { +async function peers(waku: WakuLight | undefined): Promise { if (!waku) { return ["Waku node is starting"]; } @@ -77,7 +80,7 @@ async function peers(waku: Waku | undefined): Promise { return response; } -function connections(waku: Waku | undefined): string[] { +function connections(waku: WakuLight | undefined): string[] { if (!waku) { return ["Waku node is starting"]; } @@ -98,7 +101,7 @@ function connections(waku: Waku | undefined): string[] { export default async function handleCommand( input: string, - waku: Waku | undefined, + waku: WakuLight | undefined, setNick: (nick: string) => void ): Promise<{ command: string; response: string[] }> { let response: string[] = [];