From 998d05a74c300f0f14aea412406e5502617cdecb Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Sat, 15 Apr 2023 05:45:07 -0400 Subject: [PATCH] *Create event forwards after socket is created --- src/socket.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/socket.ts b/src/socket.ts index 3b22410..d0a28e2 100644 --- a/src/socket.ts +++ b/src/socket.ts @@ -58,14 +58,6 @@ export class TCPSocket extends Duplex { } public connect() { - ["timeout", "error", "connect", "end", "destroy", "close"].forEach( - (event) => { - this._socket?.on(event, (...args: any) => - this.emit(event as any, ...args) - ); - } - ); - this.on("error", (err: Error) => { this._peer.messages.errorSocket?.send({ ...this._getSocketRequest(), @@ -88,6 +80,14 @@ export class TCPSocket extends Duplex { } this._socket = net.connect(this._options); + ["timeout", "error", "connect", "end", "destroy", "close"].forEach( + (event) => { + this._socket?.on(event, (...args: any) => + this.emit(event as any, ...args) + ); + } + ); + this._socket.pipe(this as any); this.pipe(this._socket); }