Skip to content

Commit

Permalink
Clean up web-client NodeJS example
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Jul 10, 2024
1 parent e936073 commit 5b6a747
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web-client/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ to build the WASM files. Then go into `example/node` and run
yarn
```

to install the dependencies. Other package managers will also work, but the `preinstall` script uses `yarn`.
to install the dependencies. Other package managers will also work.

Once installation finishes, run the CommonJS example with

Expand Down
7 changes: 6 additions & 1 deletion web-client/example/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ async function main() {

const client = await Nimiq.Client.create(config.build());

let peerCount = 0;
client.addPeerChangedListener((_peerId, _reason, newPeerCount) => {
peerCount = newPeerCount;
})

setInterval(async () => {
const consensus = await client.isConsensusEstablished();
console.log(`Consensus ${consensus ? 'established' : 'not established'}`);
console.log(`Consensus ${consensus ? 'established' : 'not established'}, ${peerCount} peers`);
}, 1000);
}

Expand Down
7 changes: 6 additions & 1 deletion web-client/example/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ const config = new Nimiq.ClientConfiguration();

const client = await Nimiq.Client.create(config.build());

let peerCount = 0;
client.addPeerChangedListener((_peerId, _reason, newPeerCount) => {
peerCount = newPeerCount;
})

setInterval(async () => {
const consensus = await client.isConsensusEstablished();
console.log(`Consensus ${consensus ? 'established' : 'not established'}`);
console.log(`Consensus ${consensus ? 'established' : 'not established'}, ${peerCount} peers`);
}, 1000);
3 changes: 0 additions & 3 deletions web-client/example/node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@
"module": "index.mjs",
"dependencies": {
"@nimiq/core": "../../dist"
},
"scripts": {
"preinstall": "cd ../.. && ./scripts/build-launcher.sh"
}
}

0 comments on commit 5b6a747

Please sign in to comment.