refactor: add end method to transports
This commit is contained in:
parent
e821da5a27
commit
90c0614773
|
@ -38,4 +38,6 @@ export abstract class BasePeer implements Peer {
|
|||
logger,
|
||||
}: { onDone?: any; onError?: (...args: any[]) => void; logger: Logger },
|
||||
): void;
|
||||
|
||||
abstract end(): void;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import * as console from "console";
|
|||
import { BasePeer } from "#transports/base.js";
|
||||
|
||||
export class TcpPeer extends BasePeer implements Peer {
|
||||
declare _socket: net.Socket;
|
||||
|
||||
sendMessage(message: Uint8Array): void {
|
||||
this._socket.write(message);
|
||||
}
|
||||
|
@ -59,6 +61,9 @@ export class TcpPeer extends BasePeer implements Peer {
|
|||
this._socket.on("error", onError);
|
||||
}
|
||||
}
|
||||
end(): void {
|
||||
this._socket.end();
|
||||
}
|
||||
|
||||
public static async connect(uri: URL): Promise<net.Socket> {
|
||||
const host = uri.hostname;
|
||||
|
|
|
@ -42,6 +42,9 @@ export class WebSocketPeer extends BasePeer implements Peer {
|
|||
this._socket.addEventListener("error", onError);
|
||||
}
|
||||
}
|
||||
end(): void {
|
||||
this._socket.end();
|
||||
}
|
||||
|
||||
public static async connect(uri: URL): Promise<WebSocket> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -28,6 +28,7 @@ export interface Peer {
|
|||
): void;
|
||||
|
||||
renderLocationUri(): string;
|
||||
end(): void;
|
||||
}
|
||||
|
||||
export type PeerConstructorOptions = { socket: any; uris?: URL[] };
|
||||
|
|
Loading…
Reference in New Issue