From 573135545c9655db717512645b92cc96f77bac5c Mon Sep 17 00:00:00 2001 From: Sambo Chea Date: Thu, 30 Jun 2022 10:10:39 +0700 Subject: [PATCH] Task: Updated the lib models for http tunnel client and updated the package version --- lib.js | 10 ++++++++++ package.json | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib.js b/lib.js index c2c07ab..2939bb3 100644 --- a/lib.js +++ b/lib.js @@ -5,11 +5,13 @@ class TunnelRequest extends stream.Readable { super(); this._socket = socket; this._requestId = requestId; + const onRequestPipe = (requestId, data) => { if (this._requestId === requestId) { this.push(data); } }; + const onRequestPipes = (requestId, data) => { if (this._requestId === requestId) { data.forEach((chunk) => { @@ -17,6 +19,7 @@ class TunnelRequest extends stream.Readable { }); } }; + const onRequestPipeError = (requestId, error) => { if (this._requestId === requestId) { this._socket.off("request-pipe", onRequestPipe); @@ -26,6 +29,7 @@ class TunnelRequest extends stream.Readable { this.destroy(new Error(error)); } }; + const onRequestPipeEnd = (requestId, data) => { if (this._requestId === requestId) { this._socket.off("request-pipe", onRequestPipe); @@ -38,6 +42,7 @@ class TunnelRequest extends stream.Readable { this.push(null); } }; + this._socket.on("request-pipe", onRequestPipe); this._socket.on("request-pipes", onRequestPipes); this._socket.on("request-pipe-error", onRequestPipeError); @@ -52,6 +57,7 @@ class TunnelResponse extends stream.Duplex { super(); this._socket = socket; this._responseId = responseId; + if (duplex) { // for websocket request: bidirection const onResponsePipe = (responseId, data) => { @@ -59,6 +65,7 @@ class TunnelResponse extends stream.Duplex { this.push(data); } }; + const onResponsePipes = (responseId, data) => { if (this._responseId === responseId) { data.forEach((chunk) => { @@ -66,6 +73,7 @@ class TunnelResponse extends stream.Duplex { }); } }; + const onResponsePipeError = (responseId, error) => { if (this._responseId === responseId) { this._socket.off("response-pipe", onResponsePipe); @@ -75,6 +83,7 @@ class TunnelResponse extends stream.Duplex { this.destroy(new Error(error)); } }; + const onResponsePipeEnd = (responseId, data) => { if (this._responseId === responseId) { this._socket.off("response-pipe", onResponsePipe); @@ -87,6 +96,7 @@ class TunnelResponse extends stream.Duplex { this.push(null); } }; + this._socket.on("response-pipe", onResponsePipe); this._socket.on("response-pipes", onResponsePipes); this._socket.on("response-pipe-error", onResponsePipeError); diff --git a/package.json b/package.json index df93a5e..2aa76b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cubetiq/hlt", - "version": "0.0.8", + "version": "0.0.9", "description": "A lightweight http tunnel client using nodejs and socket.io client", "main": "client.js", "bin": {