summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@protonmail.com>2019-06-16 12:34:00 -0500
committerOmar Roth <omarroth@protonmail.com>2019-06-16 12:55:17 -0500
commit17edfd65736fde44d16e5fe9b4e68e637246a127 (patch)
treeeacfa846130e16811a86f31a34726fb89a99ff64
parent458e9d6cc77c467a9ae61b5baf151978de92cf31 (diff)
downloadinvidious-17edfd65736fde44d16e5fe9b4e68e637246a127.tar.gz
invidious-17edfd65736fde44d16e5fe9b4e68e637246a127.tar.bz2
invidious-17edfd65736fde44d16e5fe9b4e68e637246a127.zip
Shorten timeout for AJAX
-rw-r--r--assets/js/embed.js2
-rw-r--r--assets/js/notifications.js20
-rw-r--r--assets/js/subscribe_widget.js4
-rw-r--r--assets/js/themes.js2
-rw-r--r--assets/js/watch.js8
-rw-r--r--assets/js/watched_widget.js4
-rw-r--r--src/invidious/views/subscription_manager.ecr2
-rw-r--r--src/invidious/views/token_manager.ecr2
8 files changed, 19 insertions, 25 deletions
diff --git a/assets/js/embed.js b/assets/js/embed.js
index 1f742864..16a79e73 100644
--- a/assets/js/embed.js
+++ b/assets/js/embed.js
@@ -16,7 +16,7 @@ function get_playlist(plid, retries = 5) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', plid_url, true);
xhr.onreadystatechange = function () {
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');
diff --git a/assets/js/subscribe_widget.js b/assets/js/subscribe_widget.js
index 1201a554..6c21bffb 100644
--- a/assets/js/subscribe_widget.js
+++ b/assets/js/subscribe_widget.js
@@ -17,7 +17,7 @@ function subscribe(retries = 5) {
'&c=' + subscribe_data.ucid;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -57,7 +57,7 @@ function unsubscribe(retries = 5) {
'&c=' + subscribe_data.ucid;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
diff --git a/assets/js/themes.js b/assets/js/themes.js
index 826c6597..683aea39 100644
--- a/assets/js/themes.js
+++ b/assets/js/themes.js
@@ -7,7 +7,7 @@ toggle_theme.addEventListener('click', function () {
var url = '/toggle_theme?redirect=false';
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', url, true);
set_mode(dark_mode);
diff --git a/assets/js/watch.js b/assets/js/watch.js
index fb4ab4b4..2f027b1a 100644
--- a/assets/js/watch.js
+++ b/assets/js/watch.js
@@ -134,7 +134,7 @@ function get_playlist(plid, retries = 5) {
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', plid_url, true);
xhr.onreadystatechange = function () {
@@ -212,7 +212,7 @@ function get_reddit_comments(retries = 5) {
'&hl=' + video_data.preferences.locale;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
@@ -289,7 +289,7 @@ function get_youtube_comments(retries = 5) {
'&thin_mode=' + video_data.preferences.thin_mode;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
@@ -360,7 +360,7 @@ function get_youtube_replies(target, load_more) {
'&continuation=' + continuation;
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
diff --git a/assets/js/watched_widget.js b/assets/js/watched_widget.js
index 4a5cfd2d..1e88fa27 100644
--- a/assets/js/watched_widget.js
+++ b/assets/js/watched_widget.js
@@ -6,7 +6,7 @@ function mark_watched(target) {
'&id=' + target.getAttribute('data-id');
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -31,7 +31,7 @@ function mark_unwatched(target) {
'&id=' + target.getAttribute('data-id');
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
diff --git a/src/invidious/views/subscription_manager.ecr b/src/invidious/views/subscription_manager.ecr
index 508cf51c..aa6c5d81 100644
--- a/src/invidious/views/subscription_manager.ecr
+++ b/src/invidious/views/subscription_manager.ecr
@@ -65,7 +65,7 @@ function remove_subscription(target) {
'&c=' + target.getAttribute('data-ucid');
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
diff --git a/src/invidious/views/token_manager.ecr b/src/invidious/views/token_manager.ecr
index 659f5ab3..e1c0228f 100644
--- a/src/invidious/views/token_manager.ecr
+++ b/src/invidious/views/token_manager.ecr
@@ -57,7 +57,7 @@ function revoke_token(target) {
'&session=' + target.getAttribute('data-session');
var xhr = new XMLHttpRequest();
xhr.responseType = 'json';
- xhr.timeout = 20000;
+ xhr.timeout = 10000;
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');