Updated tunnel response and request

This commit is contained in:
Sambo Chea 2022-07-09 12:27:28 +07:00
parent 596b99a99a
commit 1b96f430e8
Signed by: sombochea
GPG Key ID: 3C7CF22A05D95490

10
lib.js
View File

@ -7,14 +7,12 @@ 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);
@ -51,7 +49,7 @@ class TunnelRequest extends stream.Readable {
this._socket.on("request-pipe-end", onRequestPipeEnd);
}
_read() {}
_read() { }
}
class TunnelResponse extends stream.Duplex {
@ -63,7 +61,6 @@ 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);
}
@ -108,16 +105,13 @@ class TunnelResponse extends stream.Duplex {
}
_write(chunk, encoding, callback) {
console.log("Res Write Chunk: ", chunk.length, encoding);
this._socket.emit("response-pipe", this._responseId, chunk);
this._socket.io.engine.once("drain", () => {
console.log("hello = ", "callback...")
callback();
});
}
_writev(chunks, callback) {
console.log("Res Write Chunks: ", chunks.length);
this._socket.emit("response-pipes", this._responseId, chunks);
this._socket.io.engine.once("drain", () => {
callback();
@ -155,7 +149,7 @@ class TunnelResponse extends stream.Duplex {
});
}
_read(size) {}
_read(size) { }
}
exports.TunnelRequest = TunnelRequest;