Compare commits

...

3 Commits

Author SHA1 Message Date
semantic-release-bot d87c589c3d chore(release): 0.1.0-develop.6 [skip ci]
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/kernel-ipfs/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-07-23)

### Features

* add status api ([16dcaaf](16dcaafd78))
2023-07-23 13:55:22 +00:00
Derrick Hammer 653833d552
Merge remote-tracking branch 'origin/develop' into develop 2023-07-23 09:53:28 -04:00
Derrick Hammer 16dcaafd78
feat: add status api 2023-07-23 09:53:21 -04:00
4 changed files with 66 additions and 3 deletions

View File

@ -1,3 +1,10 @@
# [0.1.0-develop.6](https://git.lumeweb.com/LumeWeb/kernel-ipfs/compare/v0.1.0-develop.5...v0.1.0-develop.6) (2023-07-23)
### Features
* add status api ([16dcaaf](https://git.lumeweb.com/LumeWeb/kernel-ipfs/commit/16dcaafd781ee3957a489c73b8027b2eabca648f))
# [0.1.0-develop.5](https://git.lumeweb.com/LumeWeb/kernel-ipfs/compare/v0.1.0-develop.4...v0.1.0-develop.5) (2023-07-23)
# [0.1.0-develop.4](https://git.lumeweb.com/LumeWeb/kernel-ipfs/compare/v0.1.0-develop.3...v0.1.0-develop.4) (2023-07-23)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@lumeweb/kernel-ipfs",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/kernel-ipfs",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"hasInstallScript": true,
"dependencies": {
"@helia/ipns": "^1.1.3",

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/kernel-ipfs",
"version": "0.1.0-develop.5",
"version": "0.1.0-develop.6",
"type": "module",
"readme": "ERROR: No README data found!",
"repository": {

View File

@ -43,6 +43,7 @@ onmessage = handleMessage;
const moduleDefer = defer();
let activeIpfsPeersDefer = defer();
let networkPeersAvailable = defer();
let networkReady = true;
const networkRegistry = createNetworkRegistryClient();
let swarm;
@ -58,6 +59,7 @@ BigInt.prototype.toJSON = function () {
addHandler("presentKey", handlePresentKey);
addHandler("register", handleRegister);
addHandler("status", handleStatus, { receiveUpdates: true });
addHandler("ready", handleReady);
addHandler("stat", handleStat);
addHandler("ls", handleLs, { receiveUpdates: true });
@ -94,6 +96,7 @@ async function handlePresentKey() {
if (!ipfs.libp2p.isStarted()) {
await ipfs.start();
networkPeersAvailable.resolve();
networkReady = true;
}
});
@ -295,3 +298,56 @@ async function handleRegister(aq: ActiveQuery) {
aq.respond();
}
async function handleStatus(aq: ActiveQuery) {
function sendUpdate() {
aq.sendUpdate({
peers: netPeers,
ready: netPeers > 0,
});
}
let netPeers = 0;
if (!networkReady) {
sendUpdate();
await ready();
getPeers();
}
function getPeers() {
netPeers = ipfs.libp2p.getPeers().length;
}
function peersListener() {
getPeers();
sendUpdate();
}
const peerEvents = ["connection:prune", "peer:connect", "peer:disconnect"];
peerEvents.forEach((ev) => {
// @ts-ignore
ipfs.libp2p.components.connectionManager.events.addEventListener(
ev,
peersListener,
);
});
// @ts-ignore
ipfs.libp2p.components.connectionManager.events.addEventListener(
"peer:disconnect",
peersListener,
);
aq.setReceiveUpdate?.(() => {
peerEvents.forEach((ev) => {
// @ts-ignore
ipfs.libp2p.components.connectionManager.events.removeEventListener(
ev,
peersListener,
);
});
aq.respond();
});
sendUpdate();
}