Added RDP flow control.

This commit is contained in:
Ylian Saint-Hilaire 2020-06-11 11:13:21 -07:00
parent d46eba8d21
commit 7266f7c57c

View File

@ -54,7 +54,9 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
} else { } else {
obj.relaySocket = socket; obj.relaySocket = socket;
obj.relaySocket.pause(); obj.relaySocket.pause();
obj.relaySocket.on('data', function (chunk) { if (obj.relayActive == true) { obj.wsClient.send(chunk); } }); obj.relaySocket.on('data', function (chunk) { // Make sure to handle flow control.
if (obj.relayActive == true) { obj.relaySocket.pause(); obj.wsClient.send(chunk, function () { obj.relaySocket.resume(); }); }
});
obj.relaySocket.on('end', function () { obj.close(0); }); obj.relaySocket.on('end', function () { obj.close(0); });
obj.relaySocket.on('error', function (err) { obj.close(0); }); obj.relaySocket.on('error', function (err) { obj.close(0); });
@ -66,9 +68,15 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
var domainadd = ''; var domainadd = '';
if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' } if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
obj.wsClient = new WebSocket(protocol + '://127.0.0.1/' + domainadd + 'meshrelay.ashx?auth=' + obj.infos.ip, options); obj.wsClient = new WebSocket(protocol + '://127.0.0.1/' + domainadd + 'meshrelay.ashx?auth=' + obj.infos.ip, options);
obj.wsClient.on('open', function () { }); obj.wsClient.on('open', function () { });
obj.wsClient.on('message', function (data) { if ((obj.relayActive == false) && (data == 'c')) { obj.relayActive = true; obj.relaySocket.resume(); } else { obj.relaySocket.write(data); } }); obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
if ((obj.relayActive == false) && (data == 'c')) {
obj.relayActive = true; obj.relaySocket.resume();
} else {
obj.wsClient._socket.pause();
obj.relaySocket.write(data, function () { obj.wsClient._socket.resume(); });
}
});
obj.wsClient.on('close', function () { obj.close(0); }); obj.wsClient.on('close', function () { obj.close(0); });
obj.tcpServer.close(); obj.tcpServer.close();
obj.tcpServer = null; obj.tcpServer = null;
@ -130,8 +138,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
// If the web socket is closed // If the web socket is closed
ws.on('close', function (req) { obj.close(0); }); ws.on('close', function (req) { obj.close(0); });
// Send an object // Send an object with flow control
function send(obj) { try { ws.send(JSON.stringify(obj)); } catch (ex) { } } function send(obj) { ws._socket.pause(); try { ws.send(JSON.stringify(obj), function () { ws._socket.resume(); }); } catch (ex) { } }
// We are all set, start receiving data // We are all set, start receiving data
ws._socket.resume(); ws._socket.resume();