Merge pull request #277 from BeaudanBrown/polling-patch

Polling patch
pull/278/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit 95cad09253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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 || 5000; const timeout = options.timeout || 10000;
const method = options.method || 'GET'; const method = options.method || 'GET';
const address = parse(url).hostname; const address = parse(url).hostname;

@ -3,7 +3,8 @@
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
(function() { (function() {
let server; let server;
const POLL_TIME = 100; const SUCCESS_POLL_TIME = 100;
const FAIL_POLL_TIME = 2000;
function stringToArrayBufferBase64(string) { function stringToArrayBufferBase64(string) {
return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer(); return dcodeIO.ByteBuffer.wrap(string, 'base64').toArrayBuffer();
@ -87,12 +88,14 @@
}); });
connected = true; connected = true;
} catch (err) { } catch (err) {
window.log.err('Polling error: ', err);
connected = false; connected = false;
} }
const pollTime = connected ? SUCCESS_POLL_TIME : FAIL_POLL_TIME;
callback(connected); callback(connected);
setTimeout(() => { setTimeout(() => {
this.pollServer(callback); this.pollServer(callback);
}, POLL_TIME); }, pollTime);
}; };
this.isConnected = function isConnected() { this.isConnected = function isConnected() {

Loading…
Cancel
Save