From 1a813256e930405c224b4abc1a1ff003d566fee1 Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 15 Apr 2021 13:48:49 +1000 Subject: [PATCH] Start Waku first So that even if the user does not enter a nick, the chat app already acts as a waku node. --- src/chat/index.ts | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/chat/index.ts b/src/chat/index.ts index c555c5db43..2c01b6d3e7 100644 --- a/src/chat/index.ts +++ b/src/chat/index.ts @@ -15,21 +15,31 @@ const ChatContentTopic = 'dingpu'; (async function () { const opts = processArguments(); + const waku = await Waku.create({ listenAddresses: [opts.listenAddr] }); + console.log('Waku started'); + // TODO: Automatically subscribe, tracked with + // https://github.com/status-im/js-waku/issues/17 + await waku.relay.subscribe(); + console.log('Subscribed to waku relay'); + + if (opts.staticNode) { + console.log(`dialing ${opts.staticNode}`); + await waku.dial(opts.staticNode); + } + const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); const question = util.promisify(rl.question).bind(rl); - // Looks like wrong type definition of promisify is picked. // May be related to https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20497 const nick = ((await question( 'Please choose a nickname: ' )) as unknown) as string; - console.log(`Hi ${nick}!`); - const waku = await Waku.create({ listenAddresses: [opts.listenAddr] }); + console.log(`Hi, ${nick}!`); // TODO: Bubble event to waku, infer topic, decode msg // Tracked with https://github.com/status-im/js-waku/issues/19 @@ -41,18 +51,6 @@ const ChatContentTopic = 'dingpu'; } }); - console.log('Waku started'); - - if (opts.staticNode) { - console.log(`dialing ${opts.staticNode}`); - await waku.dial(opts.staticNode); - } - - // TODO: Automatically subscribe, tracked with - // https://github.com/status-im/js-waku/issues/17 - await waku.relay.subscribe(); - console.log('Subscribed to waku relay'); - const staticNodeId = opts.staticNode?.getPeerId(); if (staticNodeId) { const storePeerId = PeerId.createFromB58String(staticNodeId);