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.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)
|
# [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",
|
"name": "@lumeweb/kernel-ipfs",
|
||||||
"version": "0.1.0-develop.6",
|
"version": "0.1.0-develop.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/kernel-ipfs",
|
"name": "@lumeweb/kernel-ipfs",
|
||||||
"version": "0.1.0-develop.6",
|
"version": "0.1.0-develop.5",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@helia/ipns": "^1.1.3",
|
"@helia/ipns": "^1.1.3",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/kernel-ipfs",
|
"name": "@lumeweb/kernel-ipfs",
|
||||||
"version": "0.1.0-develop.6",
|
"version": "0.1.0-develop.5",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"readme": "ERROR: No README data found!",
|
"readme": "ERROR: No README data found!",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
56
src/index.ts
56
src/index.ts
|
@ -43,7 +43,6 @@ onmessage = handleMessage;
|
||||||
const moduleDefer = defer();
|
const moduleDefer = defer();
|
||||||
let activeIpfsPeersDefer = defer();
|
let activeIpfsPeersDefer = defer();
|
||||||
let networkPeersAvailable = defer();
|
let networkPeersAvailable = defer();
|
||||||
let networkReady = true;
|
|
||||||
const networkRegistry = createNetworkRegistryClient();
|
const networkRegistry = createNetworkRegistryClient();
|
||||||
|
|
||||||
let swarm;
|
let swarm;
|
||||||
|
@ -59,7 +58,6 @@ BigInt.prototype.toJSON = function () {
|
||||||
|
|
||||||
addHandler("presentKey", handlePresentKey);
|
addHandler("presentKey", handlePresentKey);
|
||||||
addHandler("register", handleRegister);
|
addHandler("register", handleRegister);
|
||||||
addHandler("status", handleStatus, { receiveUpdates: true });
|
|
||||||
addHandler("ready", handleReady);
|
addHandler("ready", handleReady);
|
||||||
addHandler("stat", handleStat);
|
addHandler("stat", handleStat);
|
||||||
addHandler("ls", handleLs, { receiveUpdates: true });
|
addHandler("ls", handleLs, { receiveUpdates: true });
|
||||||
|
@ -96,7 +94,6 @@ async function handlePresentKey() {
|
||||||
if (!ipfs.libp2p.isStarted()) {
|
if (!ipfs.libp2p.isStarted()) {
|
||||||
await ipfs.start();
|
await ipfs.start();
|
||||||
networkPeersAvailable.resolve();
|
networkPeersAvailable.resolve();
|
||||||
networkReady = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -298,56 +295,3 @@ async function handleRegister(aq: ActiveQuery) {
|
||||||
|
|
||||||
aq.respond();
|
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