Compare commits

..

No commits in common. "v0.1.0-develop.11" and "v0.1.0-develop.10" have entirely different histories.

7 changed files with 14 additions and 20 deletions

View File

@ -1,5 +1,3 @@
# [0.1.0-develop.11](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.10...v0.1.0-develop.11) (2023-08-31)
# [0.1.0-develop.10](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.9...v0.1.0-develop.10) (2023-08-31)
# [0.1.0-develop.9](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.8...v0.1.0-develop.9) (2023-08-31)

4
npm-shrinkwrap.json generated
View File

@ -1,12 +1,12 @@
{
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.11",
"version": "0.1.0-develop.10",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.11",
"version": "0.1.0-develop.10",
"dependencies": {
"@noble/curves": "^1.1.0",
"@noble/hashes": "^1.3.1",

View File

@ -1,6 +1,6 @@
{
"name": "@lumeweb/libs5",
"version": "0.1.0-develop.11",
"version": "0.1.0-develop.10",
"type": "module",
"main": "lib/index.js",
"repository": {

View File

@ -319,10 +319,7 @@ export class P2PService {
this.logger.verbose(`[connect] ${connectionUri}`);
const socket = await createTransportSocket(protocol, connectionUri);
const peer = createTransportPeer(protocol, {
socket,
uris: [connectionUri],
});
const peer = createTransportPeer(protocol, socket, [connectionUri]);
peer.id = id;
await this.onNewPeer(peer, true);

View File

@ -1,17 +1,17 @@
import { Logger, Peer, PeerConstructorOptions } from "#types.js";
import { Logger, Peer } from "#types.js";
import { URL } from "url";
import NodeId from "#nodeId.js";
export abstract class BasePeer implements Peer {
connectionUris: URL[];
connectionUris: Array<URL>;
isConnected: boolean = false;
challenge: Uint8Array;
protected _socket: any;
constructor({ socket, uris }: PeerConstructorOptions) {
this.connectionUris = uris.map((uri) => new URL(uri.toString()));
constructor(_socket: any, connectionUris: URL[]) {
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
this.challenge = new Uint8Array();
this._socket = socket;
this._socket = _socket;
}
private _id?: NodeId;

View File

@ -1,7 +1,7 @@
import { URL } from "url";
import { TcpPeer } from "#transports/tcp.js";
import { WebSocketPeer } from "#transports/webSocket.js";
import { PeerConstructorOptions, PeerStatic } from "#types.js";
import { PeerStatic } from "#types.js";
import isNode from "detect-node";
import { BasePeer } from "#transports/base.js";
const transports = new Map<string, PeerStatic>();
@ -26,7 +26,8 @@ export function createTransportSocket(type: string, uri: URL) {
export function createTransportPeer(
type: string,
params: PeerConstructorOptions,
socket: any,
connectionUris: URL[] = [],
) {
if (!isTransport(type)) {
throw new Error(`transport ${type} does not exist`);
@ -34,7 +35,7 @@ export function createTransportPeer(
const transport = transports.get(type) as PeerStatic;
return new transport(params);
return new transport(socket, connectionUris);
}
export { BasePeer };

View File

@ -30,11 +30,9 @@ export interface Peer {
renderLocationUri(): string;
}
export type PeerConstructorOptions = { socket: any; uris: URL[] };
// Define the static side of the class
export interface PeerStatic {
new ({ socket, uris }: PeerConstructorOptions): Peer;
new (_socket: any, uri: URL[]): Peer;
connect(uri: URL): Promise<any>;
}