Skip to content

Instantly share code, notes, and snippets.

@williamtoader
Last active May 26, 2020 10:49
Show Gist options
  • Save williamtoader/9904714f948244cdd5b89f7de80c88b2 to your computer and use it in GitHub Desktop.
Save williamtoader/9904714f948244cdd5b89f7de80c88b2 to your computer and use it in GitHub Desktop.
nodejs lbry connection script
const lbry = require("./node_lbry_2020.js");
let promise = lbry.requestPromise("example_method", {
param: "value"
})
promise.then(
claims => console.log(claims),
error => console.error(error)
)
const http = require('http');
const lbry ={}
const _request = (method_name, params) => {
let requestPromise = new Promise((resolve, reject) => {
let post_data = {
method: method_name
}
if (params) {
post_data.params = params
}
let post_data_string = JSON.stringify(post_data)
const options = {
hostname: '127.0.0.1',
port: '5279',
path: '/lbryapi',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(post_data_string)
}
}
const req = http.request(options, (res) => {
console.log(`statusCode: ${res.statusCode}`)
res.on('data', (data) => {
resolve(data.toString())
})
})
req.on('error', (error) => {
reject(error)
})
req.write(post_data_string);
req.end()
})
return requestPromise
}
lbry.requestPromise = _request
module.exports = lbry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment