aboutsummaryrefslogtreecommitdiffstats
path: root/view/js
diff options
context:
space:
mode:
authorMario <mario@mariovavti.com>2020-11-14 21:28:50 +0000
committerMario <mario@mariovavti.com>2020-11-14 21:28:50 +0000
commitb63c5f27853aded30c492bdb94a680e5a9c9648b (patch)
tree0d5036dec62e5a3b4abdb34df6993e7634dddf5e /view/js
parent685c569eaf094fd7f354bd3fa8026ecefadfa590 (diff)
downloadvolse-hubzilla-b63c5f27853aded30c492bdb94a680e5a9c9648b.tar.gz
volse-hubzilla-b63c5f27853aded30c492bdb94a680e5a9c9648b.tar.bz2
volse-hubzilla-b63c5f27853aded30c492bdb94a680e5a9c9648b.zip
Polling fallback to server sent events. Polling is the default. SSE must be enabled in /admin/site > Advanced > Enable SSE Notifications if desired.
Diffstat (limited to 'view/js')
-rw-r--r--view/js/main.js82
1 files changed, 57 insertions, 25 deletions
diff --git a/view/js/main.js b/view/js/main.js
index 8ceb0b143..560868046 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -31,6 +31,7 @@ var sse_offset = 0;
var sse_type;
var sse_partial_result = false;
var sse_rmids = [];
+var sse_fallback_interval;
var page_cache = {};
@@ -94,37 +95,56 @@ $(document).ready(function() {
jQuery.timeago.settings.allowFuture = true;
- if(typeof(window.SharedWorker) === 'undefined') {
- // notifications with multiple tabs open will not work very well in this scenario
- var evtSource = new EventSource('/sse');
- evtSource.addEventListener('notifications', function(e) {
- var obj = JSON.parse(e.data);
- sse_handleNotifications(obj, false, false);
- }, false);
+ if(sse_enabled) {
+ if(typeof(window.SharedWorker) === 'undefined') {
+ // notifications with multiple tabs open will not work very well in this scenario
+ var evtSource = new EventSource('/sse');
- document.addEventListener('visibilitychange', function() {
- if (!document.hidden) {
- sse_offset = 0;
- sse_bs_init();
- }
- }, false);
+ evtSource.addEventListener('notifications', function(e) {
+ var obj = JSON.parse(e.data);
+ sse_handleNotifications(obj, false, false);
+ }, false);
- }
- else {
- var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser);
+ document.addEventListener('visibilitychange', function() {
+ if (!document.hidden) {
+ sse_offset = 0;
+ sse_bs_init();
+ }
+ }, false);
- myWorker.port.onmessage = function(e) {
- obj = e.data;
- console.log(obj);
- sse_handleNotifications(obj, false, false);
}
+ else {
+ var myWorker = new SharedWorker('/view/js/sse_worker.js', localUser);
- myWorker.onerror = function(e) {
- myWorker.port.close();
+ myWorker.port.onmessage = function(e) {
+ obj = e.data;
+ console.log(obj);
+ sse_handleNotifications(obj, false, false);
+ }
+
+ myWorker.onerror = function(e) {
+ myWorker.port.close();
+ }
+
+ myWorker.port.start();
}
+ }
+ else {
+ if (!document.hidden)
+ sse_fallback_interval = setInterval(sse_fallback, updateInterval);
- myWorker.port.start();
+ document.addEventListener('visibilitychange', function() {
+ if (document.hidden) {
+ clearInterval(sse_fallback_interval);
+ }
+ else {
+ sse_offset = 0;
+ sse_bs_init();
+ sse_fallback_interval = setInterval(sse_fallback, updateInterval);
+ }
+
+ }, false);
}
$('.notification-link').on('click', { replace: true, followup: false }, sse_bs_notifications);
@@ -224,6 +244,8 @@ $(document).ready(function() {
cache_next_page();
});
+
+
});
function getConversationSettings() {
@@ -1763,8 +1785,6 @@ function sse_bs_init() {
}
function sse_bs_counts() {
-
-
if(sse_bs_active)
return;
@@ -2022,3 +2042,15 @@ function sse_setNotificationsStatus() {
}
}
+
+function sse_fallback() {
+ $.get('/sse', function(obj) {
+ if(! obj)
+ return;
+
+ console.log('sse fallback');
+ console.log(obj);
+
+ sse_handleNotifications(obj, false, false);
+ });
+}