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

View File

@ -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": {