now with background polling and indication of online hosts

This commit is contained in:
R. Aidan Campbell 2016-08-25 17:29:57 -04:00
parent a11b097dde
commit 6b8ac65d7f
3 changed files with 39 additions and 1 deletions

View File

@ -162,6 +162,9 @@ main {
-moz-border-radius: 10px;
border-radius: 10px;
}
.host-cell-inactive {
border: 3px solid red;
}
.host-cell:hover {
cursor: pointer;
color: #000 !important;

View File

@ -49,6 +49,35 @@ function restoreUiAfterNaClLoad() {
$('#naclSpinner').hide();
$('#loadingSpinner').css('display', 'none');
showHostsAndSettingsMode();
for(hostUID in hosts) {
beginBackgroundPollingOfHost(hosts[hostUID]);
}
}
function beginBackgroundPollingOfHost(host) {
$("#hostgrid-" + host.serverUid).addClass('host-cell-inactive');
// for each host, first assume it's inactive.
host.initialPing(function () { // initial attempt was a success
$("#hostgrid-" + host.serverUid).removeClass('host-cell-inactive');
window.setInterval(function() {
// every 5 seconds, poll at the address we know it was live at
host.refreshServerInfoAtAddress(host.address).then(function (onSuccess){
$("#hostgrid-" + host.serverUid).removeClass('host-cell-inactive');
}, function (onFailure) {
$("#hostgrid-" + host.serverUid).addClass('host-cell-inactive');
});
}, 5000);
}, function () { // initial attempt was a failure
$("#hostgrid-" + host.serverUid).addClass('host-cell-inactive');
window.setInterval(function() {
if(host.refreshServerInfoAtAddress(host.address)) {
$("#hostgrid-" + host.serverUid).removeClass('host-cell-inactive');
} else {
$("#hostgrid-" + host.serverUid).addClass('host-cell-inactive');
}
}, 5000);
});
}
function snackbarLog(givenMessage) {

View File

@ -90,9 +90,10 @@ NvHTTP.prototype = {
// try HTTPS first
return sendMessage('openUrl', [ 'https://' + givenAddress + ':47984' + '/serverinfo?' + _self._buildUidStr(), false]).then(function(ret) {
if (!_self._parseServerInfo(ret)) { // if that fails
console.log('Failed to parse serverinfo from HTTPS, falling back to HTTP');
// try HTTP as a failover. Useful to clients who aren't paired yet
return sendMessage('openUrl', [ 'http://' + givenAddress + ':47989' + '/serverinfo?' + _self._buildUidStr(), false]).then(function(retHttp) {
_self._parseServerInfo(retHttp);
return _self._parseServerInfo(retHttp);
});
}
});
@ -148,6 +149,11 @@ NvHTTP.prototype = {
return false;
}
if(_self.serverUid != $root.find('uniqueid').text().trim() && _self.serverUid != null) {
// if we received a UID that isn't the one we expected, fail.
return false;
}
console.log('parsing server info: ');
console.log($root);