Added support for Browser Ping/Pong in RDP sessions.
Ylian Saint-Hilaire committed
May 5, 2022 at 12:38 UTC
4ce9e09e91f8471a7a189528cb1e17644fe50129
1 file changed
+14
-6
apprelays.js
+14
-6
@@ -73,8 +73,8 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
73
if (obj.wsClient) { obj.wsClient.close(); delete obj.wsClient; }
74
if (obj.tcpServer) { obj.tcpServer.close(); delete obj.tcpServer; }
75
if (rdpClient) { rdpClient.close(); rdpClient = null; }
76
- if ((arg == 1) || (arg == null)) { try { ws.close(); } catch (e) { console.log(e); } } // Soft close, close the websocket
77
- if (arg == 2) { try { ws._socket._parent.end(); } catch (e) { console.log(e); } } // Hard close, close the TCP socket
76
+ if ((arg == 1) || (arg == null)) { try { ws.close(); } catch (ex) { console.log(ex); } } // Soft close, close the websocket
77
+ if (arg == 2) { try { ws._socket._parent.end(); } catch (ex) { console.log(ex); } } // Hard close, close the TCP socket
78
obj.ws.removeAllListeners();
79
obj.relayActive = false;
80
@@ -105,16 +105,24 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) {
105
const protocol = (args.tlsoffload) ? 'ws' : 'wss';
106
var domainadd = '';
107
if ((domain.dns == null) && (domain.id != '')) { domainadd = domain.id + '/' }
108
- const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?noping=1&p=10&auth=' + obj.infos.ip; // Protocol 10 is Web-RDP
108
+ const url = protocol + '://localhost:' + args.port + '/' + domainadd + (((obj.mtype == 3) && (obj.relaynodeid == null)) ? 'local' : 'mesh') + 'relay.ashx?p=10&auth=' + obj.infos.ip; // Protocol 10 is Web-RDP
109
parent.parent.debug('relay', 'RDP: Connection websocket to ' + url);
110
obj.wsClient = new WebSocket(url, options);
111
obj.wsClient.on('open', function () { parent.parent.debug('relay', 'RDP: Relay websocket open'); });
112
obj.wsClient.on('message', function (data) { // Make sure to handle flow control.
113
- if ((obj.relayActive == false) && (data == 'c')) {
114
- obj.relayActive = true; obj.relaySocket.resume();
113
+ if (obj.relayActive == false) {
114
+ if ((data == 'c') || (data == 'cr')) {
115
+ obj.relayActive = true;
116
+ obj.relaySocket.resume();
117
+ }
118
} else {
119
+ if (typeof data == 'string') return; // Only process binary data, this will include ping/ping
120
obj.wsClient._socket.pause();
117
- try { obj.relaySocket.write(data, function () { try { obj.wsClient._socket.resume(); } catch (ex) { } }); } catch (ex) { obj.close(); }
121
+ try {
122
+ obj.relaySocket.write(data, function () {
123
+ try { obj.wsClient._socket.resume(); } catch (ex) { console.log(ex); }
124
+ });
125
+ } catch (ex) { console.log(ex); obj.close(); }
126
}
127
});
128
obj.wsClient.on('close', function () { parent.parent.debug('relay', 'RDP: Relay websocket closed'); obj.close(); });