*Update dist

This commit is contained in:
Derrick Hammer 2023-02-16 21:48:11 -05:00
parent db894376eb
commit 3ede7224aa
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 38 additions and 5 deletions

6
dist/index.d.ts vendored
View File

@ -6,11 +6,15 @@ import type { EventEmitter } from "eventemitter3";
export declare class SwarmClient extends Client { export declare class SwarmClient extends Client {
private useDefaultSwarm; private useDefaultSwarm;
private id; private id;
constructor(useDefaultDht?: boolean); private _autoReconnect;
private _connectBackoff;
private _ready?;
constructor(useDefaultDht?: boolean, autoReconnect?: boolean);
get swarm(): number | undefined; get swarm(): number | undefined;
connect(pubkey: string | Uint8Array): Promise<Socket>; connect(pubkey: string | Uint8Array): Promise<Socket>;
init(): Promise<ErrTuple>; init(): Promise<ErrTuple>;
ready(): Promise<void>; ready(): Promise<void>;
start(): Promise<void>;
addRelay(pubkey: string): Promise<void>; addRelay(pubkey: string): Promise<void>;
removeRelay(pubkey: string): Promise<void>; removeRelay(pubkey: string): Promise<void>;
clearRelays(): Promise<void>; clearRelays(): Promise<void>;

2
dist/index.d.ts.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAW,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAoB,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,qBAAa,WAAY,SAAQ,MAAM;IACrC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,EAAE,CAAa;gBAEX,aAAa,UAAO;IAKhC,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAEY,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAa5D,IAAI,IAAI,OA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qC;gBAE7C,EAAE,EAAE,MAAM;IAKtB,OAAO,CAAC,gBAAgB,CAAC,CAAa;IAEtC,IAAI,eAAe,IAAI,UAAU,CAEhC;IAED,OAAO,CAAC,UAAU,CAAC,CAAa;IAEhC,IAAI,SAAS,IAAI,UAAU,CAE1B;IAEK,KAAK;IAOX,EAAE,CAAC,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EACnD,KAAK,EAAE,CAAC,EACR,EAAE,EAAE,YAAY,CAAC,aAAa,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EAClD,OAAO,CAAC,EAAE,GAAG,GACZ,IAAI;IAiBP,GAAG,CAAC,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EACpD,KAAK,EAAE,CAAC,EACR,EAAE,CAAC,EAAE,YAAY,CAAC,aAAa,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,EACnD,OAAO,CAAC,EAAE,GAAG,EACb,IAAI,CAAC,EAAE,OAAO,GACb,IAAI;IASP,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,GAAG,IAAI,IAAI;IAUX,OAAO,CAAC,WAAW;IAMnB,OAAO,CAAC,UAAU;CAInB;AAID,eAAO,MAAM,YAAY,+BAA4C,CAAC"}

35
dist/index.js vendored
View File

@ -1,11 +1,20 @@
import { Client, factory } from "@lumeweb/libkernel-universal"; import { Client, factory } from "@lumeweb/libkernel-universal";
import { hexToBuf } from "@siaweb/libweb"; import { hexToBuf } from "@siaweb/libweb";
import backoff from "backoff";
export class SwarmClient extends Client { export class SwarmClient extends Client {
useDefaultSwarm; useDefaultSwarm;
id = 0; id = 0;
constructor(useDefaultDht = true) { _autoReconnect;
_connectBackoff;
_ready;
constructor(useDefaultDht = true, autoReconnect = false) {
super(); super();
this.useDefaultSwarm = useDefaultDht; this.useDefaultSwarm = useDefaultDht;
this._autoReconnect = autoReconnect;
this._connectBackoff = backoff.fibonacci();
this._connectBackoff.on("ready", () => {
this.start();
});
} }
get swarm() { get swarm() {
return this.useDefaultSwarm ? undefined : this.id; return this.useDefaultSwarm ? undefined : this.id;
@ -22,13 +31,33 @@ export class SwarmClient extends Client {
return createSocket(resp.id); return createSocket(resp.id);
} }
async init() { async init() {
return this.callModuleReturn("init", { swarm: this.swarm }); const ret = await this.callModuleReturn("init", { swarm: this.swarm });
this._connectBackoff.reset();
return ret;
} }
async ready() { async ready() {
await this.callModuleReturn("ready", { swarm: this.swarm }); if (this._ready) {
return this._ready;
}
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
await this._ready;
this.connectModule("listenConnections", { swarm: this.swarm }, async (socketId) => { this.connectModule("listenConnections", { swarm: this.swarm }, async (socketId) => {
this.emit("connection", await createSocket(socketId)); this.emit("connection", await createSocket(socketId));
}); });
this._ready = undefined;
}
async start() {
let ready = this.ready();
const backoff = () => setImmediate(() => this._connectBackoff.backoff());
try {
await this.init();
}
catch (e) {
this.logErr(e);
backoff();
}
this.once("close", backoff);
await ready;
} }
async addRelay(pubkey) { async addRelay(pubkey) {
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm }); return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });