From 34bb3bf730e774e629b7907ede2968ee52781f14 Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Thu, 30 Jun 2022 21:29:16 +0700 Subject: [PATCH] Task: Updated the tunnel models request and response in http tunnel client --- client.js | 14 ++++++++++++++ lib.js | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/client.js b/client.js index aa6d1c1..e46aba2 100644 --- a/client.js +++ b/client.js @@ -77,6 +77,7 @@ function initClient(options) { ...defaultParams, os: osInfo, }, + // reconnection: true, }; const http_proxy = process.env.https_proxy || process.env.http_proxy; @@ -196,6 +197,19 @@ function initClient(options) { } }); + // reconnect manually + const tryReconnect = () => { + setTimeout(() => { + socket.io.open((err) => { + if (err) { + tryReconnect(); + } + }); + }, 2000); + }; + + // socket.io.on("close", tryReconnect); + keepAlive(); } diff --git a/lib.js b/lib.js index 2939bb3..0e84ee8 100644 --- a/lib.js +++ b/lib.js @@ -7,12 +7,14 @@ class TunnelRequest extends stream.Readable { this._requestId = requestId; const onRequestPipe = (requestId, data) => { + console.log("Res pipe size", data.length) if (this._requestId === requestId) { this.push(data); } }; const onRequestPipes = (requestId, data) => { + console.log("Res pipes size", data.length) if (this._requestId === requestId) { data.forEach((chunk) => { this.push(chunk); @@ -61,6 +63,7 @@ class TunnelResponse extends stream.Duplex { if (duplex) { // for websocket request: bidirection const onResponsePipe = (responseId, data) => { + console.log("Res pipe: ", data.toString()); if (this._responseId === responseId) { this.push(data); } @@ -105,6 +108,7 @@ class TunnelResponse extends stream.Duplex { } _write(chunk, encoding, callback) { + console.log("Res Write Chunk: ", chunk.length); this._socket.emit("response-pipe", this._responseId, chunk); this._socket.io.engine.once("drain", () => { callback();