*Update dist

This commit is contained in:
Derrick Hammer 2023-02-17 08:04:33 -05:00
parent 439bd9f022
commit 411582ef05
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 84 additions and 76 deletions

20
dist/index.d.ts vendored
View File

@ -3,18 +3,18 @@ import Hyperswarm from "hyperswarm";
import EventEmitter from "eventemitter2"; import EventEmitter from "eventemitter2";
export default class HyperswarmWeb extends EventEmitter { export default class HyperswarmWeb extends EventEmitter {
private _options; private _options;
private _relays;
private _activeRelay;
private _discovery; private _discovery;
private _queuedEmActions; private _queuedEmActions;
private _connectionMutex; private _connectionMutex;
constructor(opts?: any); constructor(opts?: any);
get activeRelay(): Hyperswarm; private _relays;
init(): Promise<void>;
private ensureConnection;
private isServerAvailable;
connect(pubkey: string, options?: {}): Promise<DhtNode>;
get relays(): string[]; get relays(): string[];
private _activeRelay;
get activeRelay(): Hyperswarm;
private _ready;
get ready(): boolean;
init(): Promise<void>;
connect(pubkey: string, options?: {}): Promise<DhtNode>;
addRelay(pubkey: string): Promise<void>; addRelay(pubkey: string): Promise<void>;
removeRelay(pubkey: string): boolean; removeRelay(pubkey: string): boolean;
clearRelays(): void; clearRelays(): void;
@ -24,8 +24,6 @@ export default class HyperswarmWeb extends EventEmitter {
removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this; removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
emit(eventName: string | symbol, ...args: any[]): boolean; emit(eventName: string | symbol, ...args: any[]): boolean;
once(eventName: string | symbol, listener: (...args: any[]) => void): this; once(eventName: string | symbol, listener: (...args: any[]) => void): this;
private _processOrQueueAction;
private _processQueuedActions;
join(topic: Uint8Array, opts?: {}): void; join(topic: Uint8Array, opts?: {}): void;
joinPeer(publicKey: Uint8Array): void; joinPeer(publicKey: Uint8Array): void;
leave(topic: Uint8Array): void; leave(topic: Uint8Array): void;
@ -34,5 +32,9 @@ export default class HyperswarmWeb extends EventEmitter {
topics(): string[]; topics(): string[];
flush(): Promise<any>; flush(): Promise<any>;
clear(): Promise<any>; clear(): Promise<any>;
private ensureConnection;
private isServerAvailable;
private _processOrQueueAction;
private _processQueuedActions;
} }
//# sourceMappingURL=index.d.ts.map //# sourceMappingURL=index.d.ts.map

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

@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAW5C,OAAO,UAAU,MAAM,YAAY,CAAC;AAEpC,OAAO,YAAY,MAAM,eAAe,CAAC;AAGzC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,YAAY;IACrD,OAAO,CAAC,QAAQ,CAAM;IACtB,OAAO,CAAC,OAAO,CAA0B;IACzC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,gBAAgB,CAAuB;IAE/C,OAAO,CAAC,gBAAgB,CAAsB;gBAClC,IAAI,GAAE,GAAQ;IAO1B,IAAI,WAAW,IAAI,UAAU,CAE5B;IAED,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;YAIP,gBAAgB;YAmEhB,iBAAiB;IAYzB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC;IAQ7D,IAAI,MAAM,IAAI,MAAM,EAAE,CAErB;IAEY,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI7C,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO;IAUpC,WAAW,IAAI,IAAI;IAI1B,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,UAAU;IAGb,WAAW,CACT,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,K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AAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,IAAI;IAInE,IAAI,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,KAAK,GAAG,IAAI;IAIxC,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAIrC,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAI9B,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAItC,MAAM,CAAC,SAAS,EAAE,UAAU;IAI5B,MAAM,IAAI,MAAM,EAAE;IAIZ,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;IAIrB,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;YAIpB,gBAAgB;YAqEhB,iBAAiB;IAa/B,OAAO,CAAC,qBAAqB;IAS7B,OAAO,CAAC,qBAAqB;CAO9B"}

138
dist/index.js vendored
View File

@ -11,8 +11,6 @@ import EventEmitter from "eventemitter2";
import { Mutex } from "async-mutex"; import { Mutex } from "async-mutex";
export default class HyperswarmWeb extends EventEmitter { export default class HyperswarmWeb extends EventEmitter {
_options; _options;
_relays = new Set();
_activeRelay;
_discovery; _discovery;
_queuedEmActions = []; _queuedEmActions = [];
_connectionMutex = new Mutex(); _connectionMutex = new Mutex();
@ -22,12 +20,82 @@ export default class HyperswarmWeb extends EventEmitter {
this._options = opts; this._options = opts;
this._discovery = createClient(); this._discovery = createClient();
} }
_relays = new Set();
get relays() {
return [...this._relays.values()];
}
_activeRelay;
get activeRelay() { get activeRelay() {
return this._activeRelay; return this._activeRelay;
} }
_ready = false;
get ready() {
return this._ready;
}
init() { init() {
return this.ensureConnection(); return this.ensureConnection();
} }
async connect(pubkey, options = {}) {
if (!this._activeRelay) {
await this.ensureConnection();
}
return this._activeRelay.connect(pubkey, options);
}
async addRelay(pubkey) {
this._relays.add(pubkey);
}
removeRelay(pubkey) {
if (!this._relays.has(pubkey)) {
return false;
}
this._relays.delete(pubkey);
return true;
}
clearRelays() {
this._relays.clear();
}
on(eventName, listener) {
return this._processOrQueueAction("on", ...arguments);
}
addListener(eventName, listener) {
return this.on(eventName, listener);
}
off(eventName, listener) {
return this._processOrQueueAction("off", ...arguments);
}
removeListener(eventName, listener) {
return this.off(eventName, listener);
}
emit(eventName, ...args) {
return this._processOrQueueAction("emit", ...arguments);
}
once(eventName, listener) {
return this._processOrQueueAction("once", ...arguments);
}
join(topic, opts = {}) {
return this._processOrQueueAction("join", ...arguments);
}
joinPeer(publicKey) {
return this._processOrQueueAction("joinPeer", ...arguments);
}
leave(topic) {
return this._processOrQueueAction("leave", ...arguments);
}
leavePeer(publicKey) {
return this._processOrQueueAction("leavePeer", ...arguments);
}
status(publicKey) {
return this._activeRelay?.status(publicKey);
}
topics() {
return this._activeRelay?.topics();
}
async flush() {
return this._activeRelay?.flush();
}
async clear() {
return this._activeRelay?.clear();
}
async ensureConnection() { async ensureConnection() {
const logErr = (await load()).logErr; const logErr = (await load()).logErr;
await this._connectionMutex.waitForUnlock(); await this._connectionMutex.waitForUnlock();
@ -65,6 +133,7 @@ export default class HyperswarmWeb extends EventEmitter {
}); });
this._activeRelay.on("close", () => { this._activeRelay.on("close", () => {
this._activeRelay = undefined; this._activeRelay = undefined;
this._ready = false;
}); });
} while (relays.length > 0 && !this._activeRelay); } while (relays.length > 0 && !this._activeRelay);
} }
@ -75,6 +144,7 @@ export default class HyperswarmWeb extends EventEmitter {
this._processQueuedActions(); this._processQueuedActions();
await this._activeRelay.dht.ready(); await this._activeRelay.dht.ready();
this._connectionMutex.release(); this._connectionMutex.release();
this._ready = true;
this.emit("ready"); this.emit("ready");
} }
async isServerAvailable(connection) { async isServerAvailable(connection) {
@ -89,46 +159,6 @@ export default class HyperswarmWeb extends EventEmitter {
}); });
}); });
} }
async connect(pubkey, options = {}) {
if (!this._activeRelay) {
await this.ensureConnection();
}
return this._activeRelay.connect(pubkey, options);
}
get relays() {
return [...this._relays.values()];
}
async addRelay(pubkey) {
this._relays.add(pubkey);
}
removeRelay(pubkey) {
if (!this._relays.has(pubkey)) {
return false;
}
this._relays.delete(pubkey);
return true;
}
clearRelays() {
this._relays.clear();
}
on(eventName, listener) {
return this._processOrQueueAction("on", ...arguments);
}
addListener(eventName, listener) {
return this.on(eventName, listener);
}
off(eventName, listener) {
return this._processOrQueueAction("off", ...arguments);
}
removeListener(eventName, listener) {
return this.off(eventName, listener);
}
emit(eventName, ...args) {
return this._processOrQueueAction("emit", ...arguments);
}
once(eventName, listener) {
return this._processOrQueueAction("once", ...arguments);
}
_processOrQueueAction(method, ...args) { _processOrQueueAction(method, ...args) {
if (this._activeRelay) { if (this._activeRelay) {
return this._activeRelay[method](...args); return this._activeRelay[method](...args);
@ -142,28 +172,4 @@ export default class HyperswarmWeb extends EventEmitter {
} }
this._queuedEmActions = []; this._queuedEmActions = [];
} }
join(topic, opts = {}) {
return this._processOrQueueAction("join", ...arguments);
}
joinPeer(publicKey) {
return this._processOrQueueAction("joinPeer", ...arguments);
}
leave(topic) {
return this._processOrQueueAction("leave", ...arguments);
}
leavePeer(publicKey) {
return this._processOrQueueAction("leavePeer", ...arguments);
}
status(publicKey) {
return this._activeRelay?.status(publicKey);
}
topics() {
return this._activeRelay?.topics();
}
async flush() {
return this._activeRelay?.flush();
}
async clear() {
return this._activeRelay?.clear();
}
} }