Compare commits
No commits in common. "524d647f21e8e51bde492d52e4a325ac057a6ad8" and "e69e7a67b6f64c924c0179c523f245eca6e91970" have entirely different histories.
524d647f21
...
e69e7a67b6
|
@ -6,8 +6,8 @@ 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);
|
|
||||||
get swarm(): number | undefined;
|
get swarm(): number | undefined;
|
||||||
|
constructor(useDefaultDht?: boolean);
|
||||||
connect(pubkey: string | Uint8Array): Promise<Socket>;
|
connect(pubkey: string | Uint8Array): Promise<Socket>;
|
||||||
init(): Promise<ErrTuple>;
|
init(): Promise<ErrTuple>;
|
||||||
ready(): Promise<void>;
|
ready(): Promise<void>;
|
||||||
|
@ -21,11 +21,6 @@ export declare class Socket extends Client {
|
||||||
private id;
|
private id;
|
||||||
private eventUpdates;
|
private eventUpdates;
|
||||||
constructor(id: number);
|
constructor(id: number);
|
||||||
private _remotePublicKey?;
|
|
||||||
get remotePublicKey(): Uint8Array;
|
|
||||||
private _rawStream?;
|
|
||||||
get rawStream(): Uint8Array;
|
|
||||||
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;
|
||||||
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;
|
||||||
write(message: string | Buffer): void;
|
write(message: string | Buffer): void;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index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AAC;IAIvC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI1C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAG5B,SAAS,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAI9B,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAGhD;AAED,qBAAa,MAAO,SAAQ,MAAM;IAChC,OAAO,CAAC,EAAE,CAAS;IACnB,OAAO,CAAC,YAAY,CAAqC;gBAE7C,EAAE,EAAE,MAAM;IAItB,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"}
|
|
@ -3,13 +3,13 @@ import { hexToBuf } from "@siaweb/libweb";
|
||||||
export class SwarmClient extends Client {
|
export class SwarmClient extends Client {
|
||||||
useDefaultSwarm;
|
useDefaultSwarm;
|
||||||
id = 0;
|
id = 0;
|
||||||
|
get swarm() {
|
||||||
|
return this.useDefaultSwarm ? undefined : this.id;
|
||||||
|
}
|
||||||
constructor(useDefaultDht = true) {
|
constructor(useDefaultDht = true) {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
}
|
}
|
||||||
get swarm() {
|
|
||||||
return this.useDefaultSwarm ? undefined : this.id;
|
|
||||||
}
|
|
||||||
async connect(pubkey) {
|
async connect(pubkey) {
|
||||||
if (typeof pubkey === "string") {
|
if (typeof pubkey === "string") {
|
||||||
const buf = hexToBuf(pubkey);
|
const buf = hexToBuf(pubkey);
|
||||||
|
@ -26,8 +26,8 @@ export class SwarmClient extends Client {
|
||||||
}
|
}
|
||||||
async ready() {
|
async ready() {
|
||||||
await this.callModuleReturn("ready", { swarm: this.swarm });
|
await this.callModuleReturn("ready", { swarm: this.swarm });
|
||||||
this.connectModule("listenConnections", { swarm: this.swarm }, async (socketId) => {
|
this.connectModule("listenConnections", { swarm: this.swarm }, (socketId) => {
|
||||||
this.emit("connection", await createSocket(socketId));
|
this.emit("connection", createSocket(socketId));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async addRelay(pubkey) {
|
async addRelay(pubkey) {
|
||||||
|
@ -53,19 +53,6 @@ export class Socket extends Client {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
_remotePublicKey;
|
|
||||||
get remotePublicKey() {
|
|
||||||
return this._remotePublicKey;
|
|
||||||
}
|
|
||||||
_rawStream;
|
|
||||||
get rawStream() {
|
|
||||||
return this._rawStream;
|
|
||||||
}
|
|
||||||
async setup() {
|
|
||||||
let info = await this.callModuleReturn("socketGetInfo", { id: this.id });
|
|
||||||
this._remotePublicKey = info.remotePublicKey;
|
|
||||||
this._rawStream = info.rawStream;
|
|
||||||
}
|
|
||||||
on(event, fn, context) {
|
on(event, fn, context) {
|
||||||
const [update, promise] = this.connectModule("socketListenEvent", { id: this.id, event: event }, (data) => {
|
const [update, promise] = this.connectModule("socketListenEvent", { id: this.id, event: event }, (data) => {
|
||||||
this.emit(event, data);
|
this.emit(event, data);
|
||||||
|
@ -106,9 +93,4 @@ export class Socket extends Client {
|
||||||
}
|
}
|
||||||
const MODULE = "_A7ClA0mSa1-Pg5c4V3C0H_fnhAFjgccITYT83Euc7t_9A";
|
const MODULE = "_A7ClA0mSa1-Pg5c4V3C0H_fnhAFjgccITYT83Euc7t_9A";
|
||||||
export const createClient = factory(SwarmClient, MODULE);
|
export const createClient = factory(SwarmClient, MODULE);
|
||||||
const socketFactory = factory(Socket, MODULE);
|
const createSocket = factory(Socket, MODULE);
|
||||||
const createSocket = async (...args) => {
|
|
||||||
const socket = socketFactory(...args);
|
|
||||||
await socket.setup();
|
|
||||||
return socket;
|
|
||||||
};
|
|
||||||
|
|
48
src/index.ts
48
src/index.ts
|
@ -8,15 +8,15 @@ export class SwarmClient extends Client {
|
||||||
private useDefaultSwarm: boolean;
|
private useDefaultSwarm: boolean;
|
||||||
private id: number = 0;
|
private id: number = 0;
|
||||||
|
|
||||||
|
get swarm(): number | undefined {
|
||||||
|
return this.useDefaultSwarm ? undefined : this.id;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(useDefaultDht = true) {
|
constructor(useDefaultDht = true) {
|
||||||
super();
|
super();
|
||||||
this.useDefaultSwarm = useDefaultDht;
|
this.useDefaultSwarm = useDefaultDht;
|
||||||
}
|
}
|
||||||
|
|
||||||
get swarm(): number | undefined {
|
|
||||||
return this.useDefaultSwarm ? undefined : this.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async connect(pubkey: string | Uint8Array): Promise<Socket> {
|
public async connect(pubkey: string | Uint8Array): Promise<Socket> {
|
||||||
if (typeof pubkey === "string") {
|
if (typeof pubkey === "string") {
|
||||||
const buf = hexToBuf(pubkey);
|
const buf = hexToBuf(pubkey);
|
||||||
|
@ -39,8 +39,8 @@ export class SwarmClient extends Client {
|
||||||
this.connectModule(
|
this.connectModule(
|
||||||
"listenConnections",
|
"listenConnections",
|
||||||
{ swarm: this.swarm },
|
{ swarm: this.swarm },
|
||||||
async (socketId: any) => {
|
(socketId: any) => {
|
||||||
this.emit("connection", await createSocket(socketId));
|
this.emit("connection", createSocket(socketId));
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -65,12 +65,6 @@ export class SwarmClient extends Client {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SocketRawStream {
|
|
||||||
remoteHost: string;
|
|
||||||
remotePort: number;
|
|
||||||
remoteFamily: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Socket extends Client {
|
export class Socket extends Client {
|
||||||
private id: number;
|
private id: number;
|
||||||
private eventUpdates: { [event: string]: DataFn[] } = {};
|
private eventUpdates: { [event: string]: DataFn[] } = {};
|
||||||
|
@ -79,26 +73,6 @@ export class Socket extends Client {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _remotePublicKey?: Uint8Array;
|
|
||||||
|
|
||||||
get remotePublicKey(): Uint8Array {
|
|
||||||
return this._remotePublicKey as Uint8Array;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _rawStream?: Uint8Array;
|
|
||||||
|
|
||||||
get rawStream(): Uint8Array {
|
|
||||||
return this._rawStream as Uint8Array;
|
|
||||||
}
|
|
||||||
|
|
||||||
async setup() {
|
|
||||||
let info = await this.callModuleReturn("socketGetInfo", { id: this.id });
|
|
||||||
|
|
||||||
this._remotePublicKey = info.remotePublicKey;
|
|
||||||
this._rawStream = info.rawStream;
|
|
||||||
}
|
|
||||||
|
|
||||||
on<T extends EventEmitter.EventNames<string | symbol>>(
|
on<T extends EventEmitter.EventNames<string | symbol>>(
|
||||||
event: T,
|
event: T,
|
||||||
fn: EventEmitter.EventListener<string | symbol, T>,
|
fn: EventEmitter.EventListener<string | symbol, T>,
|
||||||
|
@ -163,12 +137,4 @@ export class Socket extends Client {
|
||||||
const MODULE = "_A7ClA0mSa1-Pg5c4V3C0H_fnhAFjgccITYT83Euc7t_9A";
|
const MODULE = "_A7ClA0mSa1-Pg5c4V3C0H_fnhAFjgccITYT83Euc7t_9A";
|
||||||
|
|
||||||
export const createClient = factory<SwarmClient>(SwarmClient, MODULE);
|
export const createClient = factory<SwarmClient>(SwarmClient, MODULE);
|
||||||
|
const createSocket = factory<Socket>(Socket, MODULE);
|
||||||
const socketFactory = factory<Socket>(Socket, MODULE);
|
|
||||||
const createSocket = async (...args: any): Promise<Socket> => {
|
|
||||||
const socket = socketFactory(...args);
|
|
||||||
|
|
||||||
await socket.setup();
|
|
||||||
|
|
||||||
return socket;
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue