Browse Source

Merge branch 'master' into feature/docker

feature/dockerfile-arm
Gonzalo Javier Aune 5 years ago
parent
commit
608d90fd81
  1. 22
      api/grpc/index.ts
  2. 22
      dist/api/grpc/index.js
  3. 2
      dist/api/grpc/index.js.map
  4. 8
      dist/public/js/app.js
  5. 4
      frontend/components/Media/index.jsx
  6. 8
      public/js/app.js

22
api/grpc/index.ts

@ -10,6 +10,7 @@ import * as path from 'path'
const constants = require(path.join(__dirname,'../../config/constants.json'))
const ERR_CODE_UNAVAILABLE = 14
const ERR_CODE_STREAM_REMOVED = 2
// VERIFY PUBKEY OF SENDER
async function parseAndVerifyPayload(data){
@ -173,16 +174,18 @@ function subscribeInvoices(actions) {
call.on('status', function(status) {
console.log("Status", status);
// The server is unavailable, trying to reconnect.
if (status.code == ERR_CODE_UNAVAILABLE) {
reconnectToLND();
if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) {
i = 0
reconnectToLND(Math.random());
} else {
resolve(status);
}
})
call.on('error', function(err){
console.error(err)
if (err.code == ERR_CODE_UNAVAILABLE) {
reconnectToLND();
if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) {
i = 0
reconnectToLND(Math.random());
} else {
reject(err)
}
@ -191,7 +194,8 @@ function subscribeInvoices(actions) {
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`Closed stream ${now}`);
// The server has closed the stream.
reconnectToLND()
i = 0
reconnectToLND(Math.random())
})
setTimeout(()=>{
resolve(null)
@ -200,7 +204,9 @@ function subscribeInvoices(actions) {
}
var i = 0
async function reconnectToLND(){
var ctx = 0
async function reconnectToLND(innerCtx:number){
ctx = innerCtx
i++
console.log(`=> [lnd] reconnecting... attempt #${i}`)
try {
@ -209,7 +215,9 @@ async function reconnectToLND(){
console.log(`=> [lnd] reconnected! ${now}`)
} catch(e) {
setTimeout(async()=>{ // retry each 2 secs
await reconnectToLND()
if(ctx===innerCtx) { // if another retry fires, then this will not run
await reconnectToLND(innerCtx)
}
},2000)
}
}

22
dist/api/grpc/index.js

@ -20,6 +20,7 @@ const moment = require("moment");
const path = require("path");
const constants = require(path.join(__dirname, '../../config/constants.json'));
const ERR_CODE_UNAVAILABLE = 14;
const ERR_CODE_STREAM_REMOVED = 2;
// VERIFY PUBKEY OF SENDER
function parseAndVerifyPayload(data) {
return __awaiter(this, void 0, void 0, function* () {
@ -184,8 +185,9 @@ function subscribeInvoices(actions) {
call.on('status', function (status) {
console.log("Status", status);
// The server is unavailable, trying to reconnect.
if (status.code == ERR_CODE_UNAVAILABLE) {
reconnectToLND();
if (status.code == ERR_CODE_UNAVAILABLE || status.code == ERR_CODE_STREAM_REMOVED) {
i = 0;
reconnectToLND(Math.random());
}
else {
resolve(status);
@ -193,8 +195,9 @@ function subscribeInvoices(actions) {
});
call.on('error', function (err) {
console.error(err);
if (err.code == ERR_CODE_UNAVAILABLE) {
reconnectToLND();
if (err.code == ERR_CODE_UNAVAILABLE || err.code == ERR_CODE_STREAM_REMOVED) {
i = 0;
reconnectToLND(Math.random());
}
else {
reject(err);
@ -204,7 +207,8 @@ function subscribeInvoices(actions) {
const now = moment().format('YYYY-MM-DD HH:mm:ss').trim();
console.log(`Closed stream ${now}`);
// The server has closed the stream.
reconnectToLND();
i = 0;
reconnectToLND(Math.random());
});
setTimeout(() => {
resolve(null);
@ -213,8 +217,10 @@ function subscribeInvoices(actions) {
}
exports.subscribeInvoices = subscribeInvoices;
var i = 0;
function reconnectToLND() {
var ctx = 0;
function reconnectToLND(innerCtx) {
return __awaiter(this, void 0, void 0, function* () {
ctx = innerCtx;
i++;
console.log(`=> [lnd] reconnecting... attempt #${i}`);
try {
@ -224,7 +230,9 @@ function reconnectToLND() {
}
catch (e) {
setTimeout(() => __awaiter(this, void 0, void 0, function* () {
yield reconnectToLND();
if (ctx === innerCtx) {
yield reconnectToLND(innerCtx);
}
}), 2000);
}
});

2
dist/api/grpc/index.js.map

File diff suppressed because one or more lines are too long

8
dist/public/js/app.js

@ -31891,8 +31891,7 @@ function Media(props) {
file = files[0] || {};
start = new Date();
_context2.next = 5;
return api_media.UPLOAD('upload/attachment', file, {
chat_uuid: '1234567890',
return api_media.UPLOAD('file', file, {
name: file.name || 'filename',
description: description || 'description',
ttl: ttl
@ -31902,14 +31901,15 @@ function Media(props) {
r = _context2.sent;
end = new Date();
time = end.getTime() - start.getTime();
console.log('Upload Timer: finished in', time, 'ms'); // await api.relay.POST('attachment', {
console.log('Upload Timer: finished in', time, 'ms');
console.log(r); // await api.relay.POST('attachment', {
// muid: r.muid,
// file_name: r.filename,
// chat_id: 13,
// ttl: ttl,
// })
case 9:
case 10:
case "end":
return _context2.stop();
}

4
frontend/components/Media/index.jsx

@ -43,8 +43,7 @@ export default function Media(props) {
const ttl = 60*60*24*7 // one week
const file = files[0] || {}
var start = new Date();
const r = await api.media.UPLOAD('upload/attachment',file,{
chat_uuid: '1234567890',
const r = await api.media.UPLOAD('public',file,{
name: file.name||'filename',
description: description||'description',
ttl: ttl,
@ -52,6 +51,7 @@ export default function Media(props) {
var end = new Date();
var time = end.getTime() - start.getTime();
console.log('Upload Timer: finished in', time, 'ms');
console.log(r)
// await api.relay.POST('attachment', {
// muid: r.muid,
// file_name: r.filename,

8
public/js/app.js

@ -31891,8 +31891,7 @@ function Media(props) {
file = files[0] || {};
start = new Date();
_context2.next = 5;
return api_media.UPLOAD('upload/attachment', file, {
chat_uuid: '1234567890',
return api_media.UPLOAD('file', file, {
name: file.name || 'filename',
description: description || 'description',
ttl: ttl
@ -31902,14 +31901,15 @@ function Media(props) {
r = _context2.sent;
end = new Date();
time = end.getTime() - start.getTime();
console.log('Upload Timer: finished in', time, 'ms'); // await api.relay.POST('attachment', {
console.log('Upload Timer: finished in', time, 'ms');
console.log(r); // await api.relay.POST('attachment', {
// muid: r.muid,
// file_name: r.filename,
// chat_id: 13,
// ttl: ttl,
// })
case 9:
case 10:
case "end":
return _context2.stop();
}

Loading…
Cancel
Save