fix(core): update
This commit is contained in:
parent
0cc7184e58
commit
45ce56b118
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.52',
|
version: '3.0.53',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -246,47 +246,32 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
|||||||
|
|
||||||
// Enable websockets
|
// Enable websockets
|
||||||
const wss = new plugins.ws.WebSocketServer({ server: this.httpsServer });
|
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}`);
|
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) => {
|
ws.on("message", (message, isBinary) => {
|
||||||
if (!wscConnectedDeferred) {
|
console.log("client to upstream", message);
|
||||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
wsc.send(message, { binary: isBinary });
|
||||||
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();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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.keepAliveTimeout = 600 * 1000;
|
||||||
this.httpsServer.headersTimeout = 600 * 1000;
|
this.httpsServer.headersTimeout = 600 * 1000;
|
||||||
|
Loading…
Reference in New Issue
Block a user