refactor: update Peer constructor to take an object bag
This commit is contained in:
parent
215a4ce4fe
commit
a84c02c36f
|
@ -3,15 +3,15 @@ import { URL } from "url";
|
||||||
import NodeId from "#nodeId.js";
|
import NodeId from "#nodeId.js";
|
||||||
|
|
||||||
export abstract class BasePeer implements Peer {
|
export abstract class BasePeer implements Peer {
|
||||||
connectionUris: Array<URL>;
|
connectionUris: URL[];
|
||||||
isConnected: boolean = false;
|
isConnected: boolean = false;
|
||||||
challenge: Uint8Array;
|
challenge: Uint8Array;
|
||||||
protected _socket: any;
|
protected _socket: any;
|
||||||
|
|
||||||
constructor(_socket: any, connectionUris: URL[]) {
|
constructor({ socket, uri }: { socket: any; uri: URL[] }) {
|
||||||
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
this.connectionUris = uri.map((uri) => new URL(uri.toString()));
|
||||||
this.challenge = new Uint8Array();
|
this.challenge = new Uint8Array();
|
||||||
this._socket = _socket;
|
this._socket = socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _id?: NodeId;
|
private _id?: NodeId;
|
||||||
|
|
|
@ -32,7 +32,7 @@ export interface Peer {
|
||||||
|
|
||||||
// Define the static side of the class
|
// Define the static side of the class
|
||||||
export interface PeerStatic {
|
export interface PeerStatic {
|
||||||
new (_socket: any, uri: URL[]): Peer;
|
new ({ socket, uri }: { socket: any; uri: URL[] }): Peer;
|
||||||
connect(uri: URL): Promise<any>;
|
connect(uri: URL): Promise<any>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue