summaryrefslogtreecommitdiffstats
path: root/welco/static
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2017-07-26 06:32:18 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2017-07-26 07:48:32 (GMT)
commit9da4f4a3aee7d1c13fc24b1384bb4e244d2b96a7 (patch)
tree492ee8cb2e02e43e880bfd899667693867f9a8e8 /welco/static
parente4b6216220e7426aec0e40deebd159ec46305175 (diff)
downloadwelco-9da4f4a3aee7d1c13fc24b1384bb4e244d2b96a7.zip
welco-9da4f4a3aee7d1c13fc24b1384bb4e244d2b96a7.tar.gz
welco-9da4f4a3aee7d1c13fc24b1384bb4e244d2b96a7.tar.bz2
phone: keep track of failed ajax calls and reload if too many (#17793)v0.51
Diffstat (limited to 'welco/static')
-rw-r--r--welco/static/js/welco.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/welco/static/js/welco.js b/welco/static/js/welco.js
index 02c3229..9ac903d 100644
--- a/welco/static/js/welco.js
+++ b/welco/static/js/welco.js
@@ -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);
}
});
}