From 029f92f821005221ece0fdb4a882c931dd9bf18f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 27 Aug 2016 16:58:35 -0700 Subject: [PATCH] Fix mDNS adding and updating hosts --- static/js/index.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 59e0ff8..0237527 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -744,15 +744,24 @@ function onWindowLoad(){ findNvService(function (finder, opt_error) { if (finder.byService_['_nvstream._tcp']) { var ips = Object.keys(finder.byService_['_nvstream._tcp']); - for (var ip in ips) { + for (var i in ips) { + var ip = ips[i]; if (finder.byService_['_nvstream._tcp'][ip]) { var mDnsDiscoveredHost = new NvHTTP(ip, myUniqueid); - if(hosts[mDnsDiscoveredHost.serverUid] != null) { - // if we're seeing a host we've already seen before, update it for the current local IP. - hosts[mDnsDiscoveredHost.serverUid].address = mDnsDiscoveredHost.address; - } else { - addHostToGrid(mDnsDiscoveredHost); - } + mDnsDiscoveredHost.pollServer(function() { + // Just drop this if the host doesn't respond + if (!mDnsDiscoveredHost.online) { + return; + } + + if (hosts[mDnsDiscoveredHost.serverUid] != null) { + // if we're seeing a host we've already seen before, update it for the current local IP. + hosts[mDnsDiscoveredHost.serverUid].address = mDnsDiscoveredHost.address; + } else { + beginBackgroundPollingOfHost(mDnsDiscoveredHost); + addHostToGrid(mDnsDiscoveredHost); + } + }); } } }