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

This commit is contained in:
Ylian Saint-Hilaire 2021-05-25 10:47:10 -07:00
parent fba2ac227a
commit b24a30ace6
2 changed files with 8 additions and 4 deletions

View File

@ -10,7 +10,7 @@ var MeshServerCreateControl = function (domain, authCookie) {
obj.connectstate = 0;
obj.pingTimer = null;
obj.authCookie = authCookie;
obj.trace = false;
//obj.trace = false;
obj.xxStateChange = function (newstate, errCode) {
if (obj.State == newstate) return;
@ -48,13 +48,17 @@ var MeshServerCreateControl = function (domain, authCookie) {
if ((typeof message != 'object') || (message.action == 'pong')) { return; }
if (message.action == 'ping') { obj.send({ action: 'pong' }); }
if (message.action == 'close') { if (message.msg) { console.log(message.msg); } obj.Stop(message.cause); return; }
if (obj.trace) { console.log('RECV', message); }
if (obj.trace == 1) { console.log('RECV', message); }
else if (obj.trace == 2) { console.log('RECV', JSON.stringify(message)); }
if (obj.onMessage) obj.onMessage(obj, message);
};
obj.send = function (x) {
if (obj.socket != null && obj.connectstate == 1) {
if (obj.trace && (x.action != 'ping')) { console.log('SEND', x); }
if (x.action != 'ping') {
if (obj.trace == 1) { console.log('SEND', x); }
else if (obj.trace == 2) { console.log('SEND', JSON.stringify(x)); }
}
obj.socket.send(JSON.stringify(x));
}
}

View File

@ -1471,7 +1471,7 @@
meshserver = MeshServerCreateControl(domainUrl, authCookie);
meshserver.onStateChanged = onStateChanged;
meshserver.onMessage = onMessage;
meshserver.trace = (args.trace == 1);
meshserver.trace = args.trace;
meshserver.Start();
// Setup page controls