Merge pull request #263 from BeaudanBrown/long-polling

Long polling
pull/271/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 949f597ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,6 +7,7 @@ const { rpc } = require('./loki_rpc');
// Will be raised (to 3?) when we get more nodes // Will be raised (to 3?) when we get more nodes
const MINIMUM_SUCCESSFUL_REQUESTS = 2; const MINIMUM_SUCCESSFUL_REQUESTS = 2;
const LOKI_LONGPOLL_HEADER = 'X-Loki-Long-Poll';
class LokiMessageAPI { class LokiMessageAPI {
constructor({ snodeServerPort }) { constructor({ snodeServerPort }) {
@ -171,13 +172,20 @@ class LokiMessageAPI {
pubKey: ourKey, pubKey: ourKey,
lastHash: nodeData.lastHash || '', lastHash: nodeData.lastHash || '',
}; };
const options = {
timeout: 40000,
headers: {
[LOKI_LONGPOLL_HEADER]: true,
},
};
try { try {
const result = await rpc( const result = await rpc(
`http://${nodeUrl}`, `http://${nodeUrl}`,
this.snodeServerPort, this.snodeServerPort,
'retrieve', 'retrieve',
params params,
options
); );
nodeComplete(nodeUrl); nodeComplete(nodeUrl);

@ -8,7 +8,7 @@ const endpointBase = '/v1/storage_rpc';
// A small wrapper around node-fetch which deserializes response // A small wrapper around node-fetch which deserializes response
const fetch = async (url, options = {}) => { const fetch = async (url, options = {}) => {
const timeout = options.timeout || 10000; const timeout = options.timeout || 5000;
const method = options.method || 'GET'; const method = options.method || 'GET';
const address = parse(url).hostname; const address = parse(url).hostname;

@ -3,8 +3,7 @@
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {
let server; let server;
const development = window.getEnvironment() !== 'production'; const POLL_TIME = 100;
const pollTime = development ? 100 : 5000;
function stringToArrayBufferBase64(string) { function stringToArrayBufferBase64(string) {
return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer(); return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer();
@ -115,7 +114,7 @@
callback(connected); callback(connected);
setTimeout(() => { setTimeout(() => {
pollServer(callback); pollServer(callback);
}, pollTime); }, POLL_TIME);
}; };
this.isConnected = function isConnected() { this.isConnected = function isConnected() {

Loading…
Cancel
Save