Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
e51c2a88cc | |||
7f8112930d | |||
b5c83b5c75 | |||
63ce1a44a4 | |||
759f70b84d | |||
45ce56b118 | |||
0cc7184e58 | |||
392e241208 | |||
32c6d77178 | |||
2c4316d2d3 | |||
62e6387c1d | |||
7fe22e962a | |||
3f1f718308 | |||
ce94d283c1 | |||
a1c4f3c341 | |||
8087bab197 | |||
db63e7bf79 | |||
2615a0ebd4 | |||
d5d77af98d | |||
1f1bf77807 | |||
d4269d290d | |||
e05e5ede55 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartproxy",
|
"name": "@pushrocks/smartproxy",
|
||||||
"version": "3.0.44",
|
"version": "3.0.55",
|
||||||
"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",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@pushrocks/smartproxy',
|
name: '@pushrocks/smartproxy',
|
||||||
version: '3.0.44',
|
version: '3.0.55',
|
||||||
description: 'a proxy for handling high workloads of proxying'
|
description: 'a proxy for handling high workloads of proxying'
|
||||||
}
|
}
|
||||||
|
@ -245,40 +245,34 @@ 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', (ws: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
wsServer.on('connection', async (wsIncoming: plugins.wsDefault, reqArg: plugins.http.IncomingMessage) => {
|
||||||
console.log(`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 wscConnectedDeferred: plugins.smartpromise.Deferred<plugins.wsDefault>;
|
|
||||||
|
|
||||||
ws.on('message', async (message) => {
|
let wsOutgoing: plugins.wsDefault;
|
||||||
if (!wscConnectedDeferred) {
|
try {
|
||||||
wscConnectedDeferred = plugins.smartpromise.defer();
|
wsOutgoing = new plugins.wsDefault(`ws://${this.router.routeReq(reqArg).destinationIp}:${this.router.routeReq(reqArg).destinationPort}${reqArg.url}`);
|
||||||
const wsc = new plugins.wsDefault(`${this.router.routeReq(reqArg)}${reqArg.url}`);
|
console.log('wss proxy: initiated outgoing proxy')
|
||||||
|
} catch (err) {
|
||||||
wsc.on('open', () => {
|
console.log(err);
|
||||||
wscConnectedDeferred.resolve(wsc);
|
wsIncoming.terminate();
|
||||||
});
|
return;
|
||||||
}
|
}
|
||||||
const wsc = await wscConnectedDeferred.promise;
|
|
||||||
wsc.emit('message', message);
|
wsIncoming.on("message", (message, isBinary) => {
|
||||||
wsc.on('message', (message) => {
|
console.log("client to upstream", message);
|
||||||
ws.emit('message', message);
|
wsOutgoing.send(message, { binary: isBinary });
|
||||||
});
|
});
|
||||||
|
|
||||||
// handle closing
|
wsOutgoing.on("message", (message, isBinary) => {
|
||||||
const cleanUp = () => {
|
console.log("upstream to client", message);
|
||||||
ws.terminate();
|
wsIncoming.send(message, { binary: isBinary });
|
||||||
wsc.terminate();
|
});
|
||||||
};
|
wsIncoming.on("error", () => wsOutgoing.terminate());
|
||||||
|
wsOutgoing.on("error", () => wsIncoming.terminate());
|
||||||
|
wsIncoming.on("close", () => wsOutgoing.terminate());
|
||||||
|
wsOutgoing.on("close", () => wsIncoming.terminate());
|
||||||
|
|
||||||
ws.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
|
||||||
|
|
||||||
wsc.on('close', (message) => {
|
|
||||||
cleanUp();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
||||||
this.httpsServer.headersTimeout = 600 * 1000;
|
this.httpsServer.headersTimeout = 600 * 1000;
|
||||||
|
Reference in New Issue
Block a user