diff --git a/examples/waku-node/index.mjs b/examples/waku-node/index.mjs new file mode 100644 index 0000000000..7f330a9a2a --- /dev/null +++ b/examples/waku-node/index.mjs @@ -0,0 +1,35 @@ +import Bootstrap from 'libp2p-bootstrap'; +import PeerId from 'peer-id'; +import { Waku } from 'js-waku'; +import WebRTCDirect from 'libp2p-webrtc-direct'; + +; +(async () => { + + const hardcodedPeerId = await PeerId.createFromJSON({ + 'id': '12D3KooWCuo3MdXfMgaqpLC5Houi1TRoFqgK9aoxok4NK5udMu8m', + 'privKey': 'CAESQAG6Ld7ev6nnD0FKPs033/j0eQpjWilhxnzJ2CCTqT0+LfcWoI2Vr+zdc1vwk7XAVdyoCa2nwUR3RJebPWsF1/I=', + 'pubKey': 'CAESIC33FqCNla/s3XNb8JO1wFXcqAmtp8FEd0SXmz1rBdfy' + }); + + const waku = await Waku.create({ + libp2p: { + peerId: hardcodedPeerId, + addresses: { + listen: ['/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct'] + }, + modules: { + transport: [WebRTCDirect] + }, + } + }); + + waku.libp2p.connectionManager.on('peer:connect', (connection) => { + console.info(`Connected to ${connection.remotePeer.toB58String()}!`); + }); + + console.log('Listening on:'); + waku.libp2p.multiaddrs.forEach((ma) => console.log(`${ma.toString()}/p2p/${waku.libp2p.peerId.toB58String()}`)); + +})(); + diff --git a/examples/waku-node/package-lock.json b/examples/waku-node/package-lock.json new file mode 100644 index 0000000000..ab0cf63924 --- /dev/null +++ b/examples/waku-node/package-lock.json @@ -0,0 +1,29 @@ +{ + "name": "@waku/node", + "version": "1.0.0", + "lockfileVersion": 2, + "requires": true, + "packages": { + "": { + "name": "@waku/node", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "js-waku": "file:../../build/main" + } + }, + "../../build/esm": { + "extraneous": true + }, + "../../build/main": {}, + "node_modules/js-waku": { + "resolved": "../../build/main", + "link": true + } + }, + "dependencies": { + "js-waku": { + "version": "file:../../build/main" + } + } +} diff --git a/examples/waku-node/package.json b/examples/waku-node/package.json index 67bd413cc8..59de54c9d7 100644 --- a/examples/waku-node/package.json +++ b/examples/waku-node/package.json @@ -3,9 +3,14 @@ "version": "1.0.0", "description": "", "main": "index.js", + "private": true, "scripts": { + "start": "node ./index.mjs", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", - "license": "ISC" + "license": "MIT OR Apache-2.0", + "dependencies": { + "js-waku": "file:../../build/main" + } } diff --git a/examples/web-chat/src/App.tsx b/examples/web-chat/src/App.tsx index 8eccafb12d..1cf3cf0d86 100644 --- a/examples/web-chat/src/App.tsx +++ b/examples/web-chat/src/App.tsx @@ -1,18 +1,13 @@ import { useEffect, useReducer, useState } from "react"; import "./App.css"; -import { - PageDirection, - getPredefinedBootstrapNodes, - Waku, - WakuMessage, -} from "js-waku"; +import { PageDirection, Waku, WakuMessage } from "js-waku"; import handleCommand from "./command"; import Room from "./Room"; import { WakuContext } from "./WakuContext"; import { ThemeProvider } from "@livechat/ui-kit"; import { generate } from "server-name-generator"; import { Message } from "./Message"; -import { Fleet } from "js-waku/lib/discovery/predefined"; +import { Protocols } from "js-waku/lib/waku"; const themes = { AuthorName: { @@ -130,8 +125,7 @@ export default function App() { if (historicalMessagesRetrieved) return; const retrieveMessages = async () => { - await waku.waitForRemotePeer(); - console.log(`Retrieving archived messages`); + await waku.waitForRemotePeer([Protocols.Relay]); try { retrieveStoreMessages(waku, dispatchMessages).then((length) => { @@ -185,7 +179,9 @@ async function initWaku(setter: (waku: Waku) => void) { }, }, bootstrap: { - peers: getPredefinedBootstrapNodes(selectFleetEnv()), + peers: [ + `/ip4/127.0.0.1/tcp/9090/http/p2p-webrtc-direct/p2p/12D3KooWCuo3MdXfMgaqpLC5Houi1TRoFqgK9aoxok4NK5udMu8m`, + ], }, }); @@ -195,15 +191,6 @@ async function initWaku(setter: (waku: Waku) => void) { } } -function selectFleetEnv() { - // Works with react-scripts - if (process?.env?.NODE_ENV === "development") { - return Fleet.Test; - } else { - return Fleet.Prod; - } -} - function reduceMessages(state: Message[], newMessages: Message[]) { return state.concat(newMessages); } diff --git a/package.json b/package.json index 8aac6cb2f8..9ecc404957 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "exports": "./", "repository": "https://github.com/status-im/js-waku", "license": "MIT OR Apache-2.0", + "exports": "./", "keywords": [ "waku", "decentralised",