Better /v2/health polling in Web UI
The Web UI now only polls when the document is visible (i.e. on-tab), so
that browsers don't eat up memory / cpu / battery polling for changes.
Successful checks of /v2/health also go through the backoff algorithm;
state transition resets it.
@@ -4318,7 +4318,8 @@ $ uaac client add '<span class="hi">[[= p.client_id ]]</span>' \
(function (s) {
var last = "",
every = 5,
- failing = true;
+ timer = undefined,
+ failing = true,
backoff = {
0: 5, /* on success */
5: 6, /* +1 */
@@ -4369,10 +4370,21 @@ $ uaac client add '<span class="hi">[[= p.client_id ]]</span>' \
rehud($global.hud);
},
complete: function () {
- window.setTimeout(ping, every * 1000);
+ timer = window.setTimeout(ping, every * 1000);
}
});
}
+ $(document).on('visibilitychange', function (event) {
+ if (document.hidden) {
+ console.log('pausing /v2/health checks...');
+ if (timer) { window.clearTimeout(timer); }
+ timer = undefined;
+ } else {
+ console.log('resuming /v2/health checks...');
+ every = backoff[0]; /* reset */
+ ping();
+ }
+ });
ping();
})(5);
/* }}} */
