refactor: update createTransportPeer
This commit is contained in:
parent
57e2c56d24
commit
1f391c15b1
|
@ -319,7 +319,10 @@ export class P2PService {
|
||||||
this.logger.verbose(`[connect] ${connectionUri}`);
|
this.logger.verbose(`[connect] ${connectionUri}`);
|
||||||
|
|
||||||
const socket = await createTransportSocket(protocol, connectionUri);
|
const socket = await createTransportSocket(protocol, connectionUri);
|
||||||
const peer = createTransportPeer(protocol, socket, [connectionUri]);
|
const peer = createTransportPeer(protocol, {
|
||||||
|
socket,
|
||||||
|
uris: [connectionUri],
|
||||||
|
});
|
||||||
|
|
||||||
peer.id = id;
|
peer.id = id;
|
||||||
await this.onNewPeer(peer, true);
|
await this.onNewPeer(peer, true);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { URL } from "url";
|
import { URL } from "url";
|
||||||
import { TcpPeer } from "#transports/tcp.js";
|
import { TcpPeer } from "#transports/tcp.js";
|
||||||
import { WebSocketPeer } from "#transports/webSocket.js";
|
import { WebSocketPeer } from "#transports/webSocket.js";
|
||||||
import { PeerStatic } from "#types.js";
|
import { PeerConstructorOptions, PeerStatic } from "#types.js";
|
||||||
import isNode from "detect-node";
|
import isNode from "detect-node";
|
||||||
import { BasePeer } from "#transports/base.js";
|
import { BasePeer } from "#transports/base.js";
|
||||||
const transports = new Map<string, PeerStatic>();
|
const transports = new Map<string, PeerStatic>();
|
||||||
|
@ -26,8 +26,7 @@ export function createTransportSocket(type: string, uri: URL) {
|
||||||
|
|
||||||
export function createTransportPeer(
|
export function createTransportPeer(
|
||||||
type: string,
|
type: string,
|
||||||
socket: any,
|
params: PeerConstructorOptions,
|
||||||
connectionUris: URL[] = [],
|
|
||||||
) {
|
) {
|
||||||
if (!isTransport(type)) {
|
if (!isTransport(type)) {
|
||||||
throw new Error(`transport ${type} does not exist`);
|
throw new Error(`transport ${type} does not exist`);
|
||||||
|
@ -35,7 +34,7 @@ export function createTransportPeer(
|
||||||
|
|
||||||
const transport = transports.get(type) as PeerStatic;
|
const transport = transports.get(type) as PeerStatic;
|
||||||
|
|
||||||
return new transport(socket, connectionUris);
|
return new transport(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { BasePeer };
|
export { BasePeer };
|
||||||
|
|
Loading…
Reference in New Issue