Compare commits
3 Commits
v0.0.2-dev
...
v0.0.2-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | ee359bfefe | |
Derrick Hammer | 365d54e844 | |
Derrick Hammer | bae26a3e01 |
|
@ -1,3 +1,5 @@
|
||||||
|
## [0.0.2-develop.7](https://git.lumeweb.com/LumeWeb/hyperswarm-web/compare/v0.0.2-develop.6...v0.0.2-develop.7) (2023-07-03)
|
||||||
|
|
||||||
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/hyperswarm-web/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-02)
|
## [0.0.2-develop.6](https://git.lumeweb.com/LumeWeb/hyperswarm-web/compare/v0.0.2-develop.5...v0.0.2-develop.6) (2023-07-02)
|
||||||
|
|
||||||
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/hyperswarm-web/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-01)
|
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/hyperswarm-web/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-07-01)
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/hyperswarm-web",
|
"name": "@lumeweb/hyperswarm-web",
|
||||||
"version": "0.0.2-develop.6",
|
"version": "0.0.2-develop.7",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/hyperswarm-web",
|
"name": "@lumeweb/hyperswarm-web",
|
||||||
"version": "0.0.2-develop.6",
|
"version": "0.0.2-develop.7",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@hyperswarm/dht-relay": "^0.4.1",
|
"@hyperswarm/dht-relay": "^0.4.1",
|
||||||
"@lumeweb/kernel-peer-discovery-client": "^0.0.2-develop.5",
|
"@lumeweb/kernel-peer-discovery-client": "^0.0.2-develop.5",
|
||||||
"@lumeweb/libkernel": "0.1.0-develop.7",
|
"@lumeweb/libkernel": "0.1.0-develop.7",
|
||||||
"async-mutex": "^0.4.0",
|
"async-mutex": "^0.4.0",
|
||||||
|
"emittery": "^1.0.1",
|
||||||
"eventemitter2": "^6.4.9",
|
"eventemitter2": "^6.4.9",
|
||||||
"hyperswarm": "^4.5.1",
|
"hyperswarm": "^4.5.1",
|
||||||
"random-number-csprng": "^1.0.2"
|
"random-number-csprng": "^1.0.2"
|
||||||
|
@ -1849,17 +1850,6 @@
|
||||||
"@noble/hashes": "^1.3.1"
|
"@noble/hashes": "^1.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/kernel-peer-discovery-client/node_modules/emittery": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/emittery/-/emittery-1.0.1.tgz",
|
|
||||||
"integrity": "sha512-2ID6FdrMD9KDLldGesP6317G78K7km/kMcwItRtVFva7I/cSEOIaLpewaUb+YLXVwdAp3Ctfxh/V5zIl1sj7dQ==",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=14.16"
|
|
||||||
},
|
|
||||||
"funding": {
|
|
||||||
"url": "https://github.com/sindresorhus/emittery?sponsor=1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@lumeweb/kernel-peer-discovery-client/node_modules/sodium-native": {
|
"node_modules/@lumeweb/kernel-peer-discovery-client/node_modules/sodium-native": {
|
||||||
"version": "3.4.1",
|
"version": "3.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-3.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/sodium-native/-/sodium-native-3.4.1.tgz",
|
||||||
|
@ -5933,12 +5923,11 @@
|
||||||
"peer": true
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/emittery": {
|
"node_modules/emittery": {
|
||||||
"version": "0.13.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/emittery/-/emittery-0.13.1.tgz",
|
"resolved": "https://registry.npmjs.org/emittery/-/emittery-1.0.1.tgz",
|
||||||
"integrity": "sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==",
|
"integrity": "sha512-2ID6FdrMD9KDLldGesP6317G78K7km/kMcwItRtVFva7I/cSEOIaLpewaUb+YLXVwdAp3Ctfxh/V5zIl1sj7dQ==",
|
||||||
"peer": true,
|
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=12"
|
"node": ">=14.16"
|
||||||
},
|
},
|
||||||
"funding": {
|
"funding": {
|
||||||
"url": "https://github.com/sindresorhus/emittery?sponsor=1"
|
"url": "https://github.com/sindresorhus/emittery?sponsor=1"
|
||||||
|
@ -9335,6 +9324,18 @@
|
||||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/jest-runner/node_modules/emittery": {
|
||||||
|
"version": "0.13.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/emittery/-/emittery-0.13.1.tgz",
|
||||||
|
"integrity": "sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==",
|
||||||
|
"peer": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sindresorhus/emittery?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/jest-runtime": {
|
"node_modules/jest-runtime": {
|
||||||
"version": "29.5.0",
|
"version": "29.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/jest-runtime/-/jest-runtime-29.5.0.tgz",
|
||||||
|
@ -9467,6 +9468,18 @@
|
||||||
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
"node": "^14.15.0 || ^16.10.0 || >=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/jest-watcher/node_modules/emittery": {
|
||||||
|
"version": "0.13.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/emittery/-/emittery-0.13.1.tgz",
|
||||||
|
"integrity": "sha512-DeWwawk6r5yR9jFgnDKYt4sLS0LmHJJi3ZOnb5/JdbYwj3nW+FxQnHIjhBKz8YLC7oRNPVM9NQ47I3CVx34eqQ==",
|
||||||
|
"peer": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sindresorhus/emittery?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/jest-worker": {
|
"node_modules/jest-worker": {
|
||||||
"version": "29.5.0",
|
"version": "29.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.5.0.tgz",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/hyperswarm-web",
|
"name": "@lumeweb/hyperswarm-web",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.0.2-develop.6",
|
"version": "0.0.2-develop.7",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -30,6 +30,7 @@
|
||||||
"@lumeweb/kernel-peer-discovery-client": "^0.0.2-develop.5",
|
"@lumeweb/kernel-peer-discovery-client": "^0.0.2-develop.5",
|
||||||
"@lumeweb/libkernel": "0.1.0-develop.7",
|
"@lumeweb/libkernel": "0.1.0-develop.7",
|
||||||
"async-mutex": "^0.4.0",
|
"async-mutex": "^0.4.0",
|
||||||
|
"emittery": "^1.0.1",
|
||||||
"eventemitter2": "^6.4.9",
|
"eventemitter2": "^6.4.9",
|
||||||
"hyperswarm": "^4.5.1",
|
"hyperswarm": "^4.5.1",
|
||||||
"random-number-csprng": "^1.0.2"
|
"random-number-csprng": "^1.0.2"
|
||||||
|
|
23
src/index.ts
23
src/index.ts
|
@ -10,11 +10,11 @@ import type {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import Hyperswarm from "hyperswarm";
|
import Hyperswarm from "hyperswarm";
|
||||||
import randomNumber from "random-number-csprng";
|
import randomNumber from "random-number-csprng";
|
||||||
import EventEmitter, { OnOptions } from "eventemitter2";
|
|
||||||
import { Mutex } from "async-mutex";
|
import { Mutex } from "async-mutex";
|
||||||
import { logErr } from "@lumeweb/libkernel";
|
import { logErr } from "@lumeweb/libkernel";
|
||||||
|
import Emittery from "emittery";
|
||||||
|
|
||||||
export default class HyperswarmWeb extends EventEmitter.default {
|
export default class HyperswarmWeb extends Emittery {
|
||||||
private _options: any;
|
private _options: any;
|
||||||
private _discovery: PeerDiscoveryClient;
|
private _discovery: PeerDiscoveryClient;
|
||||||
private _queuedEmActions: [string, any][] = [];
|
private _queuedEmActions: [string, any][] = [];
|
||||||
|
@ -75,6 +75,7 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
this._relays.clear();
|
this._relays.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
on(
|
on(
|
||||||
eventName: string | symbol,
|
eventName: string | symbol,
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
|
@ -85,9 +86,8 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
onSelf(
|
onSelf(
|
||||||
eventName: string | symbol,
|
eventName: string | symbol,
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
options?: boolean | OnOptions,
|
|
||||||
): Hyperswarm {
|
): Hyperswarm {
|
||||||
return super.on(eventName, listener, options);
|
return super.on(eventName, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
addListener(
|
addListener(
|
||||||
|
@ -97,6 +97,7 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
return this.on(eventName, listener);
|
return this.on(eventName, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
off(
|
off(
|
||||||
eventName: string | symbol,
|
eventName: string | symbol,
|
||||||
listener: (...args: any[]) => void,
|
listener: (...args: any[]) => void,
|
||||||
|
@ -118,14 +119,16 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
return this.off(eventName, listener);
|
return this.off(eventName, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
emit(eventName: string | symbol, ...args: any[]): boolean {
|
emit(eventName: string | symbol, ...args: any[]): boolean {
|
||||||
return this._processOrQueueAction("emit", ...arguments);
|
return this._processOrQueueAction("emit", ...arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
emitSelf(eventName: string | symbol, ...args: any[]): boolean {
|
async emitSelf(eventName: string | symbol, ...args: any): Promise<void> {
|
||||||
return super.emit(eventName, ...args);
|
return super.emit(eventName, { ...args });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
once(eventName: string | symbol, listener: (...args: any[]) => void): this {
|
once(eventName: string | symbol, listener: (...args: any[]) => void): this {
|
||||||
return this._processOrQueueAction("once", ...arguments);
|
return this._processOrQueueAction("once", ...arguments);
|
||||||
}
|
}
|
||||||
|
@ -216,10 +219,10 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
keyPair: this._options.keyPair,
|
keyPair: this._options.keyPair,
|
||||||
});
|
});
|
||||||
|
|
||||||
this._activeRelay.dht._protocol._stream.once("close", () => {
|
this._activeRelay.dht._protocol._stream.once("close", async () => {
|
||||||
this._activeRelay = undefined;
|
this._activeRelay = undefined;
|
||||||
this._ready = false;
|
this._ready = false;
|
||||||
this.emitSelf("close");
|
await this.emitSelf("close");
|
||||||
});
|
});
|
||||||
} while (relays.length > 0 && !this._activeRelay);
|
} while (relays.length > 0 && !this._activeRelay);
|
||||||
}
|
}
|
||||||
|
@ -229,14 +232,14 @@ export default class HyperswarmWeb extends EventEmitter.default {
|
||||||
throw new Error("Failed to find an available relay");
|
throw new Error("Failed to find an available relay");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.emitSelf("init");
|
await this.emitSelf("init");
|
||||||
|
|
||||||
this._processQueuedActions();
|
this._processQueuedActions();
|
||||||
await this._activeRelay.dht.ready();
|
await this._activeRelay.dht.ready();
|
||||||
this._connectionMutex.release();
|
this._connectionMutex.release();
|
||||||
|
|
||||||
this._ready = true;
|
this._ready = true;
|
||||||
this.emit("ready");
|
await this.emit("ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async isServerAvailable(connection: string): Promise<boolean> {
|
private async isServerAvailable(connection: string): Promise<boolean> {
|
||||||
|
|
Loading…
Reference in New Issue