jsonrpc updates
This commit is contained in:
parent
1501eaab48
commit
b081f465bb
3 changed files with 31 additions and 42 deletions
|
@ -1040,25 +1040,24 @@ var Lbry = {
|
|||
function checkAndParse(response) {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response.json();
|
||||
} else {
|
||||
return response.json().then(function (json) {
|
||||
var error = void 0;
|
||||
if (json.error) {
|
||||
error = new Error(json.error);
|
||||
} else {
|
||||
error = new Error("Protocol error with unknown response signature");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
return response.json().then(function (json) {
|
||||
var error = void 0;
|
||||
if (json.error) {
|
||||
error = new Error(json.error);
|
||||
} else {
|
||||
error = new Error('Protocol error with unknown response signature');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
function apiCall(method, params, resolve, reject) {
|
||||
var counter = new Date().getTime();
|
||||
var options = {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
jsonrpc: '2.0',
|
||||
method: method,
|
||||
params: params,
|
||||
id: counter
|
||||
|
@ -1070,9 +1069,8 @@ function apiCall(method, params, resolve, reject) {
|
|||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
} else {
|
||||
return resolve(response.result);
|
||||
}
|
||||
return resolve(response.result);
|
||||
}).catch(reject);
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
"proxy-polyfill": "0.1.6",
|
||||
"qrcode.react": "^0.7.2",
|
||||
"rc-progress": "^2.0.6",
|
||||
"react": "^16.2.0",
|
||||
"react": "16.2.0",
|
||||
"react-redux": "^5.0.3",
|
||||
"react-simplemde-editor": "^3.6.11",
|
||||
"redux": "^3.6.0",
|
||||
|
|
45
src/lbry.js
45
src/lbry.js
|
@ -12,32 +12,26 @@ const Lbry = {
|
|||
function checkAndParse(response) {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response.json();
|
||||
} else {
|
||||
return response.json().then(json => {
|
||||
let error;
|
||||
if (json.error) {
|
||||
error = new Error(json.error);
|
||||
} else {
|
||||
error = new Error("Protocol error with unknown response signature");
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
return response.json().then(json => {
|
||||
let error;
|
||||
if (json.error) {
|
||||
error = new Error(json.error);
|
||||
} else {
|
||||
error = new Error('Protocol error with unknown response signature');
|
||||
}
|
||||
return Promise.reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
function apiCall(
|
||||
method: string,
|
||||
params: ?{},
|
||||
resolve: Function,
|
||||
reject: Function
|
||||
) {
|
||||
function apiCall(method: string, params: ?{}, resolve: Function, reject: Function) {
|
||||
const counter = new Date().getTime();
|
||||
const options = {
|
||||
method: "POST",
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
jsonrpc: "2.0",
|
||||
method: method,
|
||||
params: params,
|
||||
jsonrpc: '2.0',
|
||||
method,
|
||||
params,
|
||||
id: counter,
|
||||
}),
|
||||
};
|
||||
|
@ -45,14 +39,12 @@ function apiCall(
|
|||
return fetch(Lbry.daemonConnectionString, options)
|
||||
.then(checkAndParse)
|
||||
.then(response => {
|
||||
const error =
|
||||
response.error || (response.result && response.result.error);
|
||||
const error = response.error || (response.result && response.result.error);
|
||||
|
||||
if (error) {
|
||||
return reject(error);
|
||||
} else {
|
||||
return resolve(response.result);
|
||||
}
|
||||
return resolve(response.result);
|
||||
})
|
||||
.catch(reject);
|
||||
}
|
||||
|
@ -160,8 +152,7 @@ Lbry.connect = () => {
|
|||
// Check every half second to see if the daemon is accepting connections
|
||||
function checkDaemonStarted() {
|
||||
tryNum += 1;
|
||||
Lbry
|
||||
.status()
|
||||
Lbry.status()
|
||||
.then(resolve)
|
||||
.catch(() => {
|
||||
if (tryNum <= CHECK_DAEMON_STARTED_TRY_NUMBER) {
|
||||
|
@ -171,7 +162,7 @@ Lbry.connect = () => {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
checkDaemonStarted();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue