mirror of https://github.com/waku-org/js-waku.git
Get peer connection details from command line
This commit is contained in:
parent
c3cf6462cc
commit
b4e5d6d93c
|
@ -6,8 +6,9 @@ import readline from 'readline';
|
|||
import { delay } from '../build/main/test_utils/delay';
|
||||
|
||||
;(async function() {
|
||||
const opts = processArguments();
|
||||
|
||||
const waku = await Waku.create({listenAddresses: ['/ip4/0.0.0.0/tcp/55123']});
|
||||
const waku = await Waku.create({ listenAddresses: ['/ip4/0.0.0.0/tcp/55123'] });
|
||||
|
||||
// TODO: Bubble event to waku, infere topic, decode msg
|
||||
waku.libp2p.pubsub.on(TOPIC, event => {
|
||||
|
@ -16,17 +17,12 @@ import { delay } from '../build/main/test_utils/delay';
|
|||
});
|
||||
|
||||
console.log('Waku started');
|
||||
// Status static node
|
||||
await waku.dial('/ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ');
|
||||
|
||||
// Richard's node
|
||||
// await waku.dial('/ip4/134.209.113.86/tcp/9000/p2p/16Uiu2HAmVVi6Q4j7MAKVibquW8aA27UNrA4Q8Wkz9EetGViu8ZF1');
|
||||
|
||||
// await waku.dial('/ip4/0.0.0.0/tcp/60000/p2p/16Uiu2HAmDVYacyxN4t1SYBhRSTDr6nmYwuY6qWWTgagZm558rFA6')
|
||||
|
||||
await delay(100);
|
||||
|
||||
console.log('Static node has been dialed');
|
||||
if (opts.staticNode) {
|
||||
console.log(`dialing ${opts.staticNode}`);
|
||||
await waku.dial(opts.staticNode);
|
||||
await delay(100);
|
||||
}
|
||||
|
||||
await new Promise((resolve) =>
|
||||
waku.libp2p.pubsub.once('gossipsub:heartbeat', resolve)
|
||||
|
@ -48,9 +44,32 @@ import { delay } from '../build/main/test_utils/delay';
|
|||
console.log('Ready to chat!');
|
||||
rl.prompt();
|
||||
rl.on('line', async (line) => {
|
||||
rl.prompt();
|
||||
const msg = Message.fromUtf8String('(js-chat) ' + line);
|
||||
await waku.relay.publish(msg);
|
||||
rl.prompt();
|
||||
const msg = Message.fromUtf8String('(js-chat) ' + line);
|
||||
await waku.relay.publish(msg);
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
interface Options {
|
||||
staticNode?: string;
|
||||
}
|
||||
|
||||
function processArguments(): Options {
|
||||
let passedArgs = process.argv.slice(2);
|
||||
|
||||
let opts: Options = {};
|
||||
|
||||
while (passedArgs.length) {
|
||||
const arg = passedArgs.shift();
|
||||
switch (arg) {
|
||||
case '--staticNode':
|
||||
opts = Object.assign(opts, { staticNode: passedArgs.shift() });
|
||||
break;
|
||||
default:
|
||||
console.log(`Argument ignored: ${arg}`);
|
||||
}
|
||||
}
|
||||
|
||||
return opts;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue