From 853d061acbd670609498f7bbd2091f5412f838a8 Mon Sep 17 00:00:00 2001 From: "R. Aidan Campbell" Date: Tue, 26 Jul 2016 15:20:24 -0400 Subject: [PATCH] added backend support for storing varios addressing methods of hosts --- static/js/index.js | 14 ++++++++++---- static/js/utils.js | 5 ++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 683ee13..cdc38a3 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -211,7 +211,7 @@ function addHostToGrid(host) { function continueAddHost() { var inputHost = $('#dialogInputHost').val(); - var nvhttpHost = new NvHTTP(inputHost, myUniqueid); + var nvhttpHost = new NvHTTP(inputHost, myUniqueid, inputHost); pairTo(nvhttpHost, function() { addHostToGrid(nvhttpHost); @@ -603,11 +603,11 @@ function onWindowLoad(){ storeData('uniqueid', myUniqueid, null); } }); - // load previously connected hosts, and revive them back into a class + // load previously connected hosts, which have been killed into an object, and revive them back into a class chrome.storage.sync.get('hosts', function(previousValue) { hosts = previousValue.hosts != null ? previousValue.hosts : {}; for(hostUID in hosts) { // programmatically add each new host. - var revivedHost = new NvHTTP(hosts[hostUID].address, myUniqueid); + var revivedHost = new NvHTTP(hosts[hostUID].address, myUniqueid, hosts[hostUID].userEnteredAddress); revivedHost.serverUid = hosts[hostUID].serverUid; revivedHost.externalIP = hosts[hostUID].externalIP; revivedHost.hostname = hosts[hostUID].hostname; @@ -621,7 +621,13 @@ function onWindowLoad(){ var ips = Object.keys(finder.byService_['_nvstream._tcp']); for (var ip in ips) { if (finder.byService_['_nvstream._tcp'][ip]) { - addHostToGrid(new NvHTTP(ip, myUniqueid)); + 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].localIp = mDnsDiscoveredHost.localIp; + } else { + addHostToGrid(mDnsDiscoveredHost); + } } } } diff --git a/static/js/utils.js b/static/js/utils.js index de3cdac..15921a0 100644 --- a/static/js/utils.js +++ b/static/js/utils.js @@ -31,10 +31,9 @@ String.prototype.toHex = function() { return hex; } -function NvHTTP(address, clientUid) { +function NvHTTP(address, clientUid, userEnteredAddress = '') { this.address = address; this.paired = false; - this.supports4K = false; this.currentGame = 0; this.serverMajorVersion = 0; this.clientUid = clientUid; @@ -42,6 +41,7 @@ function NvHTTP(address, clientUid) { this._baseUrlHttp = 'http://' + address + ':47989'; this._memCachedBoxArtArray = {}; + this.userEnteredAddress = userEnteredAddress; // if the user entered an address, we keep it on hand to try when polling this.serverUid = ''; this.GfeVersion = ''; this.supportedDisplayModes = {}; // key: y-resolution:x-resolution, value: array of supported framerates (only ever seen 30 or 60, here) @@ -90,7 +90,6 @@ NvHTTP.prototype = { string += 'server address: ' + _self.address + '\r\n'; string += 'server UID: ' + _self.serverUid + '\r\n'; string += 'is paired: ' + _self.paired + '\r\n'; - string += 'supports 4K: ' + _self.supports4K + '\r\n'; string += 'current game: ' + _self.currentGame + '\r\n'; string += 'server major version: ' + _self.serverMajorVersion + '\r\n'; string += 'GFE version: ' + _self.GfeVersion + '\r\n';