Add debug facilities in messaging module toggled by GET parameter
This commit is contained in:
parent
b2253b81d6
commit
ac114c16df
1 changed files with 21 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
function Messaging(screen) {
|
function Messaging(screen) {
|
||||||
var ws = new WebSocket('ws://' + window.location.hostname + '/play/');
|
var ws = new WebSocket('ws://' + window.location.hostname + '/play/');
|
||||||
|
var debug = getParameters().debug;
|
||||||
|
var doLog = debug != undefined && debug.match(/^(?:1|t(?:rue)?|v(?:rai)?)$/i);
|
||||||
var keepAlivePeriod = 20000;
|
var keepAlivePeriod = 20000;
|
||||||
var routes = {callbacks: [], children: {}};
|
var routes = {callbacks: [], children: {}};
|
||||||
|
|
||||||
|
@ -25,6 +27,15 @@ function Messaging(screen) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getParameters() {
|
||||||
|
var o = {};
|
||||||
|
window.location.search.substr(1).split('&').forEach(function(s) {
|
||||||
|
var t = s.split('=');
|
||||||
|
o[t[0]] = t[1];
|
||||||
|
});
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
function addEventListener(path, callback) {
|
function addEventListener(path, callback) {
|
||||||
var route = get(routes, path, true);
|
var route = get(routes, path, true);
|
||||||
route.callbacks.push(callback);
|
route.callbacks.push(callback);
|
||||||
|
@ -44,8 +55,16 @@ function Messaging(screen) {
|
||||||
} else {
|
} else {
|
||||||
debug.textContent = event.data;
|
debug.textContent = event.data;
|
||||||
}
|
}
|
||||||
|
o.direction = 'client < server';
|
||||||
|
log(o);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function log(message) {
|
||||||
|
if(doLog) {
|
||||||
|
console.log(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function start() {
|
function start() {
|
||||||
ping();
|
ping();
|
||||||
addEventListener(["Pong"], ping);
|
addEventListener(["Pong"], ping);
|
||||||
|
@ -54,6 +73,8 @@ function Messaging(screen) {
|
||||||
|
|
||||||
function send(o) {
|
function send(o) {
|
||||||
ws.send(JSON.stringify(o));
|
ws.send(JSON.stringify(o));
|
||||||
|
o.direction = 'client > server';
|
||||||
|
log(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ping() {
|
function ping() {
|
||||||
|
|
Loading…
Reference in a new issue