Compare commits
5 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | 3bd1adf4dd | |
Derrick Hammer | 1f391c15b1 | |
Derrick Hammer | 57e2c56d24 | |
Derrick Hammer | 3accd69ab0 | |
Derrick Hammer | a84c02c36f |
|
@ -1,3 +1,5 @@
|
|||
# [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)
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.10",
|
||||
"version": "0.1.0-develop.11",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.10",
|
||||
"version": "0.1.0-develop.11",
|
||||
"dependencies": {
|
||||
"@noble/curves": "^1.1.0",
|
||||
"@noble/hashes": "^1.3.1",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@lumeweb/libs5",
|
||||
"version": "0.1.0-develop.10",
|
||||
"version": "0.1.0-develop.11",
|
||||
"type": "module",
|
||||
"main": "lib/index.js",
|
||||
"repository": {
|
||||
|
|
|
@ -319,7 +319,10 @@ export class P2PService {
|
|||
this.logger.verbose(`[connect] ${connectionUri}`);
|
||||
|
||||
const socket = await createTransportSocket(protocol, connectionUri);
|
||||
const peer = createTransportPeer(protocol, socket, [connectionUri]);
|
||||
const peer = createTransportPeer(protocol, {
|
||||
socket,
|
||||
uris: [connectionUri],
|
||||
});
|
||||
|
||||
peer.id = id;
|
||||
await this.onNewPeer(peer, true);
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
import { Logger, Peer } from "#types.js";
|
||||
import { Logger, Peer, PeerConstructorOptions } from "#types.js";
|
||||
import { URL } from "url";
|
||||
import NodeId from "#nodeId.js";
|
||||
|
||||
export abstract class BasePeer implements Peer {
|
||||
connectionUris: Array<URL>;
|
||||
connectionUris: URL[];
|
||||
isConnected: boolean = false;
|
||||
challenge: Uint8Array;
|
||||
protected _socket: any;
|
||||
|
||||
constructor(_socket: any, connectionUris: URL[]) {
|
||||
this.connectionUris = connectionUris.map((uri) => new URL(uri.toString()));
|
||||
constructor({ socket, uris }: PeerConstructorOptions) {
|
||||
this.connectionUris = uris.map((uri) => new URL(uri.toString()));
|
||||
this.challenge = new Uint8Array();
|
||||
this._socket = _socket;
|
||||
this._socket = socket;
|
||||
}
|
||||
|
||||
private _id?: NodeId;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { URL } from "url";
|
||||
import { TcpPeer } from "#transports/tcp.js";
|
||||
import { WebSocketPeer } from "#transports/webSocket.js";
|
||||
import { PeerStatic } from "#types.js";
|
||||
import { PeerConstructorOptions, PeerStatic } from "#types.js";
|
||||
import isNode from "detect-node";
|
||||
import { BasePeer } from "#transports/base.js";
|
||||
const transports = new Map<string, PeerStatic>();
|
||||
|
@ -26,8 +26,7 @@ export function createTransportSocket(type: string, uri: URL) {
|
|||
|
||||
export function createTransportPeer(
|
||||
type: string,
|
||||
socket: any,
|
||||
connectionUris: URL[] = [],
|
||||
params: PeerConstructorOptions,
|
||||
) {
|
||||
if (!isTransport(type)) {
|
||||
throw new Error(`transport ${type} does not exist`);
|
||||
|
@ -35,7 +34,7 @@ export function createTransportPeer(
|
|||
|
||||
const transport = transports.get(type) as PeerStatic;
|
||||
|
||||
return new transport(socket, connectionUris);
|
||||
return new transport(params);
|
||||
}
|
||||
|
||||
export { BasePeer };
|
||||
|
|
|
@ -30,9 +30,11 @@ export interface Peer {
|
|||
renderLocationUri(): string;
|
||||
}
|
||||
|
||||
export type PeerConstructorOptions = { socket: any; uris: URL[] };
|
||||
|
||||
// Define the static side of the class
|
||||
export interface PeerStatic {
|
||||
new (_socket: any, uri: URL[]): Peer;
|
||||
new ({ socket, uris }: PeerConstructorOptions): Peer;
|
||||
connect(uri: URL): Promise<any>;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue