From 17edfd65736fde44d16e5fe9b4e68e637246a127 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 16 Jun 2019 12:34:00 -0500 Subject: Shorten timeout for AJAX --- assets/js/notifications.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'assets/js/notifications.js') diff --git a/assets/js/notifications.js b/assets/js/notifications.js index 4e7be42d..65c45611 100644 --- a/assets/js/notifications.js +++ b/assets/js/notifications.js @@ -7,7 +7,7 @@ function get_subscriptions(callback, retries = 5) { var xhr = new XMLHttpRequest(); xhr.responseType = 'json'; - xhr.timeout = 20000; + xhr.timeout = 10000; xhr.open('GET', '/api/v1/auth/subscriptions', true); xhr.onreadystatechange = function () { @@ -82,14 +82,8 @@ function create_notification_stream(subscriptions) { notifications.onerror = function (event) { console.log('Something went wrong with notifications, trying to reconnect...'); - notifications.close(); - setTimeout(function () { get_subscriptions(create_notification_stream) }, 100); - } - - notifications.ontimeout = function (event) { - console.log('Something went wrong with notifications, trying to reconnect...'); - notifications.close(); - get_subscriptions(create_notification_stream); + notifications = { close: function () { } }; + setTimeout(function () { get_subscriptions(create_notification_stream) }, 1000); } notifications.stream(); @@ -103,11 +97,11 @@ window.addEventListener('load', function (e) { } else { setTimeout(function () { if (!localStorage.getItem('stream')) { - notifications = true; + notifications = { close: function () { } }; get_subscriptions(create_notification_stream); localStorage.setItem('stream', true); } - }, Math.random() * 1000 + 10); + }, Math.random() * 1000 + 50); } window.addEventListener('storage', function (e) { @@ -117,11 +111,11 @@ window.addEventListener('load', function (e) { } else { setTimeout(function () { if (!localStorage.getItem('stream')) { - notifications = true; + notifications = { close: function () { } }; get_subscriptions(create_notification_stream); localStorage.setItem('stream', true); } - }, Math.random() * 1000 + 10); + }, Math.random() * 1000 + 50); } } else if (e.key === 'notification_count') { var notification_ticker = document.getElementById('notification_ticker'); -- cgit v1.2.3