phone: keep track of failed ajax calls and reload if too many (#17793)

This commit is contained in:
Frédéric Péters 2017-07-26 08:32:18 +02:00
parent e4b6216220
commit 9da4f4a3ae
1 changed files with 18 additions and 2 deletions

View File

@ -527,17 +527,31 @@ $(function() {
});
if ($('.source-phone').length) {
var failed_ajax_calls = 0;
function handle_ajax_error() {
failed_ajax_calls += 1;
if (failed_ajax_calls == 10) {
window.location.reload();
}
}
function check_active_call() {
var active_call_url = $('[data-active-call-url]').data('active-call-url');
$.ajax({url: active_call_url,
dataType: 'json',
success: function(response) {
failed_ajax_calls = 0;
if (response.active === false) {
$('<span class="done"> (terminé)</span>').appendTo($('div.phonecall.active h1'));
window.setTimeout(check_calls, 1000);
} else {
window.setTimeout(check_active_call, 5000);
}
},
error: function() {
handle_ajax_error();
window.setTimeout(check_active_call, 5000 + failed_ajax_calls * 1000);
}
});
}
@ -550,6 +564,7 @@ $(function() {
$.ajax({url: current_calls_url,
dataType: 'json',
success: function(response) {
failed_ajax_calls = 0;
if (response.data.calls.length != 0) {
/* got a call */
var caller = response.data.calls[0].caller;
@ -566,8 +581,9 @@ $(function() {
}
window.setTimeout(check_calls, 1000);
},
error: function() {
window.setTimeout(check_calls, 1000);
error: function(error) {
handle_ajax_error();
window.setTimeout(check_calls, 1000 + failed_ajax_calls * 1000);
}
});
}