fix(core): update

This commit is contained in:
Philipp Kunz 2023-01-06 11:57:11 +01:00
parent 0cc7184e58
commit 45ce56b118
2 changed files with 24 additions and 39 deletions

View File

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

View File

@ -246,47 +246,32 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
// Enable websockets
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
wss.on('connection', (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
wss.on('connection', async (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
console.log(`wss: got connection for wsc for https://${reqArg.headers.host}${reqArg.url}`);
let wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
let wsc: plugins.wsDefault;
try {
wsc = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
} catch (err) {
console.log(err);
ws.terminate();
return;
}
ws.on('message', async (message) => {
if (!wscConnectedDeferred) {
wscConnectedDeferred = plugins.smartpromise.defer();
let wsc: plugins.wsDefault;
try {
wsc = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`, {
headers: reqArg.headers
});
} catch (err) {
console.log(err);
ws.terminate();
return;
}
wsc.on('open', () => {
console.log('wsc opened.');
wscConnectedDeferred.resolve(wsc);
});
wsc.on('message', (message) => {
ws.send(message);
});
}
const wsc = await wscConnectedDeferred.promise;
wsc.send(message);
// handle closing
const cleanUp = () => {
ws.terminate();
wsc.terminate();
};
ws.on('close', (message) => {
cleanUp();
});
wsc.on('close', (message) => {
cleanUp();
});
ws.on("message", (message, isBinary) => {
console.log("client to upstream", message);
wsc.send(message, { binary: isBinary });
});
wsc.on("message", (message, isBinary) => {
console.log("upstream to client", message);
ws.send(message, { binary: isBinary });
});
ws.on("error", () => wsc.terminate());
wsc.on("error", () => ws.terminate());
ws.on("close", () => wsc.terminate());
wsc.on("close", () => ws.terminate());
});
this.httpsServer.keepAliveTimeout = 600 * 1000;
this.httpsServer.headersTimeout = 600 * 1000;