Compare commits

...

10 Commits

Author SHA1 Message Date
632015a7bd 3.0.58 2023-02-04 19:32:14 +01:00
972ee2af54 fix(core): update 2023-02-04 19:32:13 +01:00
9b1ff5eed8 3.0.57 2023-01-06 13:04:12 +01:00
0739d1093a fix(core): update 2023-01-06 13:04:11 +01:00
ee4f7fc48d 3.0.56 2023-01-06 13:00:11 +01:00
f6e656361b fix(core): update 2023-01-06 13:00:10 +01:00
e51c2a88cc 3.0.55 2023-01-06 12:56:51 +01:00
7f8112930d fix(core): update 2023-01-06 12:56:51 +01:00
b5c83b5c75 3.0.54 2023-01-06 12:53:58 +01:00
63ce1a44a4 fix(core): update 2023-01-06 12:53:58 +01:00
3 changed files with 35 additions and 18 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartproxy", "name": "@pushrocks/smartproxy",
"version": "3.0.53", "version": "3.0.58",
"private": false, "private": false,
"description": "a proxy for handling high workloads of proxying", "description": "a proxy for handling high workloads of proxying",
"main": "dist_ts/index.js", "main": "dist_ts/index.js",

View File

@ -3,6 +3,6 @@
*/ */
export const commitinfo = { export const commitinfo = {
name: '@pushrocks/smartproxy', name: '@pushrocks/smartproxy',
version: '3.0.53', version: '3.0.58',
description: 'a proxy for handling high workloads of proxying' description: 'a proxy for handling high workloads of proxying'
} }

View File

@ -245,32 +245,49 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
); );
// Enable websockets // Enable websockets
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer }); const wsServer = new plugins.ws.WebSocketServer({ server: this.httpsServer });
wss.on('connection', async (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => { wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
console.log(`wss: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`); console.log(`wss proxy: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
let wsOutgoing: plugins.wsDefault;
const outGoingDeferred = plugins.smartpromise.defer();
let wsc: plugins.wsDefault;
try { try {
wsc = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`); wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
console.log('wss proxy: initiated outgoing proxy');
wsOutgoing.on('open', async () => {
outGoingDeferred.resolve();
})
} catch (err) { } catch (err) {
console.log(err); console.log(err);
ws.terminate(); wsIncoming.terminate();
return; return;
} }
ws.on("message", (message, isBinary) => { wsIncoming.on("message", async (message, isBinary) => {
console.log("client to upstream", message); await outGoingDeferred.promise;
wsc.send(message, { binary: isBinary }); // console.log("client to upstream", message);
wsOutgoing.send(message, { binary: isBinary });
}); });
wsc.on("message", (message, isBinary) => { wsOutgoing.on("message", async (message, isBinary) => {
console.log("upstream to client", message); // console.log("upstream to client", message);
ws.send(message, { binary: isBinary }); wsIncoming.send(message, { binary: isBinary });
}); });
ws.on("error", () => wsc.terminate()); const terminateWsOutgoing = () => {
wsc.on("error", () => ws.terminate()); wsOutgoing.terminate();
ws.on("close", () => wsc.terminate()); console.log('terminated outgoing ws.');
wsc.on("close", () => ws.terminate()); }
wsIncoming.on("error", () => terminateWsOutgoing());
wsIncoming.on("close", () => terminateWsOutgoing());
const terminateWsIncoming = () => {
wsIncoming.terminate();
console.log('terminated incoming ws.');
}
wsOutgoing.on("error", () => terminateWsIncoming());
wsOutgoing.on("close", () => terminateWsIncoming());
}); });
this.httpsServer.keepAliveTimeout = 600 * 1000; this.httpsServer.keepAliveTimeout = 600 * 1000;