adds headers and means to set them to Lbry

This commit is contained in:
Jessop Breth 2019-05-30 11:24:46 -04:00
parent a01b919c72
commit ed94218cdb
5 changed files with 29 additions and 1 deletions

6
.gitignore vendored
View file

@ -1,3 +1,7 @@
/node_modules
yarn-error.log
package-lock.json
package-lock.json
# Jetbrains
.idea/

9
dist/bundle.es.js vendored
View file

@ -606,12 +606,20 @@ const Lbry = {
isConnected: false,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
setDaemonConnectionString: value => {
Lbry.daemonConnectionString = value;
},
setApiHeader: (key, value) => {
Lbry.apiRequestHeaders = Object.assign(Lbry.apiRequestHeaders, { [key]: value });
},
unsetApiHeader: key => {
Object.keys(Lbry.apiRequestHeaders).includes(key) && delete Lbry.apiRequestHeaders['key'];
},
// Allow overriding Lbry methods
overrides: {},
setOverride: (methodName, newMethod) => {
@ -730,6 +738,7 @@ function apiCall(method, params, resolve, reject) {
const counter = new Date().getTime();
const options = {
method: 'POST',
headers: Lbry.apiRequestHeaders,
body: JSON.stringify({
jsonrpc: '2.0',
method,

View file

@ -153,7 +153,10 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>,
connect: () => void,
daemonConnectionString: string,
apiRequestHeaders: {[key: string]: string},
setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void,
unsetApiHeader: (string) => void,
overrides: { [string]: ?Function },
setOverride: (string, Function) => void,
getMediaType: (string, ?string) => string,

3
flow-typed/Lbry.js vendored
View file

@ -153,7 +153,10 @@ declare type LbryTypes = {
connectPromise: ?Promise<any>,
connect: () => void,
daemonConnectionString: string,
apiRequestHeaders: {[key: string]: string},
setDaemonConnectionString: string => void,
setApiHeader: (string, string) => void,
unsetApiHeader: (string) => void,
overrides: { [string]: ?Function },
setOverride: (string, Function) => void,
getMediaType: (string, ?string) => string,

View file

@ -11,12 +11,20 @@ const Lbry: LbryTypes = {
isConnected: false,
connectPromise: null,
daemonConnectionString: 'http://localhost:5279',
apiRequestHeaders: { 'Content-Type': 'application/json-rpc' },
// Allow overriding daemon connection string (e.g. to `/api/proxy` for lbryweb)
setDaemonConnectionString: (value: string) => {
Lbry.daemonConnectionString = value;
},
setApiHeader: (key: string, value: string) => {
Lbry.apiRequestHeaders = Object.assign(Lbry.apiRequestHeaders, { [key]: value });
},
unsetApiHeader: key => {
Object.keys(Lbry.apiRequestHeaders).includes(key) && delete Lbry.apiRequestHeaders['key'];
},
// Allow overriding Lbry methods
overrides: {},
setOverride: (methodName, newMethod) => {
@ -141,6 +149,7 @@ function apiCall(method: string, params: ?{}, resolve: Function, reject: Functio
const counter = new Date().getTime();
const options = {
method: 'POST',
headers: Lbry.apiRequestHeaders,
body: JSON.stringify({
jsonrpc: '2.0',
method,