Fixed meshctrl.js shell when ping/pong are active.

Ylian Saint-Hilaire committed Apr 26, 2021 at 19:01 UTC 3b637ad389f72e43f1b3cf00bec5764e0b7b982c
2 files changed +8 -2
agents/meshcore.js
+2 -2
@@ -1610,7 +1610,7 @@ function onTunnelClosed() {
1610 function onTunnelSendOk() { /*sendConsoleText("Tunnel #" + this.index + " SendOK.", this.sessionid);*/ }
1611 function onTunnelData(data) {
1612 //console.log("OnTunnelData");
1613 - sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data);
1613 + //sendConsoleText('OnTunnelData, ' + data.length + ', ' + typeof data + ', ' + data);
1614
1615 // If this is upload data, save it to file
1616 if ((this.httprequest.uploadFile) && (typeof data == 'object') && (data[0] != 123)) {
@@ -2547,7 +2547,7 @@ function onTunnelControlData(data, ws) {
2547 if (ws == null) { ws = this; }
2548 if (typeof data == 'string') { try { obj = JSON.parse(data); } catch (e) { sendConsoleText('Invalid control JSON: ' + data); return; } }
2549 else if (typeof data == 'object') { obj = data; } else { return; }
2550 - sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data));
2550 + //sendConsoleText('onTunnelControlData(' + ws.httprequest.protocol + '): ' + JSON.stringify(data));
2551 //console.log('onTunnelControlData: ' + JSON.stringify(data));
2552
2553 switch (obj.type) {
meshctrl.js
+6
@@ -1968,6 +1968,12 @@ function connectTunnel(url) {
1968 settings.tunnelws.on('message', function (rawdata) {
1969 var data = rawdata.toString();
1970 if (settings.tunnelwsstate == 1) {
1971 + // If the incoming text looks exactly like a control command, ignore it.
1972 + if ((typeof data == 'string') && (data.startsWith('{"ctrlChannel":"102938","type":"'))) {
1973 + var ctrlCmd = null;
1974 + try { ctrlCmd = JSON.parse(data); } catch (ex) { }
1975 + if ((ctrlCmd != null) && (ctrlCmd.ctrlChannel == '102938') && (ctrlCmd.type != null)) return; // This is a control command, like ping/pong. Ignore it.
1976 + }
1977 process.stdout.write(data);
1978 } else if (settings.tunnelwsstate == 0) {
1979 if (data == 'c') { console.log('Connected.'); } else if (data == 'cr') { console.log('Connected, session is being recorded.'); } else return;