From b2bcf3a436f90f2b6c0d46a8f9561558c739df89 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 24 Mar 2016 03:08:39 -0400 Subject: [PATCH] Implement lbry.connect(); loading screen now actually checks if the daemon is loaded --- js/lbry.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index 7a44758b3..2810eee64 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -31,11 +31,24 @@ lbry.call = function (method, params, callback) //core lbry.connect = function(callback) { - //dummy connect function - one of the first things we should do is dump people to get help if it can't connect - setTimeout(function() { - lbry.isConnected = true; - callback(); - }, 1500); + // 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. + var try_num = 0; + var check_connected = setInterval(function() { + lbry.call('is_running', {}, function(is_running) { + if (is_running) { + lbry.isConnected = true; + clearInterval(check_connected); + callback(true); + } else { + if (try_num >= 20) { // Move this into a constant or config option + clearInterval(check_connected); + callback(false); + } + try_num++; + } + }); + }, 500); } lbry.getBalance = function(callback)