Task: Updated the tunnel models request and response in http tunnel client

This commit is contained in:
Sambo Chea 2022-06-30 21:29:16 +07:00
parent 573135545c
commit 34bb3bf730
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
2 changed files with 18 additions and 0 deletions

View File

@ -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();
}

4
lib.js
View File

@ -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();