Compare commits
No commits in common. "v0.1.0-develop.6" and "v0.1.0-develop.5" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,10 +1,3 @@
|
|||
# [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)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@lumeweb/kernel-ipfs",
|
||||
"version": "0.1.0-develop.6",
|
||||
"version": "0.1.0-develop.5",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lumeweb/kernel-ipfs",
|
||||
"version": "0.1.0-develop.6",
|
||||
"version": "0.1.0-develop.5",
|
||||
"hasInstallScript": true,
|
||||
"dependencies": {
|
||||
"@helia/ipns": "^1.1.3",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/kernel-ipfs",
|
||||
"version": "0.1.0-develop.6",
|
||||
"version": "0.1.0-develop.5",
|
||||
"type": "module",
|
||||
"readme": "ERROR: No README data found!",
|
||||
"repository": {
|
||||
|
|
56
src/index.ts
56
src/index.ts
|
@ -43,7 +43,6 @@ onmessage = handleMessage;
|
|||
const moduleDefer = defer();
|
||||
let activeIpfsPeersDefer = defer();
|
||||
let networkPeersAvailable = defer();
|
||||
let networkReady = true;
|
||||
const networkRegistry = createNetworkRegistryClient();
|
||||
|
||||
let swarm;
|
||||
|
@ -59,7 +58,6 @@ 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 });
|
||||
|
@ -96,7 +94,6 @@ async function handlePresentKey() {
|
|||
if (!ipfs.libp2p.isStarted()) {
|
||||
await ipfs.start();
|
||||
networkPeersAvailable.resolve();
|
||||
networkReady = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -298,56 +295,3 @@ 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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue