mirror of
https://github.com/LBRYFoundation/lbry-desktop.git
synced 2025-08-29 08:21:30 +00:00
Fixes to improve loading screen
- Add optional "connection failed" callback to lbry.call() - Make loading screen handle condition where daemon is not running at all (i.e. AJAX connection fails)
This commit is contained in:
parent
9bf1e6c55a
commit
4bdadc4551
1 changed files with 27 additions and 10 deletions
37
js/lbry.js
37
js/lbry.js
|
@ -6,7 +6,7 @@ var lbry = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry.call = function (method, params, callback)
|
lbry.call = function (method, params, callback, connectFailedCallback)
|
||||||
{
|
{
|
||||||
var xhr = new XMLHttpRequest;
|
var xhr = new XMLHttpRequest;
|
||||||
xhr.addEventListener('load', function() {
|
xhr.addEventListener('load', function() {
|
||||||
|
@ -19,6 +19,13 @@ lbry.call = function (method, params, callback)
|
||||||
console.log(method_output.result);
|
console.log(method_output.result);
|
||||||
callback(method_output.result);
|
callback(method_output.result);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (connectFailedCallback) {
|
||||||
|
xhr.addEventListener('error', function (e) {
|
||||||
|
connectFailedCallback(e);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
xhr.open('POST', 'http://localhost:5279/lbryapi', true);
|
xhr.open('POST', 'http://localhost:5279/lbryapi', true);
|
||||||
xhr.send(JSON.stringify({
|
xhr.send(JSON.stringify({
|
||||||
'jsonrpc': '2.0',
|
'jsonrpc': '2.0',
|
||||||
|
@ -33,24 +40,34 @@ lbry.connect = function(callback)
|
||||||
{
|
{
|
||||||
// Check every half second to see if the daemon's running.
|
// 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.
|
// Returns true to callback once connected, or false if it takes too long and we give up.
|
||||||
var try_num = 0;
|
function checkDaemonRunning(tryNum=0) {
|
||||||
var check_connected = setInterval(function() {
|
lbry.daemonRunningStatus(function (runningStatus) {
|
||||||
lbry.call('is_running', {}, function(is_running) {
|
if (runningStatus) {
|
||||||
if (is_running) {
|
|
||||||
lbry.isConnected = true;
|
lbry.isConnected = true;
|
||||||
clearInterval(check_connected);
|
|
||||||
callback(true);
|
callback(true);
|
||||||
} else {
|
} else {
|
||||||
if (try_num >= 20) { // Move this into a constant or config option
|
if (tryNum <= 50) { // Move # of tries into constant or config option
|
||||||
clearInterval(check_connected);
|
setTimeout(function () {
|
||||||
|
checkDaemonRunning(tryNum + 1);
|
||||||
|
}, 500);
|
||||||
|
} else {
|
||||||
callback(false);
|
callback(false);
|
||||||
}
|
}
|
||||||
try_num++;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}, 500);
|
}
|
||||||
|
checkDaemonRunning();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, function () {
|
||||||
|
callback(null);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
lbry.getBalance = function(callback)
|
lbry.getBalance = function(callback)
|
||||||
{
|
{
|
||||||
lbry.call("get_balance", {}, callback);
|
lbry.call("get_balance", {}, callback);
|
||||||
|
|
Loading…
Add table
Reference in a new issue