lbry-desktop/js/lbry.js
Jack 279fc434c1 fix thumbnail and font paths, add default thumbnail image
also remove reference to unused script (mimic.js) from index.html
2016-03-21 12:04:46 -04:00

76 lines
1.8 KiB
JavaScript

var lbry = {
isConnected: false,
rootPath: '.',
colors: {
primary: '#155B4A'
}
};
lbry.call = function (method, params, callback)
{
var xhr = new XMLHttpRequest;
xhr.addEventListener('load', function() {
// The response from the HTTP endpoint has a "result" key containing a JSON string of the output of the JSON-RPC method itself
var method_output = JSON.parse(JSON.parse(xhr.responseText).result);
if (method_output.code !== 200) {
throw new Error('Call to method ' + method + ' failed with message: ' + method_output.message);
}
console.log(method_output.result);
callback(method_output.result);
});
xhr.open('POST', 'http://localhost:5279/lbryapi', true);
xhr.send(JSON.stringify({
'jsonrpc': '2.0',
'method': method,
'params': [params, ],
'id': 0
}));
}
//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);
}
lbry.getBalance = function(callback)
{
lbry.call("get_balance", {}, callback);
}
lbry.search = function(query, callback)
{
lbry.call("search_nametrie", { "search": query }, callback);
}
//utilities
lbry.formatCredits = function(amount, precision)
{
return amount.toFixed(precision || 1);
}
lbry.loadJs = function(src, type, onload)
{
var lbryScriptTag = document.getElementById('lbry'),
newScriptTag = document.createElement('script'),
type = type || 'text/javascript';
newScriptTag.src = src;
newScriptTag.type = type;
if (onload)
{
newScript.onload = onload;
}
lbryScriptTag.parentNode.insertBefore(newScriptTag, lbryScriptTag);
}
lbry.imagePath = function(file)
{
return lbry.rootPath + '/img/' + file;
}