Avoid calling refreshServerInfo() before selecting an address

This commit is contained in:
Cameron Gutman 2016-08-27 17:26:46 -07:00
parent 029f92f821
commit 344dcc0bc3

View File

@ -170,7 +170,14 @@ function pairTo(nvhttpHost, onSuccess, onFailure) {
} }
var _api = nvhttpHost; var _api = nvhttpHost;
_api.refreshServerInfo().then(function (ret) { _api.pollServer(function (ret) {
if (!_api.online) {
snackbarLog('Failed to connect to ' + _api.address + '! Are you sure the host is on?');
console.log(_api.toString());
onFailure();
return;
}
if (_api.paired) { if (_api.paired) {
onSuccess(); onSuccess();
return; return;
@ -205,12 +212,6 @@ function pairTo(nvhttpHost, onSuccess, onFailure) {
console.log(_api.toString()); console.log(_api.toString());
onFailure(); onFailure();
}); });
}, function (failedRefreshInfo) {
snackbarLog('Failed to connect to ' + _api.address + '! Are you sure the host is on?');
console.log('Returned error was: ' + failedRefreshInfo);
console.log('failed API object: ');
console.log(_api.toString());
onFailure();
}); });
} }
@ -279,15 +280,13 @@ function addHostToGrid(host) {
function continueAddHost() { function continueAddHost() {
var inputHost = $('#dialogInputHost').val(); var inputHost = $('#dialogInputHost').val();
var _nvhttpHost = new NvHTTP(inputHost, myUniqueid, inputHost); var _nvhttpHost = new NvHTTP(inputHost, myUniqueid, inputHost);
pairTo(_nvhttpHost, pairTo(_nvhttpHost,
function() { function() {
_nvhttpHost.refreshServerInfo().then(function (onSuccess) { beginBackgroundPollingOfHost(_nvhttpHost);
addHostToGrid(_nvhttpHost); addHostToGrid(_nvhttpHost);
saveHosts(); saveHosts();
document.querySelector('#addHostDialog').close(); document.querySelector('#addHostDialog').close();
}, function (onFailure) {
console.log('FAILURE!');
});
}, },
function() { function() {
snackbarLog('pairing to ' + inputHost + ' failed!'); snackbarLog('pairing to ' + inputHost + ' failed!');
@ -584,6 +583,10 @@ function stopGameWithConfirmation() {
} }
function stopGame(callbackFunction) { function stopGame(callbackFunction) {
if (!api.paired) {
return;
}
api.refreshServerInfo().then(function (ret) { api.refreshServerInfo().then(function (ret) {
api.getAppById(api.currentGame).then(function (runningApp) { api.getAppById(api.currentGame).then(function (runningApp) {
if (!runningApp) { if (!runningApp) {