Add automatic detection of WAN IP address

This commit is contained in:
Cameron Gutman
2018-11-17 11:27:59 -08:00
parent cb80160605
commit 4613d4977c
4 changed files with 53 additions and 1 deletions

View File

@@ -107,6 +107,7 @@ function restoreUiAfterNaClLoad() {
if (hosts[returneMdnsDiscoveredHost.serverUid] != null) {
// if we're seeing a host we've already seen before, update it for the current local IP.
hosts[returneMdnsDiscoveredHost.serverUid].address = returneMdnsDiscoveredHost.address;
hosts[returneMdnsDiscoveredHost.serverUid].updateExternalAddressIP4();
} else {
// Host must be in the grid before starting background polling
addHostToGrid(returneMdnsDiscoveredHost, true);
@@ -405,6 +406,9 @@ function addHostToGrid(host, ismDNSDiscovered) {
}
$('#host-grid').append(outerDiv);
hosts[host.serverUid] = host;
if (ismDNSDiscovered) {
hosts[host.serverUid].updateExternalAddressIP4();
}
}
function removeClicked(host) {

View File

@@ -244,7 +244,14 @@ NvHTTP.prototype = {
this.serverMajorVersion = parseInt(this.appVersion.substring(0, 1), 10);
this.serverUid = $root.find('uniqueid').text().trim();
this.hostname = $root.find('hostname').text().trim();
this.externalIP = $root.find('ExternalIP').text().trim();
var externIP = $root.find('ExternalIP').text().trim();
if (externIP) {
// New versions of GFE don't have this field, so don't overwrite
// the one we found via STUN
this.externalIP = externIP;
}
try { // these aren't critical for functionality, and don't necessarily exist in older GFE versions.
this.GfeVersion = $root.find('GfeVersion').text().trim();
this.gputype = $root.find('gputype').text().trim();
@@ -439,6 +446,18 @@ NvHTTP.prototype = {
.then(this.refreshServerInfo());
},
updateExternalAddressIP4: function() {
console.log('%c[utils.js, updateExternalAddressIP4]', 'color: gray;', 'Finding external IPv4 address for ' + this.hostname);
return sendMessage('STUN').then(function(addr) {
if (addr) {
this.externalIP = addr
console.log('%c[utils.js, updateExternalAddressIP4]', 'color: gray;', 'Found external IPv4 address: ' + this.hostname + ' -> ' + this.externalIP);
} else {
console.log('%c[utils.js, updateExternalAddressIP4]', 'color: gray;', 'External IPv4 address lookup failed');
}
}.bind(this))
},
pair: function(randomNumber) {
return this.refreshServerInfo().then(function() {
if (this.paired)