Compare commits
3 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | d87c589c3d | |
Derrick Hammer | 653833d552 | |
Derrick Hammer | 16dcaafd78 |
|
@ -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.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.5",
|
"version": "0.1.0-develop.6",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/kernel-ipfs",
|
"name": "@lumeweb/kernel-ipfs",
|
||||||
"version": "0.1.0-develop.5",
|
"version": "0.1.0-develop.6",
|
||||||
"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.5",
|
"version": "0.1.0-develop.6",
|
||||||
"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,6 +43,7 @@ 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;
|
||||||
|
@ -58,6 +59,7 @@ 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 });
|
||||||
|
@ -94,6 +96,7 @@ async function handlePresentKey() {
|
||||||
if (!ipfs.libp2p.isStarted()) {
|
if (!ipfs.libp2p.isStarted()) {
|
||||||
await ipfs.start();
|
await ipfs.start();
|
||||||
networkPeersAvailable.resolve();
|
networkPeersAvailable.resolve();
|
||||||
|
networkReady = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -295,3 +298,56 @@ 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