Refactor JSON-RPC handling into generic function
This commit is contained in:
parent
9f5c999c39
commit
9d7f82e309
1 changed files with 9 additions and 4 deletions
13
js/lbry.js
13
js/lbry.js
|
@ -1,13 +1,13 @@
|
||||||
var lbry = {
|
var lbry = {
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
rootPath: '.',
|
rootPath: '.',
|
||||||
|
daemonConnectionString: 'http://localhost:5279/lbryapi',
|
||||||
colors: {
|
colors: {
|
||||||
primary: '#155B4A'
|
primary: '#155B4A'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry.call = function (method, params, callback, errorCallback, connectFailedCallback)
|
lbry.jsonrpc_call = function (connectionString, method, params, callback, errorCallback, connectFailedCallback) {
|
||||||
{
|
|
||||||
var xhr = new XMLHttpRequest;
|
var xhr = new XMLHttpRequest;
|
||||||
xhr.addEventListener('load', function() {
|
xhr.addEventListener('load', function() {
|
||||||
var response = JSON.parse(xhr.responseText);
|
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({
|
xhr.send(JSON.stringify({
|
||||||
'jsonrpc': '2.0',
|
'jsonrpc': '2.0',
|
||||||
'method': method,
|
'method': method,
|
||||||
'params': [params, ],
|
'params': params,
|
||||||
'id': 0
|
'id': 0
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lbry.call = function (method, params, callback, errorCallback, connectFailedCallback) {
|
||||||
|
lbry.jsonrpc_call(lbry.daemonConnectionString, method, [params], callback, errorCallback, connectFailedCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//core
|
//core
|
||||||
lbry.connect = function(callback)
|
lbry.connect = function(callback)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue