diff --git a/static/css/style.css b/static/css/style.css index 0d48836..9a39a02 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -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; diff --git a/static/js/index.js b/static/js/index.js index cdc38a3..b571d9d 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -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) { diff --git a/static/js/utils.js b/static/js/utils.js index f129df0..90320f3 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -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); }); } }); @@ -147,6 +148,11 @@ NvHTTP.prototype = { if($root.attr("status_code") != 200) { 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);