Added RDP flow control.
Ylian Saint-Hilaire committed
Jun 11, 2020 at 11:13 UTC
18defd1df44f51cf13c85d2d414d2028e73a4ac2
1 file changed
+13
-5
mstsc.js
+13
-5
@@ -54,7 +54,9 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
54
} else {
55
obj.relaySocket = socket;
56
obj.relaySocket.pause();
57
- obj.relaySocket.on('data', function (chunk) { if (obj.relayActive == true) { obj.wsClient.send(chunk); } });
57
+ obj.relaySocket.on('data', function (chunk) { // Make sure to handle flow control.
58
+ if (obj.relayActive == true) { obj.relaySocket.pause(); obj.wsClient.send(chunk, function () { obj.relaySocket.resume(); }); }
59
+ });
60
obj.relaySocket.on('end', function () { obj.close(0); });
61
obj.relaySocket.on('error', function (err) { obj.close(0); });
62
@@ -66,9 +68,15 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
68
var domainadd = '';
69
if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
70
obj.wsClient = new WebSocket(protocol + '://127.0.0.1/' + domainadd + 'meshrelay.ashx?auth=' + obj.infos.ip, options);
69
-
71
obj.wsClient.on('open', function () { });
71
- obj.wsClient.on('message', function (data) { if ((obj.relayActive == false) && (data == 'c')) { obj.relayActive = true; obj.relaySocket.resume(); } else { obj.relaySocket.write(data); } });
72
+ obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
73
+ if ((obj.relayActive == false) && (data == 'c')) {
74
+ obj.relayActive = true; obj.relaySocket.resume();
75
+ } else {
76
+ obj.wsClient._socket.pause();
77
+ obj.relaySocket.write(data, function () { obj.wsClient._socket.resume(); });
78
+ }
79
+ });
80
obj.wsClient.on('close', function () { obj.close(0); });
81
obj.tcpServer.close();
82
obj.tcpServer = null;
@@ -130,8 +138,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain, u
138
// If the web socket is closed
139
ws.on('close', function (req) { obj.close(0); });
140
133
- // Send an object
134
- function send(obj) { try { ws.send(JSON.stringify(obj)); } catch (ex) { } }
141
+ // Send an object with flow control
142
+ function send(obj) { ws._socket.pause(); try { ws.send(JSON.stringify(obj), function () { ws._socket.resume(); }); } catch (ex) { } }
143
144
// We are all set, start receiving data
145
ws._socket.resume();