From 1f391c15b1165f241fe038665c1a0adf26f8b432 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 31 Aug 2023 18:03:47 -0400 Subject: [PATCH] refactor: update createTransportPeer --- src/service/p2p.ts | 5 ++++- src/transports/index.ts | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/service/p2p.ts b/src/service/p2p.ts index a2775c2..37b9699 100644 --- a/src/service/p2p.ts +++ b/src/service/p2p.ts @@ -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); diff --git a/src/transports/index.ts b/src/transports/index.ts index bcc8ff8..af21859 100644 --- a/src/transports/index.ts +++ b/src/transports/index.ts @@ -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(); @@ -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 };