From 6f78f9e2764109bfa783eabc396512dcb4a72baa Mon Sep 17 00:00:00 2001 From: si458 Date: Mon, 12 Feb 2024 11:46:16 +0000 Subject: [PATCH] fix one ping/pong function Signed-off-by: si458 --- apprelays.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/apprelays.js b/apprelays.js index d2cb83c8..aeb4d635 100644 --- a/apprelays.js +++ b/apprelays.js @@ -842,24 +842,21 @@ module.exports.CreateMstscRelay = function (parent, db, ws, req, args, domain) { obj.relaySocket.resume(); } } else { - if (typeof data == 'string') { - // Forward any ping/pong commands to the browser - var cmd = null; - try { // Forward any ping/pong commands to the browser - cmd = JSON.parse(data); - if ((cmd != null) && (cmd.ctrlChannel == '102938')) { - if (cmd.type == 'ping') { send(['ping']); } - else if (cmd.type == 'pong') { send(['pong']); } - } - return; - } catch (ex) { // You are not JSON data so just send over relaySocket - obj.wsClient._socket.pause(); - try { - obj.relaySocket.write(data, function () { - if (obj.wsClient && obj.wsClient._socket) { try { obj.wsClient._socket.resume(); } catch (ex) { console.log(ex); } } - }); - } catch (ex) { console.log(ex); obj.close(); } + try { // Forward any ping/pong commands to the browser + var cmd = JSON.parse(data); + if ((cmd != null) && (cmd.ctrlChannel == '102938')) { + if (cmd.type == 'ping') { send(['ping']); } + else if (cmd.type == 'pong') { send(['pong']); } } + return; + } catch (ex) { // You are not JSON data so just send over relaySocket + obj.wsClient._socket.pause(); + try { + obj.relaySocket.write(data, function () { + if (obj.wsClient && obj.wsClient._socket) { try { obj.wsClient._socket.resume(); } catch (ex) { console.log(ex); } } + }); + } catch (ex) { console.log(ex); obj.close(); } + } } }); obj.wsClient.on('close', function () { parent.parent.debug('relay', 'RDP: Relay websocket closed'); obj.close(); });