From 9d7f82e3096bb1929d6dc000a5bb12e0f3256d64 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 18 Aug 2016 02:57:19 -0400 Subject: [PATCH] Refactor JSON-RPC handling into generic function --- js/lbry.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/js/lbry.js b/js/lbry.js index e92303ac6..9b87b8883 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -1,13 +1,13 @@ var lbry = { isConnected: false, rootPath: '.', + daemonConnectionString: 'http://localhost:5279/lbryapi', colors: { primary: '#155B4A' } }; -lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) -{ +lbry.jsonrpc_call = function (connectionString, method, params, callback, errorCallback, connectFailedCallback) { var xhr = new XMLHttpRequest; xhr.addEventListener('load', function() { var response = JSON.parse(xhr.responseText); @@ -27,15 +27,20 @@ lbry.call = function (method, params, callback, errorCallback, connectFailedCall }); } - xhr.open('POST', 'http://localhost:5279/lbryapi', true); + xhr.open('POST', connectionString, true); xhr.send(JSON.stringify({ 'jsonrpc': '2.0', 'method': method, - 'params': [params, ], + 'params': params, 'id': 0 })); } +lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) { + lbry.jsonrpc_call(lbry.daemonConnectionString, method, [params], callback, errorCallback, connectFailedCallback); +} + + //core lbry.connect = function(callback) {