aboutsummaryrefslogtreecommitdiffstats
path: root/view
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
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')
-rw-r--r--view/js/main.js82
-rwxr-xr-xview/tpl/admin_site.tpl1
-rwxr-xr-xview/tpl/head.tpl1
3 files changed, 59 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);
+ });
+}
diff --git a/view/tpl/admin_site.tpl b/view/tpl/admin_site.tpl
index 5e10e6eea..8d32ba9a4 100755
--- a/view/tpl/admin_site.tpl
+++ b/view/tpl/admin_site.tpl
@@ -95,6 +95,7 @@
</div>
<h3>{{$advanced}}</h3>
+ {{include file="field_checkbox.tpl" field=$sse_enabled}}
{{include file="field_input.tpl" field=$imagick_path}}
{{include file="field_input.tpl" field=$proxy}}
{{include file="field_input.tpl" field=$proxyuser}}
diff --git a/view/tpl/head.tpl b/view/tpl/head.tpl
index bd4cf3747..0d212e029 100755
--- a/view/tpl/head.tpl
+++ b/view/tpl/head.tpl
@@ -9,6 +9,7 @@
{{$plugins}}
<script>
var updateInterval = {{$update_interval}};
+ var sse_enabled = {{$sse_enabled}};
var localUser = {{if $local_channel}}{{$local_channel}}{{else}}false{{/if}};
var zid = {{if $zid}}'{{$zid}}'{{else}}null{{/if}};
var justifiedGalleryActive = false;