Improve startup checking

Before this fix, if the daemon wasn't accepting connections
the UI would get an error and then be stuck on the loading screen.

We now check if the daemon is accepting connections first, and then
check for the status.
This commit is contained in:
Job Evers-Meltzer 2017-01-18 09:29:47 -06:00
parent bfbe69a861
commit 2aa10261d9
2 changed files with 37 additions and 28 deletions

View file

@ -14,24 +14,36 @@ var SplashScreen = React.createClass({
}
},
updateStatus: function(was_lagging=false) {
lbry.getDaemonStatus((status) => {
if (status.code == 'started') {
this.props.onLoadDone();
return;
}
this.setState({
details: status.message + (status.is_lagging ? '' : '...'),
isLagging: status.is_lagging,
});
setTimeout(() => {
this.updateStatus(status.is_lagging);
}, 500);
lbry.getDaemonStatus(this._updateStatusCallback);
},
_updateStatusCallback: function(status) {
if (status.code == 'started') {
// Wait until we are able to resolve a name before declaring
// that we are done.
// TODO: This is a hack, and the logic should live in the daemon
// to give us a better sense of when we are actually started
this.setState({
details: 'Waiting for name resolution',
isLagging: false
});
lbry.resolveName('one', () => {
this.props.onLoadDone();
});
return;
}
this.setState({
details: status.message + (status.is_lagging ? '' : '...'),
isLagging: status.is_lagging,
});
setTimeout(() => {
this.updateStatus(status.is_lagging);
}, 500);
},
componentDidMount: function() {
this.updateStatus();
lbry.connect((connected) => {
this.updateStatus();
});
},
render: function() {
return <LoadScreen message={this.props.message} details={this.state.details} isWarning={this.state.isLagging} />;

View file

@ -90,17 +90,18 @@ lbry.call = function (method, params, callback, errorCallback, connectFailedCall
//core
lbry.connect = function(callback)
{
// Check every half second to see if the daemon's running.
// Returns true to callback once connected, or false if it takes too long and we give up.
function checkDaemonRunning(tryNum=0) {
lbry.daemonRunningStatus(function (runningStatus) {
// Check every half second to see if the daemon is accepting connections
// Once this returns True, can call getDaemonStatus to see where
// we are in the startup process
function checkDaemonStarted(tryNum=0) {
lbry.isDaemonAcceptingConnections(function (runningStatus) {
if (runningStatus) {
lbry.isConnected = true;
callback(true);
} else {
if (tryNum <= 600) { // Move # of tries into constant or config option
setTimeout(function () {
checkDaemonRunning(tryNum + 1);
checkDaemonStarted(tryNum + 1);
}, 500);
} else {
callback(false);
@ -108,16 +109,12 @@ lbry.connect = function(callback)
}
});
}
checkDaemonRunning();
checkDaemonStarted();
}
lbry.daemonRunningStatus = function (callback) {
// Returns true/false whether the daemon is running (i.e. fully conncected to the network),
// or null if the AJAX connection to the daemon fails.
lbry.call('is_running', {}, callback, null, function () {
callback(null);
});
lbry.isDaemonAcceptingConnections = function (callback) {
// Returns true/false whether the daemon is at a point it will start returning status
lbry.call('status', {}, () => callback(true), null, () => callback(false))
};
lbry.getDaemonStatus = function (callback) {