*Update dist
This commit is contained in:
parent
875ba862f0
commit
d4df7d45c3
|
@ -2,6 +2,7 @@
|
||||||
import { Buffer } from "buffer";
|
import { Buffer } from "buffer";
|
||||||
import { Client } from "@lumeweb/libkernel-universal";
|
import { Client } from "@lumeweb/libkernel-universal";
|
||||||
import { ErrTuple } from "@siaweb/libweb";
|
import { ErrTuple } from "@siaweb/libweb";
|
||||||
|
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;
|
||||||
|
@ -9,7 +10,7 @@ export declare class SwarmClient extends Client {
|
||||||
constructor(useDefaultDht?: boolean);
|
constructor(useDefaultDht?: boolean);
|
||||||
connect(pubkey: string | Uint8Array): Promise<Socket>;
|
connect(pubkey: string | Uint8Array): Promise<Socket>;
|
||||||
init(): Promise<ErrTuple>;
|
init(): Promise<ErrTuple>;
|
||||||
ready(): Promise<ErrTuple>;
|
ready(): 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>;
|
||||||
|
@ -20,8 +21,8 @@ export declare class Socket extends Client {
|
||||||
private id;
|
private id;
|
||||||
private eventUpdates;
|
private eventUpdates;
|
||||||
constructor(id: number);
|
constructor(id: number);
|
||||||
on(eventName: string, listener: (...args: any[]) => void): this;
|
on<T extends EventEmitter.EventNames<string | symbol>>(event: T, fn: EventEmitter.EventListener<string | symbol, T>, context?: any): this;
|
||||||
off(type: string, listener: any): this;
|
off<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 ens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U,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"}
|
|
@ -25,7 +25,10 @@ export class SwarmClient extends Client {
|
||||||
return this.callModuleReturn("init", { swarm: this.swarm });
|
return this.callModuleReturn("init", { swarm: this.swarm });
|
||||||
}
|
}
|
||||||
async ready() {
|
async ready() {
|
||||||
return this.callModuleReturn("ready", { swarm: this.swarm });
|
await this.callModuleReturn("ready", { swarm: this.swarm });
|
||||||
|
this.connectModule("listenConnections", { swarm: this.swarm }, (socketId) => {
|
||||||
|
this.emit("connection", createSocket(socketId));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
|
return this.callModuleReturn("addRelay", { pubkey, swarm: this.swarm });
|
||||||
|
@ -50,23 +53,23 @@ export class Socket extends Client {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
on(eventName, listener) {
|
on(event, fn, context) {
|
||||||
const [update, promise] = this.connectModule("listenSocketEvent", { id: this.id, event: eventName }, (data) => {
|
const [update, promise] = this.connectModule("listenSocketEvent", { id: this.id, event: event }, (data) => {
|
||||||
this.emit(eventName, data);
|
this.emit(event, data);
|
||||||
});
|
});
|
||||||
this.trackEvent(eventName, update);
|
this.trackEvent(event, update);
|
||||||
promise.then(() => {
|
promise.then(() => {
|
||||||
this.off(eventName, listener);
|
this.off(event, fn);
|
||||||
});
|
});
|
||||||
return super.on(eventName, listener);
|
return super.on(event, fn, context);
|
||||||
}
|
}
|
||||||
off(type, listener) {
|
off(event, fn, context, once) {
|
||||||
const updates = [...this.eventUpdates[type]];
|
const updates = [...this.eventUpdates[event]];
|
||||||
this.eventUpdates[type] = [];
|
this.eventUpdates[event] = [];
|
||||||
for (const func of updates) {
|
for (const func of updates) {
|
||||||
func({ action: "off" });
|
func();
|
||||||
}
|
}
|
||||||
return super.off(type, listener);
|
return super.off(event, fn, context, once);
|
||||||
}
|
}
|
||||||
write(message) {
|
write(message) {
|
||||||
this.callModule("write", { id: this.id, message });
|
this.callModule("write", { id: this.id, message });
|
||||||
|
|
Loading…
Reference in New Issue