Compare commits
No commits in common. "8061477c0bfc43ac18b9cbc954a19667b3f8a175" and "ae487a27e5ce0583652258672bf6f462e7f4698d" have entirely different histories.
8061477c0b
...
ae487a27e5
|
@ -9,7 +9,6 @@ export declare class SwarmClient extends Client {
|
||||||
private _autoReconnect;
|
private _autoReconnect;
|
||||||
private _connectBackoff;
|
private _connectBackoff;
|
||||||
private _ready?;
|
private _ready?;
|
||||||
private _topics;
|
|
||||||
constructor(useDefaultDht?: boolean, autoReconnect?: boolean);
|
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>;
|
||||||
|
@ -21,7 +20,7 @@ export declare class SwarmClient extends Client {
|
||||||
removeRelay(pubkey: string): Promise<void>;
|
removeRelay(pubkey: string): Promise<void>;
|
||||||
clearRelays(): Promise<void>;
|
clearRelays(): Promise<void>;
|
||||||
getRelays(): Promise<string[]>;
|
getRelays(): Promise<string[]>;
|
||||||
join(topic: Buffer | Uint8Array): Promise<void>;
|
join(topic: Buffer): Promise<void>;
|
||||||
}
|
}
|
||||||
export declare class Socket extends Client {
|
export declare class Socket extends Client {
|
||||||
private id;
|
private id;
|
||||||
|
@ -33,9 +32,7 @@ export declare class Socket extends Client {
|
||||||
get rawStream(): Uint8Array;
|
get rawStream(): Uint8Array;
|
||||||
setup(): Promise<void>;
|
setup(): Promise<void>;
|
||||||
on<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn: EventEmitter.EventListener<string | symbol, T>, context?: any): this;
|
on<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn: EventEmitter.EventListener<string | symbol, T>, context?: any): this;
|
||||||
onSelf<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn: EventEmitter.EventListener<string | symbol, T>, context?: any): this;
|
|
||||||
off<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn?: EventEmitter.EventListener<string | symbol, T>, context?: any, once?: boolean): this;
|
off<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn?: EventEmitter.EventListener<string | symbol, T>, context?: any, once?: boolean): this;
|
||||||
offSelf<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn?: EventEmitter.EventListener<string | symbol, T>, context?: any, once?: boolean): this;
|
|
||||||
write(message: string | Buffer): void;
|
write(message: string | Buffer): void;
|
||||||
end(): void;
|
end(): void;
|
||||||
private ensureEvent;
|
private ensureEvent;
|
||||||
|
|
|
@ -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,EAAU,QAAQ,EAAY,MAAM,gBAAgB,CAAC;AAE5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAKlD,qBAAa,WAAY,SAAQ,MAAM;IACrC,OAAO,CAAC,eAAe,CAAU;IACjC,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,eAAe,CAAM;IAE7B,OAAO,CAAC,MAAM,CAAC,CAAgB;IAE/B,OAAO,CAAC,OAAO,CAA0C;gBAE7C,aAAa,UAAO,EAAE,aAAa,UAAQ;IAUvD,IAAI,KAAK,IAAI,MAAM,GAAG,SAAS,CAE9B;IAEY,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAa5D,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC;IAGzB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAkBtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAUd,OAAO;IAaR,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIvC,WAAW,CA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extends Client {
|
||||||
_autoReconnect;
|
_autoReconnect;
|
||||||
_connectBackoff;
|
_connectBackoff;
|
||||||
_ready;
|
_ready;
|
||||||
_topics = new Set();
|
|
||||||
constructor(useDefaultDht = true, autoReconnect = false) {
|
constructor(useDefaultDht = true, autoReconnect = false) {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
|
@ -43,9 +42,6 @@ export class SwarmClient extends Client {
|
||||||
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
|
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
|
||||||
await this._ready;
|
await this._ready;
|
||||||
this._ready = undefined;
|
this._ready = undefined;
|
||||||
for (const topic of this._topics) {
|
|
||||||
await this.join(topic);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
async start() {
|
async start() {
|
||||||
await this._connectBackoff.run(() => this.init());
|
await this._connectBackoff.run(() => this.init());
|
||||||
|
@ -74,7 +70,6 @@ export class SwarmClient extends Client {
|
||||||
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
||||||
}
|
}
|
||||||
async join(topic) {
|
async join(topic) {
|
||||||
this._topics.add(topic);
|
|
||||||
this.callModule("join", { id: this.id, topic });
|
this.callModule("join", { id: this.id, topic });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,9 +103,6 @@ export class Socket extends Client {
|
||||||
});
|
});
|
||||||
return super.on(event, fn, context);
|
return super.on(event, fn, context);
|
||||||
}
|
}
|
||||||
onSelf(event, fn, context) {
|
|
||||||
return super.on(event, fn, context);
|
|
||||||
}
|
|
||||||
off(event, fn, context, once) {
|
off(event, fn, context, once) {
|
||||||
const updates = [...this.eventUpdates[event]];
|
const updates = [...this.eventUpdates[event]];
|
||||||
this.eventUpdates[event] = [];
|
this.eventUpdates[event] = [];
|
||||||
|
@ -119,9 +111,6 @@ export class Socket extends Client {
|
||||||
}
|
}
|
||||||
return super.off(event, fn, context, once);
|
return super.off(event, fn, context, once);
|
||||||
}
|
}
|
||||||
offSelf(event, fn, context, once) {
|
|
||||||
return super.off(event, fn, context, once);
|
|
||||||
}
|
|
||||||
write(message) {
|
write(message) {
|
||||||
this.callModule("socketWrite", { id: this.id, message });
|
this.callModule("socketWrite", { id: this.id, message });
|
||||||
}
|
}
|
||||||
|
|
26
src/index.ts
26
src/index.ts
|
@ -15,8 +15,6 @@ export class SwarmClient extends Client {
|
||||||
|
|
||||||
private _ready?: Promise<void>;
|
private _ready?: Promise<void>;
|
||||||
|
|
||||||
private _topics: Set<Uint8Array> = new Set<Uint8Array>();
|
|
||||||
|
|
||||||
constructor(useDefaultDht = true, autoReconnect = false) {
|
constructor(useDefaultDht = true, autoReconnect = false) {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
|
@ -59,10 +57,6 @@ export class SwarmClient extends Client {
|
||||||
await this._ready;
|
await this._ready;
|
||||||
|
|
||||||
this._ready = undefined;
|
this._ready = undefined;
|
||||||
|
|
||||||
for (const topic of this._topics) {
|
|
||||||
await this.join(topic);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(): Promise<void> {
|
async start(): Promise<void> {
|
||||||
|
@ -103,8 +97,7 @@ export class SwarmClient extends Client {
|
||||||
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async join(topic: Buffer | Uint8Array): Promise<void> {
|
public async join(topic: Buffer): Promise<void> {
|
||||||
this._topics.add(topic);
|
|
||||||
this.callModule("join", { id: this.id, topic });
|
this.callModule("join", { id: this.id, topic });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,14 +157,6 @@ export class Socket extends Client {
|
||||||
return super.on(event, fn, context) as this;
|
return super.on(event, fn, context) as this;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSelf<T extends EventEmitter.EventNames<string | symbol>>(
|
|
||||||
event: T,
|
|
||||||
fn: EventEmitter.EventListener<string | symbol, T>,
|
|
||||||
context?: any
|
|
||||||
): this {
|
|
||||||
return super.on(event, fn, context) as this;
|
|
||||||
}
|
|
||||||
|
|
||||||
off<T extends EventEmitter.EventNames<string | symbol>>(
|
off<T extends EventEmitter.EventNames<string | symbol>>(
|
||||||
event: T,
|
event: T,
|
||||||
fn?: EventEmitter.EventListener<string | symbol, T>,
|
fn?: EventEmitter.EventListener<string | symbol, T>,
|
||||||
|
@ -186,15 +171,6 @@ export class Socket extends Client {
|
||||||
return super.off(event, fn, context, once);
|
return super.off(event, fn, context, once);
|
||||||
}
|
}
|
||||||
|
|
||||||
offSelf<T extends EventEmitter.EventNames<string | symbol>>(
|
|
||||||
event: T,
|
|
||||||
fn?: EventEmitter.EventListener<string | symbol, T>,
|
|
||||||
context?: any,
|
|
||||||
once?: boolean
|
|
||||||
): this {
|
|
||||||
return super.off(event, fn, context, once);
|
|
||||||
}
|
|
||||||
|
|
||||||
write(message: string | Buffer): void {
|
write(message: string | Buffer): void {
|
||||||
this.callModule("socketWrite", { id: this.id, message });
|
this.callModule("socketWrite", { id: this.id, message });
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue