Added ?trace=2 support, to stringify trace output.

Ylian Saint-Hilaire committed May 25, 2021 at 10:47 UTC b24a30ace6bbacc84f0bd4c2e865dc34bb0227b4
2 files changed +8 -4
public/scripts/meshcentral.js
+7 -3
@@ -10,7 +10,7 @@ var MeshServerCreateControl = function (domain, authCookie) {
10 obj.connectstate = 0;
11 obj.pingTimer = null;
12 obj.authCookie = authCookie;
13 - obj.trace = false;
13 + //obj.trace = false;
14
15 obj.xxStateChange = function (newstate, errCode) {
16 if (obj.State == newstate) return;
@@ -48,13 +48,17 @@ var MeshServerCreateControl = function (domain, authCookie) {
48 if ((typeof message != 'object') || (message.action == 'pong')) { return; }
49 if (message.action == 'ping') { obj.send({ action: 'pong' }); }
50 if (message.action == 'close') { if (message.msg) { console.log(message.msg); } obj.Stop(message.cause); return; }
51 - if (obj.trace) { console.log('RECV', message); }
51 + if (obj.trace == 1) { console.log('RECV', message); }
52 + else if (obj.trace == 2) { console.log('RECV', JSON.stringify(message)); }
53 if (obj.onMessage) obj.onMessage(obj, message);
54 };
55
56 obj.send = function (x) {
57 if (obj.socket != null && obj.connectstate == 1) {
57 - if (obj.trace && (x.action != 'ping')) { console.log('SEND', x); }
58 + if (x.action != 'ping') {
59 + if (obj.trace == 1) { console.log('SEND', x); }
60 + else if (obj.trace == 2) { console.log('SEND', JSON.stringify(x)); }
61 + }
62 obj.socket.send(JSON.stringify(x));
63 }
64 }
views/default.handlebars
+1 -1
@@ -1471,7 +1471,7 @@
1471 meshserver = MeshServerCreateControl(domainUrl, authCookie);
1472 meshserver.onStateChanged = onStateChanged;
1473 meshserver.onMessage = onMessage;
1474 - meshserver.trace = (args.trace == 1);
1474 + meshserver.trace = args.trace;
1475 meshserver.Start();
1476
1477 // Setup page controls