Task: Updated the lib models for http tunnel client and updated the package version

This commit is contained in:
Sambo Chea 2022-06-30 10:10:39 +07:00
parent f155410eea
commit 573135545c
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490
2 changed files with 11 additions and 1 deletions

10
lib.js
View File

@ -5,11 +5,13 @@ class TunnelRequest extends stream.Readable {
super(); super();
this._socket = socket; this._socket = socket;
this._requestId = requestId; this._requestId = requestId;
const onRequestPipe = (requestId, data) => { const onRequestPipe = (requestId, data) => {
if (this._requestId === requestId) { if (this._requestId === requestId) {
this.push(data); this.push(data);
} }
}; };
const onRequestPipes = (requestId, data) => { const onRequestPipes = (requestId, data) => {
if (this._requestId === requestId) { if (this._requestId === requestId) {
data.forEach((chunk) => { data.forEach((chunk) => {
@ -17,6 +19,7 @@ class TunnelRequest extends stream.Readable {
}); });
} }
}; };
const onRequestPipeError = (requestId, error) => { const onRequestPipeError = (requestId, error) => {
if (this._requestId === requestId) { if (this._requestId === requestId) {
this._socket.off("request-pipe", onRequestPipe); this._socket.off("request-pipe", onRequestPipe);
@ -26,6 +29,7 @@ class TunnelRequest extends stream.Readable {
this.destroy(new Error(error)); this.destroy(new Error(error));
} }
}; };
const onRequestPipeEnd = (requestId, data) => { const onRequestPipeEnd = (requestId, data) => {
if (this._requestId === requestId) { if (this._requestId === requestId) {
this._socket.off("request-pipe", onRequestPipe); this._socket.off("request-pipe", onRequestPipe);
@ -38,6 +42,7 @@ class TunnelRequest extends stream.Readable {
this.push(null); this.push(null);
} }
}; };
this._socket.on("request-pipe", onRequestPipe); this._socket.on("request-pipe", onRequestPipe);
this._socket.on("request-pipes", onRequestPipes); this._socket.on("request-pipes", onRequestPipes);
this._socket.on("request-pipe-error", onRequestPipeError); this._socket.on("request-pipe-error", onRequestPipeError);
@ -52,6 +57,7 @@ class TunnelResponse extends stream.Duplex {
super(); super();
this._socket = socket; this._socket = socket;
this._responseId = responseId; this._responseId = responseId;
if (duplex) { if (duplex) {
// for websocket request bidirection // for websocket request bidirection
const onResponsePipe = (responseId, data) => { const onResponsePipe = (responseId, data) => {
@ -59,6 +65,7 @@ class TunnelResponse extends stream.Duplex {
this.push(data); this.push(data);
} }
}; };
const onResponsePipes = (responseId, data) => { const onResponsePipes = (responseId, data) => {
if (this._responseId === responseId) { if (this._responseId === responseId) {
data.forEach((chunk) => { data.forEach((chunk) => {
@ -66,6 +73,7 @@ class TunnelResponse extends stream.Duplex {
}); });
} }
}; };
const onResponsePipeError = (responseId, error) => { const onResponsePipeError = (responseId, error) => {
if (this._responseId === responseId) { if (this._responseId === responseId) {
this._socket.off("response-pipe", onResponsePipe); this._socket.off("response-pipe", onResponsePipe);
@ -75,6 +83,7 @@ class TunnelResponse extends stream.Duplex {
this.destroy(new Error(error)); this.destroy(new Error(error));
} }
}; };
const onResponsePipeEnd = (responseId, data) => { const onResponsePipeEnd = (responseId, data) => {
if (this._responseId === responseId) { if (this._responseId === responseId) {
this._socket.off("response-pipe", onResponsePipe); this._socket.off("response-pipe", onResponsePipe);
@ -87,6 +96,7 @@ class TunnelResponse extends stream.Duplex {
this.push(null); this.push(null);
} }
}; };
this._socket.on("response-pipe", onResponsePipe); this._socket.on("response-pipe", onResponsePipe);
this._socket.on("response-pipes", onResponsePipes); this._socket.on("response-pipes", onResponsePipes);
this._socket.on("response-pipe-error", onResponsePipeError); this._socket.on("response-pipe-error", onResponsePipeError);

View File

@ -1,6 +1,6 @@
{ {
"name": "@cubetiq/hlt", "name": "@cubetiq/hlt",
"version": "0.0.8", "version": "0.0.9",
"description": "A lightweight http tunnel client using nodejs and socket.io client", "description": "A lightweight http tunnel client using nodejs and socket.io client",
"main": "client.js", "main": "client.js",
"bin": { "bin": {