fix(core): update
This commit is contained in:
parent
0cc7184e58
commit
45ce56b118
@ -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'
|
||||
}
|
||||
|
@ -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>;
|
||||
|
||||
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
|
||||
});
|
||||
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;
|
||||
}
|
||||
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();
|
||||
ws.on("message", (message, isBinary) => {
|
||||
console.log("client to upstream", message);
|
||||
wsc.send(message, { binary: isBinary });
|
||||
});
|
||||
|
||||
wsc.on('close', (message) => {
|
||||
cleanUp();
|
||||
});
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user