Compare commits
2 Commits
ae487a27e5
...
8061477c0b
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | 8061477c0b | |
Derrick Hammer | df63f8be30 |
|
@ -9,6 +9,7 @@ export declare class SwarmClient extends Client {
|
|||
private _autoReconnect;
|
||||
private _connectBackoff;
|
||||
private _ready?;
|
||||
private _topics;
|
||||
constructor(useDefaultDht?: boolean, autoReconnect?: boolean);
|
||||
get swarm(): number | undefined;
|
||||
connect(pubkey: string | Uint8Array): Promise<Socket>;
|
||||
|
@ -20,7 +21,7 @@ export declare class SwarmClient extends Client {
|
|||
removeRelay(pubkey: string): Promise<void>;
|
||||
clearRelays(): Promise<void>;
|
||||
getRelays(): Promise<string[]>;
|
||||
join(topic: Buffer): Promise<void>;
|
||||
join(topic: Buffer | Uint8Array): Promise<void>;
|
||||
}
|
||||
export declare class Socket extends Client {
|
||||
private id;
|
||||
|
@ -32,7 +33,9 @@ export declare class Socket extends Client {
|
|||
get rawStream(): Uint8Array;
|
||||
setup(): Promise<void>;
|
||||
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;
|
||||
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;
|
||||
end(): void;
|
||||
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,EA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,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,OAAO,CAAC,CAAC,SAAS,YAAY,CAAC,UAAU,CAAC,MAAM,GAAG,MAAM,CAAC,EACxD,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;IAIP,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"}
|
|
@ -8,6 +8,7 @@ export class SwarmClient extends Client {
|
|||
_autoReconnect;
|
||||
_connectBackoff;
|
||||
_ready;
|
||||
_topics = new Set();
|
||||
constructor(useDefaultDht = true, autoReconnect = false) {
|
||||
super();
|
||||
this.useDefaultSwarm = useDefaultDht;
|
||||
|
@ -42,6 +43,9 @@ export class SwarmClient extends Client {
|
|||
this._ready = this.callModuleReturn("ready", { swarm: this.swarm });
|
||||
await this._ready;
|
||||
this._ready = undefined;
|
||||
for (const topic of this._topics) {
|
||||
await this.join(topic);
|
||||
}
|
||||
}
|
||||
async start() {
|
||||
await this._connectBackoff.run(() => this.init());
|
||||
|
@ -70,6 +74,7 @@ export class SwarmClient extends Client {
|
|||
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
||||
}
|
||||
async join(topic) {
|
||||
this._topics.add(topic);
|
||||
this.callModule("join", { id: this.id, topic });
|
||||
}
|
||||
}
|
||||
|
@ -103,6 +108,9 @@ export class Socket extends Client {
|
|||
});
|
||||
return super.on(event, fn, context);
|
||||
}
|
||||
onSelf(event, fn, context) {
|
||||
return super.on(event, fn, context);
|
||||
}
|
||||
off(event, fn, context, once) {
|
||||
const updates = [...this.eventUpdates[event]];
|
||||
this.eventUpdates[event] = [];
|
||||
|
@ -111,6 +119,9 @@ export class Socket extends Client {
|
|||
}
|
||||
return super.off(event, fn, context, once);
|
||||
}
|
||||
offSelf(event, fn, context, once) {
|
||||
return super.off(event, fn, context, once);
|
||||
}
|
||||
write(message) {
|
||||
this.callModule("socketWrite", { id: this.id, message });
|
||||
}
|
||||
|
|
26
src/index.ts
26
src/index.ts
|
@ -15,6 +15,8 @@ export class SwarmClient extends Client {
|
|||
|
||||
private _ready?: Promise<void>;
|
||||
|
||||
private _topics: Set<Uint8Array> = new Set<Uint8Array>();
|
||||
|
||||
constructor(useDefaultDht = true, autoReconnect = false) {
|
||||
super();
|
||||
this.useDefaultSwarm = useDefaultDht;
|
||||
|
@ -57,6 +59,10 @@ export class SwarmClient extends Client {
|
|||
await this._ready;
|
||||
|
||||
this._ready = undefined;
|
||||
|
||||
for (const topic of this._topics) {
|
||||
await this.join(topic);
|
||||
}
|
||||
}
|
||||
|
||||
async start(): Promise<void> {
|
||||
|
@ -97,7 +103,8 @@ export class SwarmClient extends Client {
|
|||
return this.callModuleReturn("getRelays", { swarm: this.swarm });
|
||||
}
|
||||
|
||||
public async join(topic: Buffer): Promise<void> {
|
||||
public async join(topic: Buffer | Uint8Array): Promise<void> {
|
||||
this._topics.add(topic);
|
||||
this.callModule("join", { id: this.id, topic });
|
||||
}
|
||||
}
|
||||
|
@ -157,6 +164,14 @@ export class Socket extends Client {
|
|||
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>>(
|
||||
event: T,
|
||||
fn?: EventEmitter.EventListener<string | symbol, T>,
|
||||
|
@ -171,6 +186,15 @@ export class Socket extends Client {
|
|||
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 {
|
||||
this.callModule("socketWrite", { id: this.id, message });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue