var ajax_site = 'ajax';
var refresh_rate = 3000;
var send_timeout = 20000;
var retry_rate = 3000;
function Blocker(sleeper) {
this.counter = 0;
this.waiting = false;
this.sleeper = sleeper;
}
Blocker.prototype.setHook = function() {
var blocker = this;
return function() {
blocker.counter++;
}
}
Blocker.prototype.setNotifier = function(cb) {
var blocker = this;
return function() {
cb.apply(this, arguments);
if (--blocker.counter == 0 && blocker.waiting)
blocker.sleeper();
}
};
Blocker.prototype.go = function() {
if (this.counter == 0)
this.sleeper();
this.waiting = true;
}
function send_request(on_success) {
$.ajax({
url: ajax_site,
type: 'GET',
cache: false,
dataType: 'json',
async: true,
success: on_success,
timeout: send_timeout,
error: function(a, b, c) {
console.log("failed while connecting, reason: " + b);
setTimeout(function() {
send_request(on_success);
}, retry_rate);
}
});
}
function hex(x) {
return ("0" + parseInt(x).toString(16)).slice(-2);
}
function random_range(min, max) {
return Math.ran